public inbox for netfilter-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netfilter: nf_nat_sip: validate exp->dir in nf_nat_sip_expected()
@ 2026-03-13 20:13 Jenny Guanni Qu
  2026-03-13 23:32 ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: Jenny Guanni Qu @ 2026-03-13 20:13 UTC (permalink / raw)
  To: pablo, kadlec; +Cc: netfilter-devel, fw, Jenny Guanni Qu

nf_nat_sip_expected() uses exp->dir to index into the 2-element
tuplehash[] array without bounds checking. If exp->dir has an
out-of-range value, this causes a slab-out-of-bounds read.

KASAN reports:

  BUG: KASAN: slab-out-of-bounds in nf_nat_sip_expected+0x804/0x938
  Read of size 8 at addr ffff0000d113e3b8
  The buggy address is located 72 bytes to the right of
   allocated 240-byte region

Add a bounds check to ensure exp->dir is less than IP_CT_DIR_MAX.

Fixes: 9a6648210687 ("netfilter: nf_nat: support IPv6 in SIP NAT helper")
Reported-by: Jenny Guanni Qu <qguanni@gmail.com>
Tested-by: Jenny Guanni Qu <qguanni@gmail.com>
Signed-off-by: Jenny Guanni Qu <qguanni@gmail.com>
---
 net/netfilter/nf_nat_sip.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
index cf4aeb299bde..48b1b2d70a1e 100644
--- a/net/netfilter/nf_nat_sip.c
+++ b/net/netfilter/nf_nat_sip.c
@@ -326,6 +326,9 @@ static void nf_nat_sip_expected(struct nf_conn *ct,
 	/* This must be a fresh one. */
 	BUG_ON(ct->status & IPS_NAT_DONE_MASK);
 
+	if (exp->dir >= IP_CT_DIR_MAX)
+		return;
+
 	/* For DST manip, map port here to where it's expected. */
 	range.flags = (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED);
 	range.min_proto = range.max_proto = exp->saved_proto;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-15  7:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 20:13 [PATCH] netfilter: nf_nat_sip: validate exp->dir in nf_nat_sip_expected() Jenny Guanni Qu
2026-03-13 23:32 ` Florian Westphal
2026-03-14 11:50   ` Pablo Neira Ayuso
2026-03-14 22:21     ` Guanni Qu
2026-03-15  7:26       ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox