Skip to content

Commit

Permalink
kernel: rename is_single_threaded(task) to current_is_single_threaded…
Browse files Browse the repository at this point in the history
…(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>
  • Loading branch information
Oleg Nesterov authored and James Morris committed Jul 16, 2009
1 parent d2e3ee9 commit 5bb459b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ static inline unsigned long wait_task_inactive(struct task_struct *p,
#define for_each_process(p) \
for (p = &init_task ; (p = next_task(p)) != &init_task ; )

extern bool is_single_threaded(struct task_struct *);
extern bool current_is_single_threaded(void);

/*
* Careful: do_each_thread/while_each_thread is a double loop so
Expand Down
3 changes: 2 additions & 1 deletion lib/is_single_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
/*
* Returns true if the task does not share ->mm with another thread/process.
*/
bool is_single_threaded(struct task_struct *task)
bool current_is_single_threaded(void)
{
struct task_struct *task = current;
struct mm_struct *mm = task->mm;
struct task_struct *p, *t;
bool ret;
Expand Down
2 changes: 1 addition & 1 deletion security/keys/process_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ long join_session_keyring(const char *name)
/* only permit this if there's a single thread in the thread group -
* this avoids us having to adjust the creds on all threads and risking
* ENOMEM */
if (!is_single_threaded(current))
if (!current_is_single_threaded())
return -EMLINK;

new = prepare_creds();
Expand Down
2 changes: 1 addition & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5187,7 +5187,7 @@ static int selinux_setprocattr(struct task_struct *p,

/* Only allow single threaded processes to change context */
error = -EPERM;
if (!is_single_threaded(p)) {
if (!current_is_single_threaded()) {
error = security_bounded_transition(tsec->sid, sid);
if (error)
goto abort_change;
Expand Down

0 comments on commit 5bb459b

Please sign in to comment.