Re: [TRIVIAL] Re: setrlimit incorrectly allows hard limits to exceed soft limits

From: Kingsley Cheung (
Date: Sun Dec 08 2002 - 18:22:56 EST

On Fri, Dec 06, 2002 at 11:07:00AM -0200, Rik van Riel wrote:
> On Fri, 6 Dec 2002, Rusty Trivial Russell wrote:
> > > Just try "ulimit -H -m 10000" for memory limits that were not
> > > previously set. You end up with (hard limit = 10000) < (soft limit =
> > > unlimited).
> > + if (new_rlim.rlim_cur > new_rlim.rlim_max)
> > + return -EINVAL;
> Wouldn't it be better to simply take the soft limit down
> to min(new_rlim.rlim_cur, new_rlim.rlim_max) ?

Another way to do it would be to adjust the max limit up to the soft
limit only if the process had CAP_SYS_RESOURCE, just like in the
function svr4_ulimit in abi/svr4/ulimit.c.

In both cases, however, changing it will mean changing a limit on
behalf of the process. But IMHO wouldn't most applications would
expect rlimits modified with setrlimit successfully to be set to the
rlimits that they specified as the argument? Any child processes they
spawn would expect the same set of modified rlimits to be inherited as
well. If we fix an incorrect pair of rlimits on their behalf, they
would then see different rlimit values with getrlimit later.

In light of that wouldn't it be better just to return an error and
insist that broken applications get fixed? Unless of course there are
just too many broken apps out there : )

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun Dec 15 2002 - 22:00:13 EST