Skip to content

Commit a5a6579

Browse files
jeffvanderstoeptorvalds
authored andcommitted
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d3733e5 commit a5a6579

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/mlock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
int can_do_mlock(void)
2828
{
29-
if (capable(CAP_IPC_LOCK))
30-
return 1;
3129
if (rlimit(RLIMIT_MEMLOCK) != 0)
3230
return 1;
31+
if (capable(CAP_IPC_LOCK))
32+
return 1;
3333
return 0;
3434
}
3535
EXPORT_SYMBOL(can_do_mlock);

0 commit comments

Comments
 (0)