]> git.karo-electronics.de Git - karo-tx-linux.git/commit
Fix user struct leakage with locked IPC shem segment
authorPavel Emelianov <xemul@openvz.org>
Tue, 31 Jul 2007 07:38:48 +0000 (00:38 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 9 Aug 2007 21:27:36 +0000 (14:27 -0700)
commit68a0460bbcc7571753b57b83f21e8c1c5029a46a
tree89b04b034309ce8ea3c640466a8cdc1406a226e1
parentdf358e1bad63f47ef3d399f8193bdc5a59d3d747
Fix user struct leakage with locked IPC shem segment

When user locks an ipc shmem segmant with SHM_LOCK ctl and the segment is
already locked the shmem_lock() function returns 0.  After this the
subsequent code leaks the existing user struct:

== ipc/shm.c: sys_shmctl() ==
     ...
     err = shmem_lock(shp->shm_file, 1, user);
     if (!err) {
          shp->shm_perm.mode |= SHM_LOCKED;
          shp->mlock_user = user;
     }
     ...
==

Other results of this are:
1. the new shp->mlock_user is not get-ed and will point to freed
   memory when the task dies.
2. the RLIMIT_MEMLOCK is screwed on both user structs.

The exploit looks like this:

==
    id = shmget(...);
    setresuid(uid, 0, 0);
    shmctl(id, SHM_LOCK, NULL);
    setresuid(uid + 1, 0, 0);
    shmctl(id, SHM_LOCK, NULL);
==

My solution is to return 0 to the userspace and do not change the
segment's user.

Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
ipc/shm.c