do not limit locked memory when RLIMIT_MEMLOCK is RLIM_INFINITY
Herbert van den Bergh [Mon, 16 Jul 2007 06:38:25 +0000 (23:38 -0700)]
Fix a bug in mm/mlock.c on 32-bit architectures that prevents a user from
locking more than 4GB of shared memory, or allocating more than 4GB of
shared memory in hugepages, when rlim[RLIMIT_MEMLOCK] is set to
RLIM_INFINITY.

Signed-off-by: Herbert van den Bergh <herbert.van.den.bergh@oracle.com>
Acked-by: Chris Mason <chris.mason@oracle.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/mlock.c

index 4d3fea2..7b26560 100644 (file)
@@ -244,9 +244,12 @@ int user_shm_lock(size_t size, struct user_struct *user)
 
        locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
        lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
+       if (lock_limit == RLIM_INFINITY)
+               allowed = 1;
        lock_limit >>= PAGE_SHIFT;
        spin_lock(&shmlock_user_lock);
-       if (locked + user->locked_shm > lock_limit && !capable(CAP_IPC_LOCK))
+       if (!allowed &&
+           locked + user->locked_shm > lock_limit && !capable(CAP_IPC_LOCK))
                goto out;
        get_uid(user);
        user->locked_shm += locked;