All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net_sched: gen_estimator: fix lockdep splat
@ 2018-01-27 18:58 Eric Dumazet
  2018-01-29  3:44 ` Cong Wang
  2018-01-29 19:31 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2018-01-27 18:58 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Jamal Hadi Salim, Cong Wang, Jiri Pirko

From: Eric Dumazet <edumazet@google.com>

syzbot reported a lockdep splat in gen_new_estimator() /
est_fetch_counters() when attempting to lock est->stats_lock.

Since est_fetch_counters() is called from BH context from timer
interrupt, we need to block BH as well when calling it from process
context.

Most qdiscs use per cpu counters and are immune to the problem,
but net/sched/act_api.c and net/netfilter/xt_RATEEST.c are using
a spinlock to protect their data. They both call gen_new_estimator()
while object is created and not yet alive, so this bug could
not trigger a deadlock, only a lockdep splat.

Fixes: 1c0d32fde5bd ("net_sched: gen_estimator: complete rewrite of rate estimators")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
---
 net/core/gen_estimator.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c
index 9834cfa21b21168a7654290dc2a999e41937b534..0a3f88f08727f1f1217560407ff539c8a8c17496 100644
--- a/net/core/gen_estimator.c
+++ b/net/core/gen_estimator.c
@@ -159,7 +159,11 @@ int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
 	est->intvl_log = intvl_log;
 	est->cpu_bstats = cpu_bstats;
 
+	if (stats_lock)
+		local_bh_disable();
 	est_fetch_counters(est, &b);
+	if (stats_lock)
+		local_bh_enable();
 	est->last_bytes = b.bytes;
 	est->last_packets = b.packets;
 	old = rcu_dereference_protected(*rate_est, 1);

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

* Re: [PATCH net] net_sched: gen_estimator: fix lockdep splat
  2018-01-27 18:58 [PATCH net] net_sched: gen_estimator: fix lockdep splat Eric Dumazet
@ 2018-01-29  3:44 ` Cong Wang
  2018-01-29 19:31 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2018-01-29  3:44 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev, Jamal Hadi Salim, Jiri Pirko

On Sat, Jan 27, 2018 at 10:58 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> syzbot reported a lockdep splat in gen_new_estimator() /
> est_fetch_counters() when attempting to lock est->stats_lock.
>
> Since est_fetch_counters() is called from BH context from timer
> interrupt, we need to block BH as well when calling it from process
> context.
>
> Most qdiscs use per cpu counters and are immune to the problem,
> but net/sched/act_api.c and net/netfilter/xt_RATEEST.c are using
> a spinlock to protect their data. They both call gen_new_estimator()
> while object is created and not yet alive, so this bug could
> not trigger a deadlock, only a lockdep splat.
>
> Fixes: 1c0d32fde5bd ("net_sched: gen_estimator: complete rewrite of rate estimators")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>

Acked-by: Cong Wang <xiyou.wangcong@gmail.com>

Nit: perhaps it is better to move the spin_lock out of est_fetch_counters()
and let callers decide to use spin_lock or spin_lock_bh.

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

* Re: [PATCH net] net_sched: gen_estimator: fix lockdep splat
  2018-01-27 18:58 [PATCH net] net_sched: gen_estimator: fix lockdep splat Eric Dumazet
  2018-01-29  3:44 ` Cong Wang
@ 2018-01-29 19:31 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-01-29 19:31 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, jhs, xiyou.wangcong, jiri

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 27 Jan 2018 10:58:43 -0800

> From: Eric Dumazet <edumazet@google.com>
> 
> syzbot reported a lockdep splat in gen_new_estimator() /
> est_fetch_counters() when attempting to lock est->stats_lock.
> 
> Since est_fetch_counters() is called from BH context from timer
> interrupt, we need to block BH as well when calling it from process
> context.
> 
> Most qdiscs use per cpu counters and are immune to the problem,
> but net/sched/act_api.c and net/netfilter/xt_RATEEST.c are using
> a spinlock to protect their data. They both call gen_new_estimator()
> while object is created and not yet alive, so this bug could
> not trigger a deadlock, only a lockdep splat.
> 
> Fixes: 1c0d32fde5bd ("net_sched: gen_estimator: complete rewrite of rate estimators")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>

Applied, thanks.

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

end of thread, other threads:[~2018-01-29 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-27 18:58 [PATCH net] net_sched: gen_estimator: fix lockdep splat Eric Dumazet
2018-01-29  3:44 ` Cong Wang
2018-01-29 19:31 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.