Subject: Re: setrlimit(RLIMIT_STACK,..) check for limit < stack usage
To: Giles Lean <email@example.com>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
Date: 11/18/2001 10:21:52
Giles Lean wrote:
> > /*
> > + * Return EINVAL if the new limit is lower than current
> > + * usage. Otherwise, the process would get SIGSEGV the moment
> > + * it would try to access anything on it's current stack.
> > + * This is not what the caller intended, unless on crack
> > + * or mistaken.
> > + */
> > + if (limp->rlim_cur < p->p_vmspace->vm_dsize * PAGE_SIZE
> > + || limp->rlim_max < p->p_vmspace->vm_dsize * PAGE_SIZE)
> > + return (EINVAL);
> > +
> I'd change the last sentence of the comment to reference the
> standard. :-) The actual code change looks good but I'm not familiar
> with the VM code to be certain.
Right, I will :) Also, the patch should have used vm_ssize, not vm_dsize.
> While you're tweaking the function I'd suggest another change as SUSv2
> also requires EINVAL when rlim_cur exceeds rlim_max:
> [EINVAL] ... in a setrlimit() call, the new rlim_cur exceeds the new
> If this is thought desirable (and worthwhile :-), then the following code:
Yes, I agree with this. Will add that too.
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.NetBSD.org/Ports/i386/ps2.html
-= Those who would give up liberty for a little temporary safety deserve =-
-= neither liberty nor safety, and will lose both. -- Benjamin Franklin =-