Skip to contentSkip to conversation

netfilter: nf_tables: fix nft_trans type confusion

PATCH New Florian Westphal 1 participant 1 message May 11, 2023

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: fix nft_trans type confusion

nft_trans_FOO objects all share a common nft_trans structure, but trailing fields might not ahve been allocated.

This means nft_trans can be treated as nft_trans_FOO only after checking trans->msg_type.

The existing code isn't correct because it treats the object as rule type before the check.

Found by code inspection.

Fixes 1a94e38d254b ("netfilter: nf_tables: add NFTA_RULE_ID attribute")
---
 net/netfilter/nf_tables_api.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +1 -3
index 59fb8320ab4d..dc5675962de4 100644
@@ -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);
 }
Signature · 1 line
2.39.3