[PATCH] hibernate: Allow uswsusp to write to swap

Domenico Andreoli
2020-03-04T08:26:35Z

From: Domenico Andreoli <domenico.andreoli@linux.com>

It turns out that there is one use case for programs being able to
write to swap devices, and that is the userspace hibernation code.

Quick fix: disable the S_SWAPFILE check if hibernation is configured.

Fixes: 1638045c3677 ("mm: set S_SWAPFILE on blockdev swap devices")
Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
Reported-by: Marian Klein <mkleinsoft@gmail.com>
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>

---
fs/block_dev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

Index: b/fs/block_dev.c
===================================================================
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -2001,7 +2001,8 @@ ssize_t blkdev_write_iter(struct kiocb *
if (bdev_read_only(I_BDEV(bd_inode)))
return -EPERM;

- if (IS_SWAPFILE(bd_inode))
+ /* uswsusp needs to write to the swap */
+ if (IS_SWAPFILE(bd_inode) && !IS_ENABLED(CONFIG_HIBERNATION))
return -ETXTBSY;

if (!iov_iter_count(from))