inconsistent resource limit checking

David Mosberger (davidm@hpl.hp.com)
Thu, 9 Sep 1999 16:28:24 -0700


It has been brought to my attention that the resource limit checks in
the kernel are done inconsistently. This didn't matter in the past,
but since the x86 tree allows (via kernel config option) a user
address space of up to 3GB in size, the inconsistent checking starts
to hurt.

To see the problem, look, for example, at sys_brk in mm/mmap.c. It
has the check:

/* Check against rlimit and stack.. */
rlim = current->rlim[RLIMIT_DATA].rlim_cur;
if (rlim < RLIM_INFINITY && brk - mm->end_code > rlim)
goto out;

This is fine because setting rlim_cur to RLIM_INFINITY will allow to
allocate all available (virtual) memory (up to 3GB).

However, do_mmap() uses a different check:

/* Check against address space limit. */
if ((mm->total_vm << PAGE_SHIFT) + len >
current->rlim[RLIMIT_AS].rlim_cur)
goto free_vma;

this is no good because RLIM_INFINITY=0x7fffffff and hence this check
will prevent you from getting more than 2GB of the address space.

Perhaps it's unfortunate that the resource interface uses signed longs
but I think it would be a mistake to change that now. So instead of
changing the interface, I think it would be better to consistently use
the kind of checking as implemented by sys_brk().

It probably would be a good idea to implement resource limit checking
as a macro/inlined-function so that on systems where the user address
space fits within a signed long (such as 64 bit systems ;-) we can
optimize away the check for RLIM_INFINITY.

--david

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