diff options
author | Hugh Dickins <hughd@google.com> | 2012-03-28 23:42:42 +0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-29 02:14:35 +0200 |
commit | d15cab975459fb6092eeba1be72c13621337784f (patch) | |
tree | 5c1d8d18c65a34eb738c97d75f2c44becdff1de3 /mm | |
parent | mm, coredump: fail allocations when coredumping instead of oom killing (diff) | |
download | linux-d15cab975459fb6092eeba1be72c13621337784f.tar.xz linux-d15cab975459fb6092eeba1be72c13621337784f.zip |
swapon: check validity of swap_flags
Most system calls taking flags first check that the flags passed in are
valid, and that helps userspace to detect when new flags are supported.
But swapon never did so: start checking now, to help if we ever want to
support more swap_flags in future.
It's difficult to get stray bits set in an int, and swapon is not widely
used, so this is most unlikely to break any userspace; but we can just
revert if it turns out to do so.
Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/swapfile.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c index dae42f380d6e..fafc26d1b1dc 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2022,6 +2022,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) struct page *page = NULL; struct inode *inode = NULL; + if (swap_flags & ~SWAP_FLAGS_VALID) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)) return -EPERM; |