setrlimit() nit

David Stevens (dlstevens@us.ibm.com)
Wed, 15 Aug 2001 23:53:25 -0700


The setrlimit() system call doesn't enforce rlim_cur <= rlim_max. This can
lead
to some unexpected results. For example, if you call setrlimit() with
RLIMIT_CPU with a hard limit of 60 secs, and a soft limit of "unlimited",
nothing will ever happen-- the hard limit is ignored, because it's never
checked if the soft limit hasn't been exceeded first (see kernel/timer.c).
BSD had the same flaw-- always annoyed me. Simple fix (below). Diffs
are for 2.4.8.

+-DLS

--- linux/kernel/sys.c Thu Jul 26 13:43:33 2001
+++ linux.NEW/kernel/sys.c Thu Aug 16 00:20:14 2001
@@ -1119,6 +1119,8 @@
return -EINVAL;
if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
return -EFAULT;
+ if (new_rlim.rlim_cur > new_rlim.rlim_max)
+ new_rlim.rlim_cur = new_rlim.rlim_max;
old_rlim = current->rlim + resource;
if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
(new_rlim.rlim_max > old_rlim->rlim_max)) &&

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/