mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: akpm@linux-foundation.org
Cc: torvalds@linux-foundation.org, adobriyan@gmail.com,
	nhorman@tuxdriver.com, oleg@redhat.com,
	linux-kernel@vger.kernel.org, jirislaby@gmail.com
Subject: [PATCH v2 09/11] rlimits: switch more rlimit syscalls to do_prlimit
Date: Fri,  7 May 2010 11:02:57 +0200	[thread overview]
Message-ID: <1273222977-17419-1-git-send-email-jslaby@suse.cz> (raw)
In-Reply-To: <1273222543-17083-9-git-send-email-jslaby@suse.cz>

From: Jiri Slaby <jirislaby@gmail.com>

This is the correct one, I forgot to re-run format-patch.
--

After we added more generic do_prlimit, switch sys_getrlimit to that.
Also switch compat handling, so we can get rid of ugly __user casts
and avoid setting process' address limit to kernel data and back.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 kernel/compat.c |   16 +++-------------
 kernel/sys.c    |   17 ++++++++---------
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/kernel/compat.c b/kernel/compat.c
index 7f40e92..199b345 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -280,10 +280,6 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,
 {
 	struct rlimit r;
 	int ret;
-	mm_segment_t old_fs = get_fs ();
-
-	if (resource >= RLIM_NLIMITS)
-		return -EINVAL;
 
 	if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) ||
 	    __get_user(r.rlim_cur, &rlim->rlim_cur) ||
@@ -294,10 +290,7 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,
 		r.rlim_cur = RLIM_INFINITY;
 	if (r.rlim_max == COMPAT_RLIM_INFINITY)
 		r.rlim_max = RLIM_INFINITY;
-	set_fs(KERNEL_DS);
-	ret = sys_setrlimit(resource, (struct rlimit __user *) &r);
-	set_fs(old_fs);
-	return ret;
+	return do_prlimit(current, resource, &r, NULL);
 }
 
 #ifdef COMPAT_RLIM_OLD_INFINITY
@@ -329,16 +322,13 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
 
 #endif
 
-asmlinkage long compat_sys_getrlimit (unsigned int resource,
+asmlinkage long compat_sys_getrlimit(unsigned int resource,
 		struct compat_rlimit __user *rlim)
 {
 	struct rlimit r;
 	int ret;
-	mm_segment_t old_fs = get_fs();
 
-	set_fs(KERNEL_DS);
-	ret = sys_getrlimit(resource, (struct rlimit __user *) &r);
-	set_fs(old_fs);
+	ret = do_prlimit(current, resource, NULL, &r);
 	if (!ret) {
 		if (r.rlim_cur > COMPAT_RLIM_INFINITY)
 			r.rlim_cur = COMPAT_RLIM_INFINITY;
diff --git a/kernel/sys.c b/kernel/sys.c
index 7a453d2..0f8034f 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1236,15 +1236,14 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
 
 SYSCALL_DEFINE2(getrlimit, unsigned int, resource, struct rlimit __user *, rlim)
 {
-	if (resource >= RLIM_NLIMITS)
-		return -EINVAL;
-	else {
-		struct rlimit value;
-		task_lock(current->group_leader);
-		value = current->signal->rlim[resource];
-		task_unlock(current->group_leader);
-		return copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
-	}
+	struct rlimit value;
+	int ret;
+
+	ret = do_prlimit(current, resource, NULL, &value);
+	if (!ret)
+		ret = copy_to_user(rlim, &value, sizeof(*rlim)) ? -EFAULT : 0;
+
+	return ret;
 }
 
 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
-- 
1.7.1



  reply	other threads:[~2010-05-07  9:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-07 16:52 [PULL] pull request for writable limits for 2.6.33-rc1 Jiri Slaby
2009-12-09 19:25 ` [PULL] pull request for writable limits for 2.6.33-rc0 Jiri Slaby
2009-12-11 11:05   ` [git pull -resend] " Jiri Slaby
2009-12-23  9:40     ` Jiri Slaby
2010-01-02 21:40   ` [PULL] " Jiri Kosina
2010-01-02 21:52     ` Ingo Molnar
2010-01-04 21:59       ` Jiri Kosina
2010-01-04 10:47   ` [PULL] pull request for limits FIXES for 2.6.33-rc Jiri Slaby
2010-01-04 10:48     ` [PATCH 1/3] SECURITY: selinux, fix update_rlimit_cpu parameter Jiri Slaby
2010-01-04 10:48     ` [PATCH 2/3] resource: move kernel function inside __KERNEL__ Jiri Slaby
2010-01-04 10:48     ` [PATCH 3/3] resource: add helpers for fetching rlimits Jiri Slaby
2010-01-05 15:50     ` [PATCH 1/3] SECURITY: selinux, fix update_rlimit_cpu parameter David Howells
2010-03-05 16:53 ` [git pull] pull request for writable limits for 2.6.34-rc0 Jiri Slaby
2010-03-20 19:20   ` Linus Torvalds
2010-03-21  1:45     ` Neil Horman
2010-03-21  6:06     ` Alexey Dobriyan
2010-03-21 18:38       ` Linus Torvalds
2010-03-24 17:02         ` Jiri Slaby
2010-04-14  9:31           ` Jiri Slaby
2010-05-05 12:12         ` Resource limits interface proposal [was: pull request for writable limits] Jiri Slaby
2010-05-05 15:08           ` Linus Torvalds
2010-05-06  6:39             ` Alexey Dobriyan
2010-05-06 15:37               ` Linus Torvalds
2010-05-07  8:55                 ` [PATCH 01/11] rlimits: security, add task_struct to setrlimit Jiri Slaby
2010-05-07  8:55                 ` [PATCH 02/11] rlimits: add task_struct to update_rlimit_cpu Jiri Slaby
2010-05-07  8:55                 ` [PATCH 03/11] rlimits: make sure ->rlim_max never grows in sys_setrlimit Jiri Slaby
2010-05-07  8:55                 ` [PATCH 04/11] rlimits: split sys_setrlimit Jiri Slaby
2010-05-07  8:55                 ` [PATCH 05/11] rlimits: allow setrlimit to non-current tasks Jiri Slaby
2010-05-07  8:55                 ` [PATCH 06/11] rlimits: do security check under task_lock Jiri Slaby
2010-05-07  8:55                 ` [PATCH 07/11] rlimits: add rlimit64 structure Jiri Slaby
2010-05-07  8:55                 ` [PATCH 08/11] rlimits: redo do_setrlimit to more generic do_prlimit Jiri Slaby
2010-05-07  8:55                 ` [PATCH 09/11] rlimits: switch getrlimit to do_prlimit Jiri Slaby
2010-05-07  9:02                   ` Jiri Slaby [this message]
2010-05-07  9:05                     ` [PATCH v2 09/11] rlimits: switch more rlimit syscalls " Jiri Slaby
2010-05-07  8:55                 ` [PATCH " Jiri Slaby
2010-05-07  8:55                 ` [PATCH 10/11] rlimits: implement prlimit64 syscall Jiri Slaby
2010-05-07  8:55                 ` [PATCH 11/11] unistd: add __NR_prlimit64 syscall numbers Jiri Slaby
2010-05-06 15:46             ` Resource limits interface proposal [was: pull request for writable limits] Jiri Slaby
2010-03-24 17:04     ` [git pull] pull request for writable limits for 2.6.34-rc0 Jiri Slaby

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=1273222977-17419-1-git-send-email-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=oleg@redhat.com \
    --cc=torvalds@linux-foundation.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®