Skip to content

Commit 35177c6

Browse files
Qi Tangummakynes
authored andcommitted
netfilter: ctnetlink: zero expect NAT fields when CTA_EXPECT_NAT absent
ctnetlink_alloc_expect() allocates expectations from a non-zeroing slab cache via nf_ct_expect_alloc(). When CTA_EXPECT_NAT is not present in the netlink message, saved_addr and saved_proto are never initialized. Stale data from a previous slab occupant can then be dumped to userspace by ctnetlink_exp_dump_expect(), which checks these fields to decide whether to emit CTA_EXPECT_NAT. The safe sibling nf_ct_expect_init(), used by the packet path, explicitly zeroes these fields. Zero saved_addr, saved_proto and dir in the else branch, guarded by IS_ENABLED(CONFIG_NF_NAT) since these fields only exist when NAT is enabled. Confirmed by priming the expect slab with NAT-bearing expectations, freeing them, creating a new expectation without CTA_EXPECT_NAT, and observing that the ctnetlink dump emits a spurious CTA_EXPECT_NAT containing stale data from the prior allocation. Fixes: 076a0ca ("netfilter: ctnetlink: add NAT support for expectations") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Qi Tang <tpluszz77@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a242a9a commit 35177c6

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

net/netfilter/nf_conntrack_netlink.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,12 @@ ctnetlink_alloc_expect(const struct nlattr * const cda[], struct nf_conn *ct,
35883588
exp, nf_ct_l3num(ct));
35893589
if (err < 0)
35903590
goto err_out;
3591+
#if IS_ENABLED(CONFIG_NF_NAT)
3592+
} else {
3593+
memset(&exp->saved_addr, 0, sizeof(exp->saved_addr));
3594+
memset(&exp->saved_proto, 0, sizeof(exp->saved_proto));
3595+
exp->dir = 0;
3596+
#endif
35913597
}
35923598
return exp;
35933599
err_out:

0 commit comments

Comments
 (0)