]> git.itanic.dy.fi Git - linux-stable/commitdiff
netfilter: nf_tables: fix nft_trans type confusion
authorFlorian Westphal <fw@strlen.de>
Thu, 11 May 2023 12:15:15 +0000 (14:15 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 17 May 2023 12:16:02 +0000 (14:16 +0200)
nft_trans_FOO objects all share a common nft_trans base structure, but
trailing fields depend on the real object size. Access is only safe after
trans->msg_type check.

Check for rule type first.  Found by code inspection.

Fixes: 1a94e38d254b ("netfilter: nf_tables: add NFTA_RULE_ID attribute")
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nf_tables_api.c

index 59fb8320ab4d7745ca08e5ffe58cf18c8c196487..dc5675962de4fcfd90518b7ab3d145b60893e2d9 100644 (file)
@@ -3865,12 +3865,10 @@ static struct nft_rule *nft_rule_lookup_byid(const struct net *net,
        struct nft_trans *trans;
 
        list_for_each_entry(trans, &nft_net->commit_list, list) {
-               struct nft_rule *rule = nft_trans_rule(trans);
-
                if (trans->msg_type == NFT_MSG_NEWRULE &&
                    trans->ctx.chain == chain &&
                    id == nft_trans_rule_id(trans))
-                       return rule;
+                       return nft_trans_rule(trans);
        }
        return ERR_PTR(-ENOENT);
 }