Skip to content

Commit 8509f62

Browse files
committed
netfilter: nf_tables: hit ENOENT on unexisting chain/flowtable update with missing attributes
If user does not specify hook number and priority, then assume this is a chain/flowtable update. Therefore, report ENOENT which provides a better hint than EINVAL. Set on extended netlink error report to refer to the chain name. Fixes: 5b6743f ("netfilter: nf_tables: skip flowtable hooknum and priority on device updates") Fixes: 5efe72698a97 ("netfilter: nf_tables: support for adding new devices to an existing netdev chain") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent c6d96df commit 8509f62

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,10 @@ static int nft_chain_parse_hook(struct net *net,
20752075

20762076
if (!basechain) {
20772077
if (!ha[NFTA_HOOK_HOOKNUM] ||
2078-
!ha[NFTA_HOOK_PRIORITY])
2079-
return -EINVAL;
2078+
!ha[NFTA_HOOK_PRIORITY]) {
2079+
NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_NAME]);
2080+
return -ENOENT;
2081+
}
20802082

20812083
hook->num = ntohl(nla_get_be32(ha[NFTA_HOOK_HOOKNUM]));
20822084
hook->priority = ntohl(nla_get_be32(ha[NFTA_HOOK_PRIORITY]));
@@ -7693,7 +7695,7 @@ static const struct nla_policy nft_flowtable_hook_policy[NFTA_FLOWTABLE_HOOK_MAX
76937695
};
76947696

76957697
static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
7696-
const struct nlattr *attr,
7698+
const struct nlattr * const nla[],
76977699
struct nft_flowtable_hook *flowtable_hook,
76987700
struct nft_flowtable *flowtable,
76997701
struct netlink_ext_ack *extack, bool add)
@@ -7705,15 +7707,18 @@ static int nft_flowtable_parse_hook(const struct nft_ctx *ctx,
77057707

77067708
INIT_LIST_HEAD(&flowtable_hook->list);
77077709

7708-
err = nla_parse_nested_deprecated(tb, NFTA_FLOWTABLE_HOOK_MAX, attr,
7710+
err = nla_parse_nested_deprecated(tb, NFTA_FLOWTABLE_HOOK_MAX,
7711+
nla[NFTA_FLOWTABLE_HOOK],
77097712
nft_flowtable_hook_policy, NULL);
77107713
if (err < 0)
77117714
return err;
77127715

77137716
if (add) {
77147717
if (!tb[NFTA_FLOWTABLE_HOOK_NUM] ||
7715-
!tb[NFTA_FLOWTABLE_HOOK_PRIORITY])
7716-
return -EINVAL;
7718+
!tb[NFTA_FLOWTABLE_HOOK_PRIORITY]) {
7719+
NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_NAME]);
7720+
return -ENOENT;
7721+
}
77177722

77187723
hooknum = ntohl(nla_get_be32(tb[NFTA_FLOWTABLE_HOOK_NUM]));
77197724
if (hooknum != NF_NETDEV_INGRESS)
@@ -7898,8 +7903,8 @@ static int nft_flowtable_update(struct nft_ctx *ctx, const struct nlmsghdr *nlh,
78987903
u32 flags;
78997904
int err;
79007905

7901-
err = nft_flowtable_parse_hook(ctx, nla[NFTA_FLOWTABLE_HOOK],
7902-
&flowtable_hook, flowtable, extack, false);
7906+
err = nft_flowtable_parse_hook(ctx, nla, &flowtable_hook, flowtable,
7907+
extack, false);
79037908
if (err < 0)
79047909
return err;
79057910

@@ -8044,8 +8049,8 @@ static int nf_tables_newflowtable(struct sk_buff *skb,
80448049
if (err < 0)
80458050
goto err3;
80468051

8047-
err = nft_flowtable_parse_hook(&ctx, nla[NFTA_FLOWTABLE_HOOK],
8048-
&flowtable_hook, flowtable, extack, true);
8052+
err = nft_flowtable_parse_hook(&ctx, nla, &flowtable_hook, flowtable,
8053+
extack, true);
80498054
if (err < 0)
80508055
goto err4;
80518056

@@ -8107,8 +8112,8 @@ static int nft_delflowtable_hook(struct nft_ctx *ctx,
81078112
struct nft_trans *trans;
81088113
int err;
81098114

8110-
err = nft_flowtable_parse_hook(ctx, nla[NFTA_FLOWTABLE_HOOK],
8111-
&flowtable_hook, flowtable, extack, false);
8115+
err = nft_flowtable_parse_hook(ctx, nla, &flowtable_hook, flowtable,
8116+
extack, false);
81128117
if (err < 0)
81138118
return err;
81148119

0 commit comments

Comments
 (0)