Skip to contentSkip to conversation

sched/fair: Use RCU accessors consistently for ->numa_group

tip:sched/core tip-bot for Jann Horn 1 participant 1 message Jul 25, 2019 1 message not in the archive Scheduler

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

tip-bot for Jann Horn

author merge bot
#1 lore raw
Commit-ID:  cb361d8cdef69990f6b4504dc1fd9a594d983c97
Gitweb:     https://git.kernel.org/tip/cb361d8cdef69990f6b4504dc1fd9a594d983c97
Author:     Jann Horn <[email protected]>
AuthorDate: Tue, 16 Jul 2019 17:20:47 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 25 Jul 2019 15:37:05 +0200

sched/fair: Use RCU accessors consistently for ->numa_group

The old code used RCU annotations and accessors inconsistently for ->numa_group, which can lead to use-after-frees and NULL dereferences.

Let all accesses to ->numa_group use proper RCU helpers to prevent such issues.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Deacon <[email protected]>
Fixes 8c8a743c5087 ("sched/numa: Use {cpu, pid} to create task groups for shared faults")
---
 include/linux/sched.h |  10 ++++-
 kernel/sched/fair.c   | 120 ++++++++++++++++++++++++++++++++++----------------
 2 files changed, 90 insertions(+), 40 deletions(-)
include/linux/sched.h +9 -1
index 8dc1811487f5..9f51932bd543 100644
@@ -1092,7 +1092,15 @@ struct task_struct {
 	u64				last_sum_exec_runtime;
 	struct callback_head		numa_work;
 
-	struct numa_group		*numa_group;
+	/*
+	 * This pointer is only modified for current in syscall and
+	 * pagefault context (and for tasks being destroyed), so it can be read
+	 * from any of the following contexts:
+	 *  - RCU read-side critical section
+	 *  - current->numa_group from everywhere
+	 *  - task's runqueue locked, task not running
+	 */
+	struct numa_group __rcu		*numa_group;
 
 	/*
 	 * numa_faults is an array split into four regions:
kernel/sched/fair.c +81 -39

308 lines not on this page · raw message