Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kernel: rename is_single_threaded(task) to current_is_single_threaded(void)

- is_single_threaded(task) is not safe unless task == current,
we can't use task->signal or task->mm.

- it doesn't make sense unless task == current, the task can
fork right after the check.

Rename it to current_is_single_threaded() and kill the argument.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

Oleg Nesterov and committed by
James Morris
5bb459bb d2e3ee9b

+5 -4
+1 -1
include/linux/sched.h
··· 2075 2075 #define for_each_process(p) \ 2076 2076 for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 2077 2077 2078 - extern bool is_single_threaded(struct task_struct *); 2078 + extern bool current_is_single_threaded(void); 2079 2079 2080 2080 /* 2081 2081 * Careful: do_each_thread/while_each_thread is a double loop so
+2 -1
lib/is_single_threaded.c
··· 15 15 /* 16 16 * Returns true if the task does not share ->mm with another thread/process. 17 17 */ 18 - bool is_single_threaded(struct task_struct *task) 18 + bool current_is_single_threaded(void) 19 19 { 20 + struct task_struct *task = current; 20 21 struct mm_struct *mm = task->mm; 21 22 struct task_struct *p, *t; 22 23 bool ret;
+1 -1
security/keys/process_keys.c
··· 702 702 /* only permit this if there's a single thread in the thread group - 703 703 * this avoids us having to adjust the creds on all threads and risking 704 704 * ENOMEM */ 705 - if (!is_single_threaded(current)) 705 + if (!current_is_single_threaded()) 706 706 return -EMLINK; 707 707 708 708 new = prepare_creds();
+1 -1
security/selinux/hooks.c
··· 5187 5187 5188 5188 /* Only allow single threaded processes to change context */ 5189 5189 error = -EPERM; 5190 - if (!is_single_threaded(p)) { 5190 + if (!current_is_single_threaded()) { 5191 5191 error = security_bounded_transition(tsec->sid, sid); 5192 5192 if (error) 5193 5193 goto abort_change;