Subject: Re: kern_fork.c - off by two error ???
To: Wolfgang Solfrank <ws@tools.de>
From: Chris Hopps <chopps@emunix.emich.edu>
List: current-users
Date: 02/21/1994 17:31:02
> > >From kern/kern_fork.c:
> >
> > /*
> > * Although process entries are dynamically entries,
> > * we still keep a global limit on the maximum number
> > * we will create. Don't allow a nonprivileged user
> > * to exceed its current limit or to bring us within one
> > * of the global limit; don't let root exceed the limit.
> > * nprocs is the current number of processes,
> > * maxproc is the limit.
> > */
> > if ((nprocs >= maxproc && uid != 0)
> > || nprocs >= maxproc + 1) {
> > ^--------- shouldn't this be "-" ???
> If you substitute a "-" the part before the "||" would be superfluous
> alltogether.
>
> What the code does, is allow atmost maxproc processes for any user with
> uid != 0, but allow one more process for the superuser.
Which is not what the comment indicates. I belive the correct code
should be:
if ((nprocs >= maxproc - 2 && uid !=0)
|| nprocs >= maxproc) {
which as the comment states allows the user to bring the number of
procs to within 2 of the limit and root to the limit. Think of it
like this:
if (( (nprocs+1) > (maxproc-2) && uid != 0)
|| (nprocs+1) > (maxproc)) fail;
which re-written is:
if ((nprocs >= maxprocs -2 && uid != 0)
|| nprocs >= maxproc) fail;
The language in the comment is misleading and I belive the source is incorrect.
> Hope this helps,
Chris.
------------------------------------------------------------------------------