mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guillem Jover <guillem.jover@nokia.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Allowing user processes to rise their oom_adj value
Date: Fri, 3 Nov 2006 21:46:11 +0200	[thread overview]
Message-ID: <20061103194611.GA22891@ziggurat.research.nokia.com> (raw)

Currently a user process cannot rise its own oom_adj value (i.e.
unprotecting itself from the OOM killer). As this value is stored
in the task structure it gets inherited and the unprivileged childs
will be unable to rise it.

The EPERM will be handled by the generic proc fs layer, as only
processes with the proper caps or the owner of the process will be
able to write to the file. So we allow only the processes with
CAP_SYS_RESOURCE to lower the value, otherwise it will get an EACCES
which seems more appropriate than EPERM.

Signed-off-by: Guillem Jover <guillem.jover@nokia.com>
---
 fs/proc/base.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8df2740..955bb0a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -682,8 +682,6 @@ static ssize_t oom_adjust_write(struct f
 	char buffer[PROC_NUMBUF], *end;
 	int oom_adjust;
 
-	if (!capable(CAP_SYS_RESOURCE))
-		return -EPERM;
 	memset(buffer, 0, sizeof(buffer));
 	if (count > sizeof(buffer) - 1)
 		count = sizeof(buffer) - 1;
@@ -698,6 +696,10 @@ static ssize_t oom_adjust_write(struct f
 	task = get_proc_task(file->f_dentry->d_inode);
 	if (!task)
 		return -ESRCH;
+	if (oom_adjust < task->oomkilladj && !capable(CAP_SYS_RESOURCE)) {
+		put_task_struct(task);
+		return -EACCES;
+	}
 	task->oomkilladj = oom_adjust;
 	put_task_struct(task);
 	if (end - buffer == 0)
-- 
1.4.3.3


                 reply	other threads:[~2006-11-03 19:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061103194611.GA22891@ziggurat.research.nokia.com \
    --to=guillem.jover@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®