{"id":2223199,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223199/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260414171351.31212-2-fw@strlen.de/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.1/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260414171351.31212-2-fw@strlen.de>","date":"2026-04-14T17:13:47","name":"[nf,2/2] netfilter: nf_conntrack_sip: don't use strtoul_simple","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"223a6eee05d41bd1384d71fed75193d59b7baa8a","submitter":{"id":1025,"url":"http://patchwork.ozlabs.org/api/1.1/people/1025/?format=json","name":"Florian Westphal","email":"fw@strlen.de"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260414171351.31212-2-fw@strlen.de/mbox/","series":[{"id":499877,"url":"http://patchwork.ozlabs.org/api/1.1/series/499877/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=499877","date":"2026-04-14T17:13:46","name":"[nf,1/2] netfilter: conntrack: remove sprintf usage","version":1,"mbox":"http://patchwork.ozlabs.org/series/499877/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223199/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223199/checks/","tags":{},"headers":{"Return-Path":"\n <netfilter-devel+bounces-11886-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","netfilter-devel@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-11886-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.216.245.30","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fw9vW5WQ9z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 03:17:43 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id B9B99306A417\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 17:14:14 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id C17922F693B;\n\tTue, 14 Apr 2026 17:14:12 +0000 (UTC)","from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc\n [91.216.245.30])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A04D2773F7\n\tfor <netfilter-devel@vger.kernel.org>; Tue, 14 Apr 2026 17:14:11 +0000 (UTC)","by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)\n\tid DEC7E608DB; Tue, 14 Apr 2026 19:14:09 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776186852; cv=none;\n b=sxUDTSj4OAh6d20s4GqTws9xCmPhPM+mlLDjzdUoi6bVE/JE4bSHOOhSb0ke0qAlT6GLtjrKOBOgNZkAbO+jab11yePDWkHk/cIUr3+2HSnqHmsYMUNzTUMACkXTFE8HJyb+g3wVKxP1Tu6AjIae54AAPuSZHWsjPnniV3UognE=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776186852; c=relaxed/simple;\n\tbh=pVk+bUqDXOHWJDOkoGosU4C74QU7W88WC3KXlxYwuTA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=Ux1MHLDVR9/kELqJmnYzoZq0CIEKGd+UyqycULM0lc6TOBwyX3GudGkftl0Ym3PiFoLwxexi4Pn8STYadh8dlpinq/GhfDF6zdzxWJG7fkQpWqBG7JUXMPiahDpA8QQc6EolCFM0UUqRzQtYJuDNWjPRS1LryPB3uUsU7m7rXt8=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc;\n arc=none smtp.client-ip=91.216.245.30","From":"Florian Westphal <fw@strlen.de>","To":"<netfilter-devel@vger.kernel.org>","Cc":"Florian Westphal <fw@strlen.de>","Subject":"[PATCH nf 2/2] netfilter: nf_conntrack_sip: don't use strtoul_simple","Date":"Tue, 14 Apr 2026 19:13:47 +0200","Message-ID":"<20260414171351.31212-2-fw@strlen.de>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260414171351.31212-1-fw@strlen.de>","References":"<20260414171351.31212-1-fw@strlen.de>","Precedence":"bulk","X-Mailing-List":"netfilter-devel@vger.kernel.org","List-Id":"<netfilter-devel.vger.kernel.org>","List-Subscribe":"<mailto:netfilter-devel+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:netfilter-devel+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Probably 'safe' because struct shinfo is stored at end of linear data area\nand simple_strotul bails out on first character thats not a number.\n\nPrefer a stricter version instead.  There are intentional changes:\n\n- Bail out if number is > UINT_MAX and indicate a failure.\n  We don't expect huge values here.\n\n- Bail out if we get more characters than expected, we don't expect\n  something like 'expires=9999999999999999999999999999999999'.\n\n- In ct_sip_parse_numerical_param() base 10 is enforced. This is used\n  to fetch 'expire=' and 'rports='; both are expected to be base-10 values.\n\n- In nf_nat_sip.c, only accept the parsed value if its within the 1k-64k\n  range.\n\nSigned-off-by: Florian Westphal <fw@strlen.de>\n---\n Could be deferred to nf-next, but given we're in merge window I think nf is fine.\n\n net/netfilter/nf_conntrack_sip.c | 73 ++++++++++++++++++++++++++------\n net/netfilter/nf_nat_sip.c       |  1 +\n 2 files changed, 62 insertions(+), 12 deletions(-)","diff":"diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c\nindex 939502ff7c87..02c65415f309 100644\n--- a/net/netfilter/nf_conntrack_sip.c\n+++ b/net/netfilter/nf_conntrack_sip.c\n@@ -228,6 +228,51 @@ static int skp_epaddr_len(const struct nf_conn *ct, const char *dptr,\n \treturn epaddr_len(ct, dptr, limit, shift);\n }\n \n+/* simple_stroul stops after first non-number character.\n+ * But as we're not dealing with c-strings, we can't rely on\n+ * hitting \\r,\\n,\\0 etc. before moving past end of buffer.\n+ *\n+ * This is a variant of simple_stroul, but doesn't require\n+ * a c-string.\n+ *\n+ * If value exceeds UINT_MAX, 0 is returned.\n+ */\n+static unsigned int sip_strtouint(const char *cp, unsigned int len, char **endp)\n+{\n+\tconst unsigned int max = sizeof(\"4294967295\");\n+\tunsigned int olen = len;\n+\tconst char *s = cp;\n+\tu64 result = 0;\n+\n+\tif (len > max)\n+\t\tlen = max;\n+\n+\twhile (olen > 0 && isdigit(*s)) {\n+\t\tunsigned int value;\n+\n+\t\tif (len == 0)\n+\t\t\tgoto err;\n+\n+\t\tvalue = *s - '0';\n+\t\tresult = result * 10 + value;\n+\n+\t\tif (result > UINT_MAX)\n+\t\t\tgoto err;\n+\t\ts++;\n+\t\tlen--;\n+\t\tolen--;\n+\t}\n+\n+\tif (endp)\n+\t\t*endp = (char *)s;\n+\n+\treturn result;\n+err:\n+\tif (endp)\n+\t\t*endp = (char *)cp;\n+\treturn 0;\n+}\n+\n /* Parse a SIP request line of the form:\n  *\n  * Request-Line = Method SP Request-URI SP SIP-Version CRLF\n@@ -269,7 +314,7 @@ int ct_sip_parse_request(const struct nf_conn *ct,\n \t\treturn -1;\n \tif (end < limit && *end == ':') {\n \t\tend++;\n-\t\tp = simple_strtoul(end, (char **)&end, 10);\n+\t\tp = sip_strtouint(end, limit - end, (char **)&end);\n \t\tif (p < 1024 || p > 65535)\n \t\t\treturn -1;\n \t\t*port = htons(p);\n@@ -522,7 +567,7 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,\n \t\treturn -1;\n \tif (*c == ':') {\n \t\tc++;\n-\t\tp = simple_strtoul(c, (char **)&c, 10);\n+\t\tp = sip_strtouint(c, limit - c, (char **)&c);\n \t\tif (p < 1024 || p > 65535)\n \t\t\treturn -1;\n \t\t*port = htons(p);\n@@ -609,7 +654,7 @@ int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,\n \t\treturn 0;\n \n \tstart += strlen(name);\n-\t*val = simple_strtoul(start, &end, 0);\n+\t*val = sip_strtouint(start, limit - start, (char **)&end);\n \tif (start == end)\n \t\treturn -1;\n \tif (matchoff && matchlen) {\n@@ -1065,6 +1110,8 @@ static int process_sdp(struct sk_buff *skb, unsigned int protoff,\n \n \tmediaoff = sdpoff;\n \tfor (i = 0; i < ARRAY_SIZE(sdp_media_types); ) {\n+\t\tchar *end;\n+\n \t\tif (ct_sip_get_sdp_header(ct, *dptr, mediaoff, *datalen,\n \t\t\t\t\t  SDP_HDR_MEDIA, SDP_HDR_UNSPEC,\n \t\t\t\t\t  &mediaoff, &medialen) <= 0)\n@@ -1080,8 +1127,8 @@ static int process_sdp(struct sk_buff *skb, unsigned int protoff,\n \t\tmediaoff += t->len;\n \t\tmedialen -= t->len;\n \n-\t\tport = simple_strtoul(*dptr + mediaoff, NULL, 10);\n-\t\tif (port == 0)\n+\t\tport = sip_strtouint(*dptr + mediaoff, *datalen - mediaoff, (char **)&end);\n+\t\tif (port == 0 || *dptr + mediaoff == end)\n \t\t\tcontinue;\n \t\tif (port < 1024 || port > 65535) {\n \t\t\tnf_ct_helper_log(skb, ct, \"wrong port %u\", port);\n@@ -1255,7 +1302,7 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,\n \t */\n \tif (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,\n \t\t\t      &matchoff, &matchlen) > 0)\n-\t\texpires = simple_strtoul(*dptr + matchoff, NULL, 10);\n+\t\texpires = sip_strtouint(*dptr + matchoff, *datalen - matchoff, NULL);\n \n \tret = ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,\n \t\t\t\t      SIP_HDR_CONTACT, NULL,\n@@ -1359,7 +1406,7 @@ static int process_register_response(struct sk_buff *skb, unsigned int protoff,\n \n \tif (ct_sip_get_header(ct, *dptr, 0, *datalen, SIP_HDR_EXPIRES,\n \t\t\t      &matchoff, &matchlen) > 0)\n-\t\texpires = simple_strtoul(*dptr + matchoff, NULL, 10);\n+\t\texpires = sip_strtouint(*dptr + matchoff, *datalen - matchoff, NULL);\n \n \twhile (1) {\n \t\tunsigned int c_expires = expires;\n@@ -1422,7 +1469,8 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff,\n \n \tif (*datalen < strlen(\"SIP/2.0 200\"))\n \t\treturn NF_ACCEPT;\n-\tcode = simple_strtoul(*dptr + strlen(\"SIP/2.0 \"), NULL, 10);\n+\tcode = sip_strtouint(*dptr + strlen(\"SIP/2.0 \"),\n+\t\t\t     *datalen - strlen(\"SIP/2.0\"), NULL);\n \tif (!code) {\n \t\tnf_ct_helper_log(skb, ct, \"cannot get code\");\n \t\treturn NF_DROP;\n@@ -1433,7 +1481,7 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff,\n \t\tnf_ct_helper_log(skb, ct, \"cannot parse cseq\");\n \t\treturn NF_DROP;\n \t}\n-\tcseq = simple_strtoul(*dptr + matchoff, NULL, 10);\n+\tcseq = sip_strtouint(*dptr + matchoff, *datalen - matchoff, NULL);\n \tif (!cseq && *(*dptr + matchoff) != '0') {\n \t\tnf_ct_helper_log(skb, ct, \"cannot get cseq\");\n \t\treturn NF_DROP;\n@@ -1483,6 +1531,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,\n \n \tfor (i = 0; i < ARRAY_SIZE(sip_handlers); i++) {\n \t\tconst struct sip_handler *handler;\n+\t\tchar *end;\n \n \t\thandler = &sip_handlers[i];\n \t\tif (handler->request == NULL)\n@@ -1499,8 +1548,8 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,\n \t\t\tnf_ct_helper_log(skb, ct, \"cannot parse cseq\");\n \t\t\treturn NF_DROP;\n \t\t}\n-\t\tcseq = simple_strtoul(*dptr + matchoff, NULL, 10);\n-\t\tif (!cseq && *(*dptr + matchoff) != '0') {\n+\t\tcseq = sip_strtouint(*dptr + matchoff, *datalen - matchoff, (char **)&end);\n+\t\tif (*dptr + matchoff == end) {\n \t\t\tnf_ct_helper_log(skb, ct, \"cannot get cseq\");\n \t\t\treturn NF_DROP;\n \t\t}\n@@ -1576,7 +1625,7 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,\n \t\t\t\t      &matchoff, &matchlen) <= 0)\n \t\t\tbreak;\n \n-\t\tclen = simple_strtoul(dptr + matchoff, (char **)&end, 10);\n+\t\tclen = sip_strtouint(dptr + matchoff, datalen - matchoff, (char **)&end);\n \t\tif (dptr + matchoff == end)\n \t\t\tbreak;\n \ndiff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c\nindex c845b6d1a2bd..9fbfc6bff0c2 100644\n--- a/net/netfilter/nf_nat_sip.c\n+++ b/net/netfilter/nf_nat_sip.c\n@@ -246,6 +246,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,\n \t\tif (ct_sip_parse_numerical_param(ct, *dptr, matchend, *datalen,\n \t\t\t\t\t\t \"rport=\", &poff, &plen,\n \t\t\t\t\t\t &n) > 0 &&\n+\t\t    n >= 1024 && n <= 65535 &&\n \t\t    htons(n) == ct->tuplehash[dir].tuple.dst.u.udp.port &&\n \t\t    htons(n) != ct->tuplehash[!dir].tuple.src.u.udp.port) {\n \t\t\t__be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port;\n","prefixes":["nf","2/2"]}