From ffede8d5259c20eb423f3035e483e7efd8e598cd Mon Sep 17 00:00:00 2001 From: Mandeep Singh Baines Date: Thu, 13 Jan 2011 15:46:05 -0800 Subject: [PATCH] --- yaml --- r: 230720 b: refs/heads/master c: dabb16f639820267b3850d804571c70bd93d4e07 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/Documentation/filesystems/proc.txt | 4 ++++ trunk/fs/proc/base.c | 4 +++- trunk/include/linux/sched.h | 2 ++ trunk/kernel/fork.c | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 688c192d23d9..7810c78009b5 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: d0a21265dfb5fa8ae54e90d0fb6d1c215b10a28a +refs/heads/master: dabb16f639820267b3850d804571c70bd93d4e07 diff --git a/trunk/Documentation/filesystems/proc.txt b/trunk/Documentation/filesystems/proc.txt index ef757fca470b..23cae6548d3a 100644 --- a/trunk/Documentation/filesystems/proc.txt +++ b/trunk/Documentation/filesystems/proc.txt @@ -1323,6 +1323,10 @@ scaled linearly with /proc//oom_score_adj. Writing to /proc//oom_score_adj or /proc//oom_adj will change the other with its scaled value. +The value of /proc//oom_score_adj may be reduced no lower than the last +value set by a CAP_SYS_RESOURCE process. To reduce the value any lower +requires CAP_SYS_RESOURCE. + NOTICE: /proc//oom_adj is deprecated and will be removed, please see Documentation/feature-removal-schedule.txt. diff --git a/trunk/fs/proc/base.c b/trunk/fs/proc/base.c index 93f1cdd5d3d7..9d096e82b201 100644 --- a/trunk/fs/proc/base.c +++ b/trunk/fs/proc/base.c @@ -1151,7 +1151,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, goto err_task_lock; } - if (oom_score_adj < task->signal->oom_score_adj && + if (oom_score_adj < task->signal->oom_score_adj_min && !capable(CAP_SYS_RESOURCE)) { err = -EACCES; goto err_sighand; @@ -1164,6 +1164,8 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, atomic_dec(&task->mm->oom_disable_count); } task->signal->oom_score_adj = oom_score_adj; + if (has_capability_noaudit(current, CAP_SYS_RESOURCE)) + task->signal->oom_score_adj_min = oom_score_adj; /* * Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is * always attainable. diff --git a/trunk/include/linux/sched.h b/trunk/include/linux/sched.h index 07402530fc70..f23b5bb6f52e 100644 --- a/trunk/include/linux/sched.h +++ b/trunk/include/linux/sched.h @@ -634,6 +634,8 @@ struct signal_struct { int oom_adj; /* OOM kill score adjustment (bit shift) */ int oom_score_adj; /* OOM kill score adjustment */ + int oom_score_adj_min; /* OOM kill score adjustment minimum value. + * Only settable by CAP_SYS_RESOURCE. */ struct mutex cred_guard_mutex; /* guard against foreign influences on * credential calculations diff --git a/trunk/kernel/fork.c b/trunk/kernel/fork.c index 76a1fdd80bdf..1499607e4da2 100644 --- a/trunk/kernel/fork.c +++ b/trunk/kernel/fork.c @@ -910,6 +910,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) sig->oom_adj = current->signal->oom_adj; sig->oom_score_adj = current->signal->oom_score_adj; + sig->oom_score_adj_min = current->signal->oom_score_adj_min; mutex_init(&sig->cred_guard_mutex);