mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adam Tkac <vonsch@gmail.com>
To: Andreas Schwab <schwab@suse.de>
Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, mtk.manpages@gmail.com
Subject: Re: [PATCH 2.6.27-rc5] Allow set RLIMIT_NOFILE to RLIM_INFINITY
Date: Fri, 12 Sep 2008 13:52:26 +0200	[thread overview]
Message-ID: <20080912115226.GA4024@evileye.atkac.englab.brq.redhat.com> (raw)
In-Reply-To: <jesks5wqy9.fsf@sykes.suse.de>

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

On Fri, Sep 12, 2008 at 01:20:46PM +0200, Andreas Schwab wrote:
> Adam Tkac <vonsch@gmail.com> writes:
> 
> > diff -puN kernel/sys.c~rlimit-permit-setting-rlimit_nofile-to-rlim_infinity kernel/sys.c
> > --- a/kernel/sys.c~rlimit-permit-setting-rlimit_nofile-to-rlim_infinity
> > +++ a/kernel/sys.c
> > @@ -1532,8 +1532,14 @@ asmlinkage long sys_setrlimit(unsigned i
> >  	if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
> >  	    !capable(CAP_SYS_RESOURCE))
> >  		return -EPERM;
> > -	if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
> > -		return -EPERM;
> > +	if (resource == RLIMIT_NOFILE) {
> > +		if (new_rlim.rlim_max == RLIM_INFINITY)
> > +			new_rlim.rlim_max = sysctl_nr_open;
> > +		if (new_rlim.rlim_cur == RLIM_INFINITY)
> > +			new_rlim.rlim_cur = sysctl_nr_open;
> > +		if (new_rlim.rlim_max > sysctl_nr_open)
> > +			return -EPERM;
> 
> This makes it possible to set cur > nr_open (when max = INF but nr_open
> < cur < INF).  You need to check that cur <= max after adjustment.
> 
> Andreas.
> 

Right you are. Improved patch is attached, when cur > max && cur !=
INF after adjustment EINVAL is returned. (cur can be also set to max
but it seems like bad solution for me)

-- 
Adam Tkac


[-- Attachment #2: linux26-openfiles.patch --]
[-- Type: text/plain, Size: 1967 bytes --]

When a process wants to set the limit of open files to RLIM_INFINITY it
gets EPERM even if it has CAP_SYS_RESOURCE capability.

For example, BIND does:

...
#elif defined(NR_OPEN) && defined(__linux__)
        /*
         * Some Linux kernels don't accept RLIM_INFINIT; the maximum
         * possible value is the NR_OPEN defined in linux/fs.h.
         */
        if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
                rl.rlim_cur = rl.rlim_max = NR_OPEN;
                unixresult = setrlimit(unixresource, &rl);
                if (unixresult == 0)
                        return (ISC_R_SUCCESS);
        }
#elif ...

If we allow setting RLIMIT_NOFILE to RLIM_INFINITY we increase portability
- you don't have to check if OS is linux and then use different schema for
limits.

The spec says "Specifying RLIM_INFINITY as any resource limit value on a
successful call to setrlimit() shall inhibit enforcement of that resource
limit." and we're presently not doing that.

Signed-off-by: Adam Tkac <vonsch@gmail.com>
--- a/kernel/sys.c.openfiles
+++ a/kernel/sys.c
@@ -1469,14 +1469,22 @@ asmlinkage long sys_setrlimit(unsigned i
 		return -EINVAL;
 	if (copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
 		return -EFAULT;
-	if (new_rlim.rlim_cur > new_rlim.rlim_max)
-		return -EINVAL;
 	old_rlim = current->signal->rlim + resource;
 	if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
 	    !capable(CAP_SYS_RESOURCE))
 		return -EPERM;
-	if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
-		return -EPERM;
+
+	if (resource == RLIMIT_NOFILE) {
+		if (new_rlim.rlim_max == RLIM_INFINITY)
+			new_rlim.rlim_max = sysctl_nr_open;
+		if (new_rlim.rlim_cur == RLIM_INFINITY)
+			new_rlim.rlim_cur = sysctl_nr_open;
+		if (new_rlim.rlim_max > sysctl_nr_open)
+			return -EPERM;
+	}
+
+	if (new_rlim.rlim_cur > new_rlim.rlim_max)
+		return -EINVAL;
 
 	retval = security_task_setrlimit(resource, &new_rlim);
 	if (retval)

      reply	other threads:[~2008-09-12 11:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09  7:14 Adam Tkac
2008-09-10 21:31 ` Andrew Morton
2008-09-11  7:54   ` Adam Tkac
2008-09-11 19:22     ` Andrew Morton
2008-09-12 11:06       ` Adam Tkac
2008-09-12 11:20         ` Andreas Schwab
2008-09-12 11:52           ` Adam Tkac [this message]

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=20080912115226.GA4024@evileye.atkac.englab.brq.redhat.com \
    --to=vonsch@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=schwab@suse.de \
    --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®