linux-stable/kernel/rcu
Zqiang d0a8c0e31a rcu: Protect rcu_print_task_exp_stall() ->exp_tasks access
[ Upstream commit 3c1566bca3 ]

For kernels built with CONFIG_PREEMPT_RCU=y, the following scenario can
result in a NULL-pointer dereference:

           CPU1                                           CPU2
rcu_preempt_deferred_qs_irqrestore                rcu_print_task_exp_stall
  if (special.b.blocked)                            READ_ONCE(rnp->exp_tasks) != NULL
    raw_spin_lock_rcu_node
    np = rcu_next_node_entry(t, rnp)
    if (&t->rcu_node_entry == rnp->exp_tasks)
      WRITE_ONCE(rnp->exp_tasks, np)
      ....
      raw_spin_unlock_irqrestore_rcu_node
                                                    raw_spin_lock_irqsave_rcu_node
                                                    t = list_entry(rnp->exp_tasks->prev,
                                                        struct task_struct, rcu_node_entry)
                                                    (if rnp->exp_tasks is NULL, this
                                                       will dereference a NULL pointer)

The problem is that CPU2 accesses the rcu_node structure's->exp_tasks
field without holding the rcu_node structure's ->lock and CPU2 did
not observe CPU1's change to rcu_node structure's ->exp_tasks in time.
Therefore, if CPU1 sets rcu_node structure's->exp_tasks pointer to NULL,
then CPU2 might dereference that NULL pointer.

This commit therefore holds the rcu_node structure's ->lock while
accessing that structure's->exp_tasks field.

[ paulmck: Apply Frederic Weisbecker feedback. ]

Acked-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-24 17:32:33 +01:00
..
Kconfig Merge branch 'ctxt.2022.07.05a' into HEAD 2022-07-21 17:46:18 -07:00
Kconfig.debug Char / Misc driver changes for 6.0-rc1 2022-08-04 11:05:48 -07:00
Makefile rcuperf: Change rcuperf to rcuscale 2020-08-24 18:39:24 -07:00
rcu.h Merge branch 'ctxt.2022.07.05a' into HEAD 2022-07-21 17:46:18 -07:00
rcu_segcblist.c rcu: Clarify fill-the-gap comment in rcu_segcblist_advance() 2022-04-11 17:28:48 -07:00
rcu_segcblist.h rcu: Mark writes to the rcu_segcblist structure's ->flags field 2022-02-14 10:36:58 -08:00
rcuscale.c rcuscale: Fix smp_processor_id()-in-preemptible warnings 2022-06-21 15:57:04 -07:00
rcutorture.c Merge branches 'doc.2022.08.31b', 'fixes.2022.08.31b', 'kvfree.2022.08.31b', 'nocb.2022.09.01a', 'poll.2022.08.31b', 'poll-srcu.2022.08.31b' and 'tasks.2022.08.31b' into HEAD 2022-09-01 10:55:57 -07:00
refscale.c refscale: Move shutdown from wait_event() to wait_event_idle() 2023-05-24 17:32:33 +01:00
srcutiny.c srcu: Make Tiny SRCU use full-sized grace-period counters 2022-08-31 05:10:15 -07:00
srcutree.c srcu: Delegate work to the boot cpu if using SRCU_SIZE_SMALL 2023-03-10 09:33:48 +01:00
sync.c rcu_sync: Fix comment to properly reflect rcu_sync_exit() behavior 2022-04-20 16:51:11 -07:00
tasks.h rcu-tasks: Handle queue-shrink/callback-enqueue race condition 2023-03-10 09:33:48 +01:00
tiny.c Merge branches 'doc.2022.08.31b', 'fixes.2022.08.31b', 'kvfree.2022.08.31b', 'nocb.2022.09.01a', 'poll.2022.08.31b', 'poll-srcu.2022.08.31b' and 'tasks.2022.08.31b' into HEAD 2022-09-01 10:55:57 -07:00
tree.c rcu: Avoid stack overflow due to __rcu_irq_enter_check_tick() being kprobe-ed 2023-05-11 23:03:02 +09:00
tree.h Merge branch 'ctxt.2022.07.05a' into HEAD 2022-07-21 17:46:18 -07:00
tree_exp.h rcu: Protect rcu_print_task_exp_stall() ->exp_tasks access 2023-05-24 17:32:33 +01:00
tree_nocb.h rcu/nocb: Add CPU number to CPU-{,de}offload failure messages 2022-08-31 05:07:19 -07:00
tree_plugin.h Merge branches 'doc.2022.08.31b', 'fixes.2022.08.31b', 'kvfree.2022.08.31b', 'nocb.2022.09.01a', 'poll.2022.08.31b', 'poll-srcu.2022.08.31b' and 'tasks.2022.08.31b' into HEAD 2022-09-01 10:55:57 -07:00
tree_stall.h sched/debug: Try trigger_single_cpu_backtrace(cpu) in dump_cpu_task() 2022-08-31 05:03:14 -07:00
update.c Merge branch 'ctxt.2022.07.05a' into HEAD 2022-07-21 17:46:18 -07:00