netfilter: nf_conntrack_sip: fix OOB read in epaddr_len and ct_sip_parse_header_uri
Subsystems (3)
PATCH 1/1 netfilter: nf_conntrack_sip: fix OOB read in epaddr_len and ct_sip_parse_header_uri
In epaddr_len() and ct_sip_parse_header_uri(), after sip_parse_addr() successfully parses an IP address, the code checks whether the next character is ':' to determine if a port number follows. However, neither function verifies that the pointer is still within bounds before dereferencing it.
When a SIP header URI contains an IP address that extends to the last byte of the packet data, in4_pton() or in6_pton() consumes all available bytes and returns with the end pointer equal to limit. The subsequent dereference reads one byte past the valid SIP message data.
ct_sip_parse_request() already handles this correctly:
if (end < limit && *end == ':') {Apply the same bounds check to the two functions that are missing it.
--- net/netfilter/nf_conntrack_sip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +2 -2
@@ -194,7 +194,7 @@ static int epaddr_len(const struct nf_conn *ct, const char *dptr, }/* Port number */ -if (*dptr ==':' ) { +if (dptr < limit && *dptr ==':' ) { dptr++; dptr +=digits_len (ct, dptr, limit, shift); }
@@ -520,7 +520,7 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,if (!sip_parse_addr (ct, dptr + *matchoff, &c, addr, limit, true))return -1 ; -if (*c ==':' ) { +if (c < limit && *c ==':' ) { c++; p =simple_strtoul (c, (char **)&c,10 );if (p <1024 || p >65535 )
Signature · 1 line
2.43.0
Florian Westphal
maintainerQuoted 5 lines · Weiming Shi
In
epaddr_len()andct_sip_parse_header_uri(), aftersip_parse_addr()successfully parses an IP address, the code checks whether the next character is ':' to determine if a port number follows. However, neither function verifies that the pointer is still within bounds before dereferencing it.
I already queued up:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
for nf-next (I already sent the 'last' PR for 7.0).
Could you check if that resolves the problem you're reporting?
Quoted 1 line
p =
simple_strtoul(c, (char **)&c, 10);
All of these functions require a c-string, which we usually don't have with network packet parsing.
IOW, sip helper needs to be audited for these problems but I don't know when I can get to it.
Weiming Shi
Tested-byQuoted 14 lines · Florian Westphal
Quoted 5 lines · Weiming Shi
In
epaddr_len()andct_sip_parse_header_uri(), aftersip_parse_addr()successfully parses an IP address, the code checks whether the next character is ':' to determine if a port number follows. However, neither function verifies that the pointer is still within bounds before dereferencing it.I already queued up:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/for nf-next (I already sent the 'last' PR for 7.0).
Could you check if that resolves the problem you're reporting?
Quoted 7 lines
Quoted 1 line
p =
simple_strtoul(c, (char **)&c, 10);All of these functions require a c-string, which we usually don't have with network packet parsing.
IOW, sip helper needs to be audited for these problems but I don't know when I can get to it.