mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: tj@kernel.org, jiangshanlai@gmail.com
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
	syzbot+a73d496b2c6919c3f12c@syzkaller.appspotmail.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH] workqueue: Fix false leak report when lockdep is turned off
Date: Wed,  2 Dec 2026 10:52:49 +0800	[thread overview]
Message-ID: <20261202025250.372140-1-jiayuan.chen@linux.dev> (raw)

process_one_work() reads lockdep_depth(current) before and after the work
function and complains if they differ. But lockdep_depth() returns 0 once
debug_locks is cleared:

  #define lockdep_depth(tsk)	(debug_locks ? (tsk)->lockdep_depth : 0)

A BH work item runs on top of whatever task is current, so the start
depth can be non-zero. If lockdep gets turned off while the work function
is running, e.g. by a lockdep splat on another CPU, the second read
returns 0 and we get a bogus report:

BUG: workqueue leaked atomic, lock or RCU: syz-executor[6626]
     preempt=0x00000000 lock=4->0 RCU=2->2 workfn=usb_giveback_urb_bh
INFO: lockdep is turned off.
CPU: 0 UID: 0 PID: 6626 Comm: syz-executor Not tainted syzkaller #0 PREEMPT_{RT,(full)}
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 process_one_work kernel/workqueue.c:3516 [inline]
 process_scheduled_works+0x12c2/0x1630 kernel/workqueue.c:3578
 bh_worker+0x4b3/0xbb0 kernel/workqueue.c:3885
 tasklet_hi_action+0xf/0x70 kernel/softirq.c:1028
 handle_softirqs+0x1d4/0x6c0 kernel/softirq.c:669
 __do_softirq kernel/softirq.c:703 [inline]
 __local_bh_enable_ip+0x16f/0x2b0 kernel/softirq.c:325
 local_bh_enable include/linux/bottom_half.h:33 [inline]
 __alloc_skb+0x1b1/0x7a0 net/core/skbuff.c:700
 alloc_skb include/linux/skbuff.h:1390 [inline]
 nlmsg_new include/net/netlink.h:1055 [inline]
 rtmsg_fib+0xda/0x440 net/ipv4/fib_semantics.c:584
 fib_table_insert+0xd54/0x1b10 net/ipv4/fib_trie.c:1381
 fib_magic+0x43b/0x530 net/ipv4/fib_frontend.c:1147
 fib_add_ifaddr+0x376/0x5d0 net/ipv4/fib_frontend.c:1184
 fib_netdev_event+0x382/0x490 net/ipv4/fib_frontend.c:1529
 notifier_call_chain+0x1a5/0x3d0 kernel/notifier.c:86
 call_netdevice_notifiers_extack net/core/dev.c:2351 [inline]
 call_netdevice_notifiers net/core/dev.c:2365 [inline]
 __dev_notify_flags+0x31e/0x510 net/core/dev.c:10063
 netif_change_flags+0xde/0x1b0 net/core/dev.c:10092
 do_setlink+0xdd6/0x47a0 net/core/rtnetlink.c:3294
 rtnl_changelink net/core/rtnetlink.c:3942 [inline]
 __rtnl_newlink net/core/rtnetlink.c:4113 [inline]
 rtnl_newlink+0x15b0/0x1c30 net/core/rtnetlink.c:4252
 rtnetlink_rcv_msg+0x802/0xc00 net/core/rtnetlink.c:7169
 netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2585
 netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
 netlink_unicast+0x90c/0xac0 net/netlink/af_netlink.c:1362
 netlink_sendmsg+0x7f0/0xb20 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
 __sock_sendmsg net/socket.c:818 [inline]
 __sys_sendto+0x41e/0x5d0 net/socket.c:2283
 __do_sys_sendto net/socket.c:2290 [inline]
 __se_sys_sendto net/socket.c:2286 [inline]
 __x64_sys_sendto+0xde/0x100 net/socket.c:2286
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
 </TASK>

Lockdep stops tracking the depth once it is off, so skip the depth check
in that case. debug_locks is tested after the depth is read: it is not
set back at runtime, so if it is still set the depth we read is valid.

In the syzbot report the lockdep splat came from an unrelated kworker
on the other CPU.

Fixes: 4cb1ef64609f ("workqueue: Implement BH workqueues to eventually replace tasklets")
Reported-by: syzbot+a73d496b2c6919c3f12c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a73d496b2c6919c3f12c
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
 kernel/workqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index a2a441837a9d..e64c643a6f5c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3506,7 +3506,8 @@ __acquires(&pool->lock)
 		lock_map_release(pwq->wq->lockdep_map);
 
 	if (unlikely((worker->task && in_atomic()) ||
-		     lockdep_depth(current) != lockdep_start_depth ||
+		     (lockdep_depth(current) != lockdep_start_depth &&
+		      debug_locks) ||
 		     rcu_preempt_depth() != rcu_start_depth)) {
 		pr_err("BUG: workqueue leaked atomic, lock or RCU: %s[%d]\n"
 		       "     preempt=0x%08x lock=%d->%d RCU=%d->%d workfn=%ps\n",
-- 
2.43.0


                 reply	other threads:[~2026-12-02  2:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202025250.372140-1-jiayuan.chen@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+a73d496b2c6919c3f12c@syzkaller.appspotmail.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®