Skip to content

Commit 447750f

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: don't use position attribute on rule replacement
Its possible to set both HANDLE and POSITION when replacing a rule. In this case, the rule at POSITION gets replaced using the userspace-provided handle. Rule handles are supposed to be generated by the kernel only. Duplicate handles should be harmless, however better disable this "feature" by only checking for the POSITION attribute on insert operations. Fixes: 5e94846 ("netfilter: nf_tables: add insert operation") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 25d8bce commit 447750f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,17 +2589,14 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
25892589

25902590
if (chain->use == UINT_MAX)
25912591
return -EOVERFLOW;
2592-
}
2593-
2594-
if (nla[NFTA_RULE_POSITION]) {
2595-
if (!(nlh->nlmsg_flags & NLM_F_CREATE))
2596-
return -EOPNOTSUPP;
25972592

2598-
pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
2599-
old_rule = __nft_rule_lookup(chain, pos_handle);
2600-
if (IS_ERR(old_rule)) {
2601-
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
2602-
return PTR_ERR(old_rule);
2593+
if (nla[NFTA_RULE_POSITION]) {
2594+
pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
2595+
old_rule = __nft_rule_lookup(chain, pos_handle);
2596+
if (IS_ERR(old_rule)) {
2597+
NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
2598+
return PTR_ERR(old_rule);
2599+
}
26032600
}
26042601
}
26052602

0 commit comments

Comments
 (0)