mm: reorder can_do_mlock to fix audit denial
authorJeff Vander Stoep <jeffv@google.com>
Wed, 11 Mar 2015 21:32:24 +0000 (14:32 -0700)
committerAndres Morales <anmorales@google.com>
Wed, 11 Mar 2015 21:32:24 +0000 (14:32 -0700)
commite48e8c45925185c02b23ae461671be29c91101d5
tree991cb3ca999b8a043791fbcb8fc54f4745a4c5ea
parent062a6b5efee1a4e97fae2569517d35af9ed99148
mm: reorder can_do_mlock to fix audit denial

A userspace call to mmap(MAP_LOCKED) may result in the successful locking
of memory while also producing a confusing audit log denial.  can_do_mlock
checks capable and rlimit.  If either of these return positive
can_do_mlock returns true.  The capable check leads to an LSM hook used by
apparmour and selinux which produce the audit denial.  Reordering so
rlimit is checked first eliminates the denial on success, only recording a
denial when the lock is unsuccessful as a result of the denial.

Signed-off-by: Jeff Vander Stoep <jeffv@google.com>
Acked-by: Nick Kralevich <nnk@google.com>
Cc: Jeff Vander Stoep <jeffv@google.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Paul Cassella <cassella@cray.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mlock.c