]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: exit in case we can't fetch current genid
authorFlorian Westphal <fw@strlen.de>
Sun, 14 Jul 2019 08:49:28 +0000 (10:49 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 15 Jul 2019 10:26:36 +0000 (12:26 +0200)
When running iptables -nL as non-root user, iptables would loop indefinitely.

With this change, it will fail with
iptables v1.8.3 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)

Reported-by: Amish <anon.amish@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft.c

index e927d1db2b426930c104b9b36bf4fb8d1832b112..8f0d5e664eca67d68cc515653be9bf43f476f813 100644 (file)
@@ -82,13 +82,19 @@ out:
        return MNL_CB_ERROR;
 }
 
-static int mnl_genid_get(struct nft_handle *h, uint32_t *genid)
+static void mnl_genid_get(struct nft_handle *h, uint32_t *genid)
 {
        char buf[MNL_SOCKET_BUFFER_SIZE];
        struct nlmsghdr *nlh;
+       int ret;
 
        nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_GETGEN, 0, 0, h->seq);
-       return mnl_talk(h, nlh, genid_cb, genid);
+       ret = mnl_talk(h, nlh, genid_cb, genid);
+       if (ret == 0)
+               return;
+
+       xtables_error(RESOURCE_PROBLEM,
+                     "Could not fetch rule set generation id: %s\n", nft_strerror(errno));
 }
 
 int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,