• Rik van Riel's avatar
    [PATCH] rlimit-based mlocks for unprivileged users · 16698c49
    Rik van Riel authored
    Here is the last agreed-on patch that lets normal users mlock pages up to
    their rlimit.  This patch addresses all the issues brought up by Chris and
    Andrea.
    
    From: Chris Wright <chrisw@osdl.org>
    
    Couple more nits.
    
    The default lockable amount is one page now (first patch is was 0).  Why
    don't we keep it as 0, with the CAP_IPC_LOCK overrides in place?  That way
    nothing is changed from user perspective, and the rest of the policy can be
    done by userspace as it should.
    
    This patch breaks in one scenario.  When ulimit == 0, process has
    CAP_IPC_LOCK, and does SHM_LOCK.  The subsequent unlock or destroy will
    corrupt the locked_shm count.
    
    It's also inconsistent in handling user_can_mlock/CAP_IPC_LOCK interaction
    betwen shm_lock and shm_hugetlb.
    
    SHM_HUGETLB can now only be done by the shm_group or CAP_IPC_LOCK.
    Not any can_do_mlock() user.
    
    Double check of can_do_mlock isn't needed in SHM_LOCK path.
    
    Interface names user_can_mlock and user_substract_mlock could be better.
    
    Incremental update below.  Ran some simple sanity tests on this plus my
    patch below and didn't find any problems.
    
    * Make default RLIM_MEMLOCK limit 0.
    * Move CAP_IPC_LOCK check into user_can_mlock to be consistent
      and fix but with ulimit == 0 && CAP_IPC_LOCK with SHM_LOCK.
    * Allow can_do_mlock() user to try SHM_HUGETLB setup.
    * Remove unecessary extra can_do_mlock() test in shmem_lock().
    * Rename user_can_mlock to user_shm_lock and user_subtract_mlock
      to user_shm_unlock.
    * Use user instead of current->user to fit in 80 cols on SHM_LOCK.
    Signed-off-by: default avatarRik van Riel <riel@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    16698c49
resource.h 1.49 KB