mm/mlock.c: mlockall error for flag MCL_ONFAULT
authorPotyra, Stefan <[email protected]>
Thu, 13 Jun 2019 22:55:55 +0000 (15:55 -0700)
committerLinus Torvalds <[email protected]>
Fri, 14 Jun 2019 03:34:56 +0000 (17:34 -1000)
If mlockall() is called with only MCL_ONFAULT as flag, it removes any
previously applied lockings and does nothing else.

This behavior is counter-intuitive and doesn't match the Linux man page.

  For mlockall():

  EINVAL Unknown flags were specified or MCL_ONFAULT was specified
  without either MCL_FUTURE or MCL_CURRENT.

Consequently, return the error EINVAL, if only MCL_ONFAULT is passed.
That way, applications will at least detect that they are calling
mlockall() incorrectly.

Link: http://lkml.kernel.org/r/[email protected]
Fixes: b0f205c2a308 ("mm: mlock: add mlock flags to enable VM_LOCKONFAULT usage")
Signed-off-by: Stefan Potyra <[email protected]>
Reviewed-by: Daniel Jordan <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/mlock.c

index 080f3b36415b2ec34999dbc3d7dc6ea8f876cddd..cef65bf3964c3e618ace98b5514e0a480a2012b6 100644 (file)
@@ -797,7 +797,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
        unsigned long lock_limit;
        int ret;
 
-       if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
+       if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)) ||
+           flags == MCL_ONFAULT)
                return -EINVAL;
 
        if (!can_do_mlock())