]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: egress: silence egress hook lockdep splats
authorFlorian Westphal <fw@strlen.de>
Mon, 28 Feb 2022 03:18:05 +0000 (04:18 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 28 Feb 2022 21:34:04 +0000 (22:34 +0100)
Netfilter assumes its called with rcu_read_lock held, but in egress
hook case it may be called with BH readlock.

This triggers lockdep splat.

In order to avoid to change all rcu_dereference() to
rcu_dereference_check(..., rcu_read_lock_bh_held()), wrap nf_hook_slow
with read lock/unlock pair.

Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/linux/netfilter_netdev.h

index b4dd96e4dc8dca30782ae9c1e8458fb9dae412f7..e6487a69113609307cf2ae0fd274bbab4b9d6012 100644 (file)
@@ -101,7 +101,11 @@ static inline struct sk_buff *nf_hook_egress(struct sk_buff *skb, int *rc,
        nf_hook_state_init(&state, NF_NETDEV_EGRESS,
                           NFPROTO_NETDEV, dev, NULL, NULL,
                           dev_net(dev), NULL);
+
+       /* nf assumes rcu_read_lock, not just read_lock_bh */
+       rcu_read_lock();
        ret = nf_hook_slow(skb, &state, e, 0);
+       rcu_read_unlock();
 
        if (ret == 1) {
                return skb;