]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netfilter: conntrack: add missing netlink policy validations
authorFlorian Westphal <fw@strlen.de>
Mon, 9 Mar 2026 23:28:29 +0000 (00:28 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 13 Mar 2026 14:31:14 +0000 (15:31 +0100)
Hyunwoo Kim reports out-of-bounds access in sctp and ctnetlink.

These attributes are used by the kernel without any validation.
Extend the netlink policies accordingly.

Quoting the reporter:
  nlattr_to_sctp() assigns the user-supplied CTA_PROTOINFO_SCTP_STATE
  value directly to ct->proto.sctp.state without checking that it is
  within the valid range. [..]

  and: ... with exp->dir = 100, the access at
  ct->master->tuplehash[100] reads 5600 bytes past the start of a
  320-byte nf_conn object, causing a slab-out-of-bounds read confirmed by
  UBSAN.

Fixes: 076a0ca02644 ("netfilter: ctnetlink: add NAT support for expectations")
Fixes: a258860e01b8 ("netfilter: ctnetlink: add full support for SCTP to ctnetlink")
Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nf_conntrack_netlink.c
net/netfilter/nf_conntrack_proto_sctp.c

index 65aa44a12d0143f4ec58cba070256c4643bf5a18..c156574e127389ab1941bd38e72cc31c1cd29363 100644 (file)
@@ -3489,7 +3489,7 @@ ctnetlink_change_expect(struct nf_conntrack_expect *x,
 
 #if IS_ENABLED(CONFIG_NF_NAT)
 static const struct nla_policy exp_nat_nla_policy[CTA_EXPECT_NAT_MAX+1] = {
-       [CTA_EXPECT_NAT_DIR]    = { .type = NLA_U32 },
+       [CTA_EXPECT_NAT_DIR]    = NLA_POLICY_MAX(NLA_BE32, IP_CT_DIR_REPLY),
        [CTA_EXPECT_NAT_TUPLE]  = { .type = NLA_NESTED },
 };
 #endif
index 7c6f7c9f73320dd208bd0940f539bd9e662e62d0..645d2c43ebf7af94b50ec9215cced174eb2d6891 100644 (file)
@@ -582,7 +582,8 @@ nla_put_failure:
 }
 
 static const struct nla_policy sctp_nla_policy[CTA_PROTOINFO_SCTP_MAX+1] = {
-       [CTA_PROTOINFO_SCTP_STATE]          = { .type = NLA_U8 },
+       [CTA_PROTOINFO_SCTP_STATE]          = NLA_POLICY_MAX(NLA_U8,
+                                                        SCTP_CONNTRACK_HEARTBEAT_SENT),
        [CTA_PROTOINFO_SCTP_VTAG_ORIGINAL]  = { .type = NLA_U32 },
        [CTA_PROTOINFO_SCTP_VTAG_REPLY]     = { .type = NLA_U32 },
 };