mm: reorder can_do_mlock to fix audit denial
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 <fbe788dcd509b324901fbdfe505a4d610d560569@google.com>
Acked-by: Nick Kralevich <e7ef2d30577bd192d036a7f424ec6dd692d415f2@google.com>
Cc: Jeff Vander Stoep <fbe788dcd509b324901fbdfe505a4d610d560569@google.com>
Cc: Sasha Levin <e642b69ed2fc111e09ffdc37feb733a52253340d@oracle.com>
Cc: "Paul E. McKenney" <1e0ce936bb9b355d257bf5790d2513c3f28be22b@linux.vnet.ibm.com>
Cc: Rik van Riel <a21938f5d463ddf41aa718934c205ca2cce8ebbc@redhat.com>
Cc: Vlastimil Babka <db766431e3f0373ca1ec8fa855cfd5f84b2f2eb6@suse.cz>
Cc: Paul Cassella <6d2d03ae85dfddf16aee17102bb77a74daed91be@cray.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs