[PATCH] proc, oom: drop bogus sighand lock

From: Michal Hocko
Date: Tue May 31 2016 - 03:28:36 EST


Oleg has pointed out that can simplify both oom_adj_write and
oom_score_adj_write even further and drop the sighand lock. The only
purpose of the lock was to protect p->signal from going away but this
will not happen since ea6d290ca34c ("signals: make task_struct->signal
immutable/refcountable").

Suggested-by: Oleg Nesterov <oleg@xxxxxxxxxx>
Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
fs/proc/base.c | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index a6014e45c516..3761f107615a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1057,7 +1057,6 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,
struct task_struct *task;
char buffer[PROC_NUMBUF];
int oom_adj;
- unsigned long flags;
int err;

memset(buffer, 0, sizeof(buffer));
@@ -1083,11 +1082,6 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,
goto out;
}

- if (!lock_task_sighand(task, &flags)) {
- err = -ESRCH;
- goto err_put_task;
- }
-
/*
* Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum
* value is always attainable.
@@ -1100,7 +1094,7 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,
if (oom_adj < task->signal->oom_score_adj &&
!capable(CAP_SYS_RESOURCE)) {
err = -EACCES;
- goto err_sighand;
+ goto err_put_task;
}

/*
@@ -1113,8 +1107,6 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,

task->signal->oom_score_adj = oom_adj;
trace_oom_score_adj_update(task);
-err_sighand:
- unlock_task_sighand(task, &flags);
err_put_task:
put_task_struct(task);
out:
@@ -1152,7 +1144,6 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
{
struct task_struct *task;
char buffer[PROC_NUMBUF];
- unsigned long flags;
int oom_score_adj;
int err;

@@ -1179,15 +1170,10 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
goto out;
}

- if (!lock_task_sighand(task, &flags)) {
- err = -ESRCH;
- goto err_put_task;
- }
-
if ((short)oom_score_adj < task->signal->oom_score_adj_min &&
!capable(CAP_SYS_RESOURCE)) {
err = -EACCES;
- goto err_sighand;
+ goto err_put_task;
}

task->signal->oom_score_adj = (short)oom_score_adj;
@@ -1195,8 +1181,6 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
task->signal->oom_score_adj_min = (short)oom_score_adj;
trace_oom_score_adj_update(task);

-err_sighand:
- unlock_task_sighand(task, &flags);
err_put_task:
put_task_struct(task);
out:
--
2.8.1

--
Michal Hocko
SUSE Labs