Skip to content

Commit 5bb459b

Browse files
oleg-nesterovJames Morris
authored and
James Morris
committed
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 <[email protected]> Acked-by: David Howells <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent d2e3ee9 commit 5bb459b

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

include/linux/sched.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ static inline unsigned long wait_task_inactive(struct task_struct *p,
20752075
#define for_each_process(p) \
20762076
for (p = &init_task ; (p = next_task(p)) != &init_task ; )
20772077

2078-
extern bool is_single_threaded(struct task_struct *);
2078+
extern bool current_is_single_threaded(void);
20792079

20802080
/*
20812081
* Careful: do_each_thread/while_each_thread is a double loop so

lib/is_single_threaded.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
/*
1616
* Returns true if the task does not share ->mm with another thread/process.
1717
*/
18-
bool is_single_threaded(struct task_struct *task)
18+
bool current_is_single_threaded(void)
1919
{
20+
struct task_struct *task = current;
2021
struct mm_struct *mm = task->mm;
2122
struct task_struct *p, *t;
2223
bool ret;

security/keys/process_keys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ long join_session_keyring(const char *name)
702702
/* only permit this if there's a single thread in the thread group -
703703
* this avoids us having to adjust the creds on all threads and risking
704704
* ENOMEM */
705-
if (!is_single_threaded(current))
705+
if (!current_is_single_threaded())
706706
return -EMLINK;
707707

708708
new = prepare_creds();

security/selinux/hooks.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5187,7 +5187,7 @@ static int selinux_setprocattr(struct task_struct *p,
51875187

51885188
/* Only allow single threaded processes to change context */
51895189
error = -EPERM;
5190-
if (!is_single_threaded(p)) {
5190+
if (!current_is_single_threaded()) {
51915191
error = security_bounded_transition(tsec->sid, sid);
51925192
if (error)
51935193
goto abort_change;

0 commit comments

Comments
 (0)