Centos-kernel-stream-9/kernel/rcu
Rafael Aquini 89edcfe6e5 rcu/kvfree: Fix data-race in __mod_timer / kvfree_call_rcu
JIRA: https://issues.redhat.com/browse/RHEL-72196
CVE: CVE-2024-53160

This patch is a backport of the following upstream commit:
commit a23da88c6c80e41e0503e0b481a22c9eea63f263
Author: Uladzislau Rezki (Sony) <urezki@gmail.com>
Date:   Tue Oct 22 12:53:07 2024 +0200

    rcu/kvfree: Fix data-race in __mod_timer / kvfree_call_rcu

    KCSAN reports a data race when access the krcp->monitor_work.timer.expires
    variable in the schedule_delayed_monitor_work() function:

    <snip>
    BUG: KCSAN: data-race in __mod_timer / kvfree_call_rcu

    read to 0xffff888237d1cce8 of 8 bytes by task 10149 on cpu 1:
     schedule_delayed_monitor_work kernel/rcu/tree.c:3520 [inline]
     kvfree_call_rcu+0x3b8/0x510 kernel/rcu/tree.c:3839
     trie_update_elem+0x47c/0x620 kernel/bpf/lpm_trie.c:441
     bpf_map_update_value+0x324/0x350 kernel/bpf/syscall.c:203
     generic_map_update_batch+0x401/0x520 kernel/bpf/syscall.c:1849
     bpf_map_do_batch+0x28c/0x3f0 kernel/bpf/syscall.c:5143
     __sys_bpf+0x2e5/0x7a0
     __do_sys_bpf kernel/bpf/syscall.c:5741 [inline]
     __se_sys_bpf kernel/bpf/syscall.c:5739 [inline]
     __x64_sys_bpf+0x43/0x50 kernel/bpf/syscall.c:5739
     x64_sys_call+0x2625/0x2d60 arch/x86/include/generated/asm/syscalls_64.h:322
     do_syscall_x64 arch/x86/entry/common.c:52 [inline]
     do_syscall_64+0xc9/0x1c0 arch/x86/entry/common.c:83
     entry_SYSCALL_64_after_hwframe+0x77/0x7f

    write to 0xffff888237d1cce8 of 8 bytes by task 56 on cpu 0:
     __mod_timer+0x578/0x7f0 kernel/time/timer.c:1173
     add_timer_global+0x51/0x70 kernel/time/timer.c:1330
     __queue_delayed_work+0x127/0x1a0 kernel/workqueue.c:2523
     queue_delayed_work_on+0xdf/0x190 kernel/workqueue.c:2552
     queue_delayed_work include/linux/workqueue.h:677 [inline]
     schedule_delayed_monitor_work kernel/rcu/tree.c:3525 [inline]
     kfree_rcu_monitor+0x5e8/0x660 kernel/rcu/tree.c:3643
     process_one_work kernel/workqueue.c:3229 [inline]
     process_scheduled_works+0x483/0x9a0 kernel/workqueue.c:3310
     worker_thread+0x51d/0x6f0 kernel/workqueue.c:3391
     kthread+0x1d1/0x210 kernel/kthread.c:389
     ret_from_fork+0x4b/0x60 arch/x86/kernel/process.c:147
     ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

    Reported by Kernel Concurrency Sanitizer on:
    CPU: 0 UID: 0 PID: 56 Comm: kworker/u8:4 Not tainted 6.12.0-rc2-syzkaller-00050-g5b7c893ed5ed #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
    Workqueue: events_unbound kfree_rcu_monitor
    <snip>

    kfree_rcu_monitor() rearms the work if a "krcp" has to be still
    offloaded and this is done without holding krcp->lock, whereas
    the kvfree_call_rcu() holds it.

    Fix it by acquiring the "krcp->lock" for kfree_rcu_monitor() so
    both functions do not race anymore.

    Reported-by: syzbot+061d370693bdd99f9d34@syzkaller.appspotmail.com
    Link: https://lore.kernel.org/lkml/ZxZ68KmHDQYU0yfD@pc636/T/
    Fixes: 8fc5494ad5fa ("rcu/kvfree: Move need_offload_krc() out of krcp->lock")
    Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
    Reviewed-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2025-01-08 17:48:13 -05:00
..
Kconfig rcu: Create NEED_TASKS_RCU to factor out enablement logic 2024-08-26 10:57:28 -04:00
Kconfig.debug rcu: Restrict access to RCU CPU stall notifiers 2024-05-31 10:56:18 -04:00
Makefile
rcu.h rcutorture: Make rcutorture support print rcu-tasks gp state 2024-08-26 10:57:47 -04:00
rcu_segcblist.c rcu: Use rcu_segcblist_segempty() instead of open coding it 2024-05-31 10:56:17 -04:00
rcu_segcblist.h
rcuscale.c rcu: Rename jiffies_till_flush to jiffies_lazy_flush 2024-08-26 10:57:21 -04:00
rcutorture.c rcutorture: Use rcu_gp_slow_register/unregister() only for rcutype test 2024-08-26 10:57:49 -04:00
refscale.c refscale: Print out additional module parameters 2024-05-31 10:56:17 -04:00
srcutiny.c srcu: Make Tiny SRCU explicitly disable preemption 2024-08-26 10:57:27 -04:00
srcutree.c rcutorture: Make rcutorture support print rcu-tasks gp state 2024-08-26 10:57:47 -04:00
sync.c rcu: Mark writes to rcu_sync ->gp_count field 2024-08-26 10:57:31 -04:00
tasks.h rcu/tasks: Fix stale task snaphot for Tasks Trace 2024-08-26 10:57:51 -04:00
tiny.c rcu: Make Tiny RCU explicitly disable preemption 2024-08-26 10:57:29 -04:00
tree.c rcu/kvfree: Fix data-race in __mod_timer / kvfree_call_rcu 2025-01-08 17:48:13 -05:00
tree.h rcu: Support direct wake-up of synchronize_rcu() users 2024-08-26 10:57:38 -04:00
tree_exp.h rcu: Reduce synchronize_rcu() latency 2024-08-26 10:57:37 -04:00
tree_nocb.h rcu: Rename jiffies_till_flush to jiffies_lazy_flush 2024-08-26 10:57:21 -04:00
tree_plugin.h Merge: Fix RCUC latency issue 2024-10-25 16:26:53 +00:00
tree_stall.h rcu: Fix buffer overflow in print_cpu_stall_info() 2024-08-26 10:57:35 -04:00
update.c rcu: Restrict access to RCU CPU stall notifiers 2024-05-31 10:56:18 -04:00