From 6105776414407225c67cb6a758aab8c5cd4db96b Mon Sep 17 00:00:00 2001 From: Domenico Andreoli Date: Mon, 15 Mar 2021 17:47:39 +0800 Subject: [PATCH] hibernate: Allow uswsusp to write to swap mainline inclusion from mainline-5.7-rc1 commit 56939e014a6c212b317414faa307029e2e80c3b9 category: bugfix bugzilla: 50612 CVE: NA --------------------------- 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: dc617f29dbe5 ("vfs: don't allow writes to swap files") Reported-by: Domenico Andreoli Reported-by: Marian Klein Signed-off-by: Domenico Andreoli Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: zhangyi (F) Reviewed-by: Yang Erkun Signed-off-by: Yang Yingliang Signed-off-by: Cheng Jian --- fs/block_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 5f58e1a604a0..a90bfc36c6da 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "internal.h" struct bdev_inode { @@ -2007,7 +2008,8 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) if (bdev_read_only(I_BDEV(bd_inode))) return -EPERM; - if (IS_SWAPFILE(bd_inode)) + /* uswsusp needs write permission to the swap */ + if (IS_SWAPFILE(bd_inode) && !hibernation_available()) return -ETXTBSY; if (!iov_iter_count(from)) -- GitLab