diff options
author | Bruce Evans <bde@FreeBSD.org> | 1994-12-06 22:53:37 +0000 |
---|---|---|
committer | Bruce Evans <bde@FreeBSD.org> | 1994-12-06 22:53:37 +0000 |
commit | a81b757af0da2d70b04d064810b0f7f3591d4fd7 (patch) | |
tree | 7b38f8d9c0850d444a93f07c61206b5f62e45641 /sys/kern/kern_resource.c | |
parent | a2a65bbb149464ed66141f6afa4736b552e9875f (diff) | |
download | src-a81b757af0da2d70b04d064810b0f7f3591d4fd7.tar.gz src-a81b757af0da2d70b04d064810b0f7f3591d4fd7.zip |
Don't allow negative limits at all. Convert them to RLIM_INFINITY instead
of returning EINVAL since something may depend on them being broken.
Allowing negative limits caused bugs almost everywhere. The recent
fixes for MAXSSIZ checked the limits too late to stop anyone defeating
limits set by root...
Notes
Notes:
svn path=/head/; revision=5009
Diffstat (limited to 'sys/kern/kern_resource.c')
-rw-r--r-- | sys/kern/kern_resource.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 846076b592f1..414bc1a8c45c 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_resource.c,v 1.8 1994/12/01 20:20:21 ats Exp $ + * $Id: kern_resource.c,v 1.9 1994/12/02 23:00:40 ats Exp $ */ #include <sys/param.h> @@ -346,6 +346,15 @@ dosetrlimit(p, which, limp) if (which >= RLIM_NLIMITS) return (EINVAL); alimp = &p->p_rlimit[which]; + + /* + * Preserve historical bugs by treating negative limits as unsigned. + */ + if (limp->rlim_cur < 0) + limp->rlim_cur = RLIM_INFINITY; + if (limp->rlim_max < 0) + limp->rlim_max = RLIM_INFINITY; + if (limp->rlim_cur > alimp->rlim_max || limp->rlim_max > alimp->rlim_max) if ((error = suser(p->p_ucred, &p->p_acflag))) @@ -362,16 +371,16 @@ dosetrlimit(p, which, limp) switch (which) { case RLIMIT_DATA: - if ((u_quad_t) limp->rlim_cur > MAXDSIZ) + if (limp->rlim_cur > MAXDSIZ) limp->rlim_cur = MAXDSIZ; - if ((u_quad_t) limp->rlim_max > MAXDSIZ) + if (limp->rlim_max > MAXDSIZ) limp->rlim_max = MAXDSIZ; break; case RLIMIT_STACK: - if ((u_quad_t) limp->rlim_cur > MAXSSIZ) + if (limp->rlim_cur > MAXSSIZ) limp->rlim_cur = MAXSSIZ; - if ((u_quad_t) limp->rlim_max > MAXSSIZ) + if (limp->rlim_max > MAXSSIZ) limp->rlim_max = MAXSSIZ; /* * Stack is allocated to the max at exec time with only @@ -383,7 +392,7 @@ dosetrlimit(p, which, limp) vm_size_t size; vm_prot_t prot; - if ((u_quad_t) limp->rlim_cur > (u_quad_t) alimp->rlim_cur) { + if (limp->rlim_cur > alimp->rlim_cur) { prot = VM_PROT_ALL; size = limp->rlim_cur - alimp->rlim_cur; addr = USRSTACK - limp->rlim_cur; |