netfilter: ctnetlink: avoid null pointer dereference
authorFlorian Westphal <fw@strlen.de>
Mon, 11 Jun 2018 20:22:19 +0000 (22:22 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 12 Jun 2018 17:31:07 +0000 (19:31 +0200)
Dan Carpenter points out that deref occurs after NULL check, we should
re-fetch the pointer and check that instead.

Fixes: 2c205dd3981f7 ("netfilter: add struct nf_nat_hook and use it")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_netlink.c

index 39327a42879f7f614fa46f6577c3f883aa3714ce..20a2e37c76d124e31771c9bf96bd13216501202a 100644 (file)
@@ -1446,7 +1446,8 @@ ctnetlink_parse_nat_setup(struct nf_conn *ct,
                }
                nfnl_lock(NFNL_SUBSYS_CTNETLINK);
                rcu_read_lock();
-               if (nat_hook->parse_nat_setup)
+               nat_hook = rcu_dereference(nf_nat_hook);
+               if (nat_hook)
                        return -EAGAIN;
 #endif
                return -EOPNOTSUPP;