CHROMIUM: Restrict swapon() to "zram" devices / lock down zram
authorWill Drewry <wad@chromium.org>
Thu, 21 Mar 2013 22:00:53 +0000 (17:00 -0500)
committerChromeBot <chrome-bot@google.com>
Wed, 3 Apr 2013 18:49:14 +0000 (11:49 -0700)
commitab3e3ed0b467c2dabbf78d845c5bd9773a512214
tree5641d12fd4f5b3d6af802099903fd53b4d48f277
parent51f5eb1c0c5614e841e2adf7f504dda1e79298d9
CHROMIUM: Restrict swapon() to "zram" devices / lock down zram

This cl contains three distinct changes collapsed into
one CL as per semenzato's request:
1. Restrict CONFIG_SWAP to ensure that only zram devices
   may be used.
2. Restrict zram to disallow open calls, even from root, if
   the device is claimed (e.g., by sys_swapon)
3. Add swapoff fallback when filp_open fails to use the path lookup.
   I don't believe swapoff needs filp_open() since kern_path()
   provides the data needed without a file object.
4. Add an open counter to zram to ensure that it is not opened more
   times than swapon(2) will claim it -- twice:
   - blkdev_get and filp_open (for swap_file)

Signed-off-by: Will Drewry <wad@chromium.org>
TEST=tested on lumpy; swapon, swapoff, change zram during swapon fails, change withotu swapon succeeds.
BUG=chromium:220974

Change-Id: Ic281a7004a81b2897cf0bf1c5d334351061261f1
Reviewed-on: https://gerrit.chromium.org/gerrit/46168
Tested-by: Will Drewry <wad@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Commit-Queue: Will Drewry <wad@chromium.org>
drivers/staging/zram/zram_drv.c
drivers/staging/zram/zram_drv.h
mm/swapfile.c