Commit a5a6579d authored by Jeff Vander Stoep's avatar Jeff Vander Stoep Committed by Linus Torvalds
Browse files

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: default avatarJeff Vander Stoep <>
Acked-by: default avatarNick Kralevich <>
Cc: Jeff Vander Stoep <>
Cc: Sasha Levin <>
Cc: "Paul E. McKenney" <>
Cc: Rik van Riel <>
Cc: Vlastimil Babka <>
Cc: Paul Cassella <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent d3733e5c
......@@ -26,10 +26,10 @@
int can_do_mlock(void)
if (capable(CAP_IPC_LOCK))
return 1;
if (rlimit(RLIMIT_MEMLOCK) != 0)
return 1;
if (capable(CAP_IPC_LOCK))
return 1;
return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment