Skip to contentSkip to conversation

netfilter: nf_conntrack_sip: fix Content-Length u32 truncation in sip_help_tcp()

PATCH New Lukas Johannes Möller 1 participant 1 message Mar 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nf_conntrack_sip: fix Content-Length u32 truncation in sip_help_tcp()

sip_help_tcp() parses the SIP Content-Length header with simple_strtoul(), which returns unsigned long, but stores the result in unsigned int clen. On 64-bit systems, values exceeding UINT_MAX are silently truncated before computing the SIP message boundary.

For example, Content-Length 4294967328 (2^32 + 32) is truncated to 32, causing the parser to miscalculate where the current message ends. The loop then treats trailing data in the TCP segment as a second SIP message and processes it through the SDP parser.

Fix this by changing clen to unsigned long to match the return type of simple_strtoul(), and reject Content-Length values that exceed the remaining TCP payload length.

Fixes f5b321bd37fb ("netfilter: nf_conntrack_sip: add TCP support")

---
Note: simple_strtoul() is deprecated; a follow-up patch could convert to kstrtoul() with stricter input validation.

 net/netfilter/nf_conntrack_sip.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_sip.c +5 -1
index ca748f8dbff1..eb6295f0e08c 100644
@@ -1534,7 +1534,8 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
 {
 	struct tcphdr *th, _tcph;
 	unsigned int dataoff, datalen;
-	unsigned int matchoff, matchlen, clen;
+	unsigned int matchoff, matchlen;
+	unsigned long clen;
 	unsigned int msglen, origlen;
 	const char *dptr, *end;
 	s16 diff, tdiff = 0;
@@ -1573,6 +1574,9 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
 		if (dptr + matchoff == end)
 			break;
 
+		if (clen > datalen)
+			break;
+
 		term = false;
 		for (; end + strlen("\r\n\r\n") <= dptr + datalen; end++) {
 			if (end[0] == '\r' && end[1] == '\n' &&

base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681

Signature · 1 line
2.43.0