netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: egress: silence egress hook lockdep splats
@ 2022-02-28  3:18 Florian Westphal
  2022-02-28 21:34 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2022-02-28  3:18 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal, Eric Dumazet

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>
---
 include/linux/netfilter_netdev.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/linux/netfilter_netdev.h b/include/linux/netfilter_netdev.h
index b4dd96e4dc8d..e6487a691136 100644
--- a/include/linux/netfilter_netdev.h
+++ b/include/linux/netfilter_netdev.h
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nf] netfilter: egress: silence egress hook lockdep splats
  2022-02-28  3:18 [PATCH nf] netfilter: egress: silence egress hook lockdep splats Florian Westphal
@ 2022-02-28 21:34 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-02-28 21:34 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel, Eric Dumazet

On Mon, Feb 28, 2022 at 04:18:05AM +0100, Florian Westphal wrote:
> 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.

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-28 21:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-28  3:18 [PATCH nf] netfilter: egress: silence egress hook lockdep splats Florian Westphal
2022-02-28 21:34 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).