netfilter: nf_tables: missing extended netlink error in lookup functions
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 22 Aug 2023 17:11:17 +0000 (19:11 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 28 Sep 2023 14:25:42 +0000 (16:25 +0200)
Set netlink extended error reporting for several lookup functions which
allows userspace to infer what is the error cause.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nf_tables_api.c

index 4356189360fb88d695b25070264783520aeef6b1..f993c237afd015bb936bf5f751b02d9e3145a779 100644 (file)
@@ -4695,8 +4695,10 @@ static int nf_tables_getset(struct sk_buff *skb, const struct nfnl_info *info,
                return -EINVAL;
 
        set = nft_set_lookup(table, nla[NFTA_SET_NAME], genmask);
-       if (IS_ERR(set))
+       if (IS_ERR(set)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_SET_NAME]);
                return PTR_ERR(set);
+       }
 
        skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
        if (skb2 == NULL)
@@ -6025,8 +6027,10 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
        }
 
        set = nft_set_lookup(table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
-       if (IS_ERR(set))
+       if (IS_ERR(set)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_SET_ELEM_LIST_SET]);
                return PTR_ERR(set);
+       }
 
        nft_ctx_init(&ctx, net, skb, info->nlh, family, table, NULL, nla);
 
@@ -6919,8 +6923,10 @@ static int nf_tables_newsetelem(struct sk_buff *skb,
 
        set = nft_set_lookup_global(net, table, nla[NFTA_SET_ELEM_LIST_SET],
                                    nla[NFTA_SET_ELEM_LIST_SET_ID], genmask);
-       if (IS_ERR(set))
+       if (IS_ERR(set)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_SET_ELEM_LIST_SET]);
                return PTR_ERR(set);
+       }
 
        if (!list_empty(&set->bindings) &&
            (set->flags & (NFT_SET_CONSTANT | NFT_SET_ANONYMOUS)))
@@ -7195,8 +7201,10 @@ static int nf_tables_delsetelem(struct sk_buff *skb,
        }
 
        set = nft_set_lookup(table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
-       if (IS_ERR(set))
+       if (IS_ERR(set)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_SET_ELEM_LIST_SET]);
                return PTR_ERR(set);
+       }
 
        if (nft_set_is_anonymous(set))
                return -EOPNOTSUPP;
@@ -8680,6 +8688,7 @@ static int nf_tables_getflowtable(struct sk_buff *skb,
                                  const struct nfnl_info *info,
                                  const struct nlattr * const nla[])
 {
+       struct netlink_ext_ack *extack = info->extack;
        u8 genmask = nft_genmask_cur(info->net);
        u8 family = info->nfmsg->nfgen_family;
        struct nft_flowtable *flowtable;
@@ -8705,13 +8714,17 @@ static int nf_tables_getflowtable(struct sk_buff *skb,
 
        table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
                                 genmask, 0);
-       if (IS_ERR(table))
+       if (IS_ERR(table)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_TABLE]);
                return PTR_ERR(table);
+       }
 
        flowtable = nft_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
                                         genmask);
-       if (IS_ERR(flowtable))
+       if (IS_ERR(flowtable)) {
+               NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_NAME]);
                return PTR_ERR(flowtable);
+       }
 
        skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
        if (!skb2)