KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on

Status: moderation: reported on 2026/11/23 06:25
Subsystems: rds
Labels: prio:high race:benign
[Documentation on labels]
Reported-by: syzbot+397ea23d5af42ce48bb1@syzkaller.appspotmail.com
First crash: 4d00h, last: 1h56m
✨ AI-generated root cause summary:

In kernel/workqueue.c, work->data (accessed via work_data_bits(work)) is manipulated locklessly by queue_work_on() and queue_delayed_work_on() via test_and_set_bit(WORK_STRUCT_PENDING_BIT, ...). When a work item is queued on an ordered or congested workqueue where nr_active >= max_active, it is placed onto pwq->inactive_works with both WORK_STRUCT_PENDING and WORK_STRUCT_INACTIVE set in work->data. When an earlier work item completes, the worker thread activates the pending work item in __pwq_activate_work() under pwq->pool->lock using an unmarked plain C read (*wdb & WORK_STRUCT_INACTIVE) and a non-atomic __clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb). A concurrent call to queue_delayed_work_on() (e.g., from rds_tcp_write_space() in softirq) executes test_and_set_bit() locklessly on the same atomic_long_t word, triggering a KCSAN data race.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 4405c18c95d2:

Technical Root Cause Analysis

Involved Components

  • Source file: kernel/workqueue.c (triggered via legitimate use from net/rds/tcp_send.c / net/rds/connection.c)
  • Functions: __pwq_activate_work(), queue_delayed_work_on(), queue_work_on()
  • Structures and fields: struct work_struct::data (atomic_long_t), accessed via work_data_bits(work) (unsigned long *), struct pool_workqueue::inactive_works, and flag bits WORK_STRUCT_PENDING_BIT (bit 0) and WORK_STRUCT_INACTIVE_BIT (bit 1).

Mechanism and Trigger Sequence

  1. Lockless PENDING claiming in Workqueue Queueing API: In kernel/workqueue.c, functions such as queue_work_on() and queue_delayed_work_on() (lines 2765, 2597) are intentionally callable from any context (including interrupt/softirq contexts) without acquiring pool->lock. To determine whether a work item can be queued, they perform an atomic bit operation:

    test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))
    

    This operation executes an atomic read-modify-write (LOCK BTS on x86, instrumented as an atomic RMW by KCSAN) directly on work->data.

  2. Inactive Work Placement: In the reported scenario, net/rds allocates an ordered workqueue (alloc_ordered_workqueue("krds_cp_wq#%lu/%d", 0, ...)) where max_active == 1. When a work item such as cp->cp_send_w is queued while another work item is already in flight (pwq->nr_active >= max_active), __queue_work() inserts it into pwq->inactive_works and marks work->data with both WORK_STRUCT_PENDING and WORK_STRUCT_INACTIVE (lines 2549–2550).

  3. Activation from inactive_works: When the running work item finishes, the worker thread executes pwq_dec_nr_in_flight() -> pwq_dec_nr_active() -> node_activate_pending_pwq() -> __pwq_activate_work(). __pwq_activate_work() (lines 1813–1824) runs under pwq->pool->lock and nna->lock:

    static void __pwq_activate_work(struct pool_workqueue *pwq,
                    struct work_struct *work)
    {
        unsigned long *wdb = work_data_bits(work);
    
        WARN_ON_ONCE(!(*wdb & WORK_STRUCT_INACTIVE));
        trace_workqueue_activate_work(work);
        if (list_empty(&pwq->pool->worklist))
            pwq->pool->last_progress_ts = jiffies;
        move_linked_works(work, &pwq->pool->worklist, NULL);
        __clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb);
    }
    
  4. The Data Race: While CPU 0 executes __pwq_activate_work() and accesses work->data using an unmarked plain C read (*wdb & WORK_STRUCT_INACTIVE at line 1818, followed by __clear_bit(WORK_STRUCT_INACTIVE_BIT, wdb) at line 1823), an incoming TCP packet triggers softirq execution on CPU 1. In softirq context, rds_tcp_write_space() calls:

    queue_delayed_work(cp->cp_wq, &cp->cp_send_w, 0);
    

    which invokes queue_delayed_work_on(). Because queue_delayed_work_on() executes test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) locklessly outside pool->lock, an atomic read-modify-write access to work->data occurs concurrently with the plain unmarked read in __pwq_activate_work(), causing KCSAN to report a data race.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
630d0127 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on 2026/11/19 06:10 2026/11/19 06:10 2026/11/19 06:38 2006bdcc
b09b84e0 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ✅ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on 2026/11/19 06:03 2026/11/19 06:03 2026/11/19 06:16 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on

read-write (marked) to 0xffff88811bbca090 of 8 bytes by interrupt on cpu 1:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 test_and_set_bit include/asm-generic/bitops/instrumented-atomic.h:71 [inline]
 queue_delayed_work_on+0x45/0x160 kernel/workqueue.c:2765
 queue_delayed_work include/linux/workqueue.h:715 [inline]
 rds_tcp_write_space+0x25b/0x2a0 net/rds/tcp_send.c:204
 tcp_new_space net/ipv4/tcp_input.c:6178 [inline]
 __tcp_check_space+0x421/0x590 net/ipv4/tcp_input.c:6201
 tcp_check_space include/net/tcp.h:827 [inline]
 tcp_data_snd_check net/ipv4/tcp_input.c:6209 [inline]
 tcp_rcv_established+0x11c5/0x1390 net/ipv4/tcp_input.c:6793
 tcp_v6_do_rcv+0x47f/0xdf0 net/ipv6/tcp_ipv6.c:1632
 tcp_v6_rcv+0x19d6/0x1c80 net/ipv6/tcp_ipv6.c:1909
 ip6_protocol_deliver_rcu+0xa6d/0x11e0 net/ipv6/ip6_input.c:479
 ip6_input_finish+0xf0/0x1c0 net/ipv6/ip6_input.c:538
 NF_HOOK include/linux/netfilter.h:325 [inline]
 ip6_input+0x5e/0x160 net/ipv6/ip6_input.c:549
 dst_input include/net/dst.h:482 [inline]
 ip6_sublist_rcv_finish net/ipv6/ip6_input.c:128 [inline]
 ip6_list_rcv_finish net/ipv6/ip6_input.c:185 [inline]
 ip6_sublist_rcv+0x8fe/0xa20 net/ipv6/ip6_input.c:361
 ipv6_list_rcv+0x267/0x2a0 net/ipv6/ip6_input.c:395
 __netif_receive_skb_list_ptype net/core/dev.c:6494 [inline]
 __netif_receive_skb_list_core+0x3c8/0x520 net/core/dev.c:6541
 __netif_receive_skb_list net/core/dev.c:6593 [inline]
 netif_receive_skb_list_internal+0x471/0x5e0 net/core/dev.c:6684
 gro_normal_list include/net/gro.h:539 [inline]
 gro_normal_one include/net/gro.h:559 [inline]
 gro_skb_finish net/core/gro.c:643 [inline]
 gro_receive_skb+0x3a8/0x590 net/core/gro.c:673
 napi_gro_receive include/linux/netdevice.h:4374 [inline]
 veth_xdp_rcv drivers/net/veth.c:951 [inline]
 veth_poll+0x1705/0x21f0 drivers/net/veth.c:991
 __napi_poll+0x73/0x350 net/core/dev.c:8001
 napi_poll net/core/dev.c:8064 [inline]
 net_rx_action+0x33f/0x850 net/core/dev.c:8221
 handle_softirqs+0x109/0x310 kernel/softirq.c:669
 do_softirq+0x46/0x60 kernel/softirq.c:569
 __local_bh_enable_ip+0x79/0x80 kernel/softirq.c:473
 local_bh_enable include/linux/bottom_half.h:33 [inline]
 rcu_read_unlock_bh include/linux/rcupdate.h:923 [inline]
 __dev_queue_xmit+0x1502/0x2020 net/core/dev.c:5135
 dev_queue_xmit include/linux/netdevice.h:3485 [inline]
 neigh_hh_output include/net/neighbour.h:538 [inline]
 neigh_output include/net/neighbour.h:552 [inline]
 ip6_finish_output2+0x974/0xe80 net/ipv6/ip6_output.c:138
 __ip6_finish_output net/ipv6/ip6_output.c:-1 [inline]
 ip6_finish_output+0x1e1/0x410 net/ipv6/ip6_output.c:221
 NF_HOOK_COND include/linux/netfilter.h:314 [inline]
 ip6_output+0x10a/0x280 net/ipv6/ip6_output.c:248
 dst_output include/net/dst.h:472 [inline]
 NF_HOOK include/linux/netfilter.h:325 [inline]
 ip6_xmit+0x900/0xcd0 net/ipv6/ip6_output.c:381
 inet6_csk_xmit+0x193/0x240 net/ipv6/inet6_connection_sock.c:121
 __tcp_transmit_skb+0x1822/0x2110 net/ipv4/tcp_output.c:1773
 tcp_transmit_skb net/ipv4/tcp_output.c:1790 [inline]
 tcp_write_xmit+0x13b5/0x30e0 net/ipv4/tcp_output.c:3126
 tcp_push_one+0x7e/0xa0 net/ipv4/tcp_output.c:3323
 tcp_sendmsg_locked+0x1e7e/0x2df0 net/ipv4/tcp.c:1408
 tcp_sendmsg+0x2f/0x50 net/ipv4/tcp.c:1465
 inet6_sendmsg+0x76/0xd0 net/ipv6/af_inet6.c:638
 sock_sendmsg_nosec net/socket.c:800 [inline]
 __sock_sendmsg net/socket.c:818 [inline]
 sock_write_iter+0x21c/0x300 net/socket.c:1269
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x57a/0x9b0 fs/read_write.c:667
 ksys_write+0xdc/0x1a0 fs/read_write.c:719
 __do_sys_write fs/read_write.c:730 [inline]
 __se_sys_write fs/read_write.c:727 [inline]
 __x64_sys_write+0x40/0x50 fs/read_write.c:727
 x64_sys_call+0x154e/0x2550 arch/x86/include/generated/asm/syscalls_64.h:2
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffff88811bbca090 of 8 bytes by task 414 on cpu 0:
 instrument_write include/linux/instrumented.h:42 [inline]
 ___clear_bit include/asm-generic/bitops/instrumented-non-atomic.h:44 [inline]
 __pwq_activate_work+0x1bd/0x290 kernel/workqueue.c:1823
 node_activate_pending_pwq kernel/workqueue.c:2057 [inline]
 pwq_dec_nr_active kernel/workqueue.c:2126 [inline]
 pwq_dec_nr_in_flight+0x499/0x7f0 kernel/workqueue.c:2166
 process_one_work kernel/workqueue.c:3552 [inline]
 process_scheduled_works+0x750/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 414 Comm: kworker/u8:6 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue:  0x0 (krds_cp_wq#0/0)
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/23 04:50 upstream b6a9fa34ce41 b2c69459 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on
2026/11/19 05:57 upstream 4405c18c95d2 2006bdcc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __pwq_activate_work / queue_delayed_work_on
* Struck through repros no longer work on HEAD.