]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
netfilter: nf_tables: don't use position attribute on rule replacement
authorFlorian Westphal <fw@strlen.de>
Sun, 4 Nov 2018 11:07:14 +0000 (12:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Dec 2019 07:51:11 +0000 (08:51 +0100)
[ Upstream commit 447750f281abef547be44fdcfe3bc4447b3115a8 ]

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: 5e94846686d0 ("netfilter: nf_tables: add insert operation")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nf_tables_api.c

index ec0f8b5bde0aa2ce87ebb8efbdc36233a4166e7b..0e1b1f7f4745e7d1defb3eda63794270f39d86e1 100644 (file)
@@ -2610,17 +2610,14 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
 
                if (chain->use == UINT_MAX)
                        return -EOVERFLOW;
-       }
-
-       if (nla[NFTA_RULE_POSITION]) {
-               if (!(nlh->nlmsg_flags & NLM_F_CREATE))
-                       return -EOPNOTSUPP;
 
-               pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
-               old_rule = __nft_rule_lookup(chain, pos_handle);
-               if (IS_ERR(old_rule)) {
-                       NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
-                       return PTR_ERR(old_rule);
+               if (nla[NFTA_RULE_POSITION]) {
+                       pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
+                       old_rule = __nft_rule_lookup(chain, pos_handle);
+                       if (IS_ERR(old_rule)) {
+                               NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
+                               return PTR_ERR(old_rule);
+                       }
                }
        }