diff mbox series

[RFC,4/6] mm: swap: Add randomization check for swapon/off calls

Message ID 1652860121-24092-5-git-send-email-quic_vivekuma@quicinc.com (mailing list archive)
State New
Headers show
Series Bootloader based hibernation | expand

Commit Message

Vivek Kumar May 18, 2022, 7:48 a.m. UTC
Add addtional check on swapon/swapoff sycalls to disable
randomization of swap offsets if GENHD_FL_NO_RANDOMIZE
flag is passed.

Signed-off-by: Vivek Kumar <quic_vivekuma@quicinc.com>
Signed-off-by: Prasanna Kumar <quic_kprasan@quicinc.com>
---
 mm/swapfile.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Andrew Lunn May 18, 2022, 12:27 p.m. UTC | #1
On Wed, May 18, 2022 at 01:18:39PM +0530, Vivek Kumar wrote:
> Add addtional check on swapon/swapoff sycalls to disable
> randomization of swap offsets if GENHD_FL_NO_RANDOMIZE
> flag is passed.

Is there already a flag in the image header which tells you if the
image is randomozied or not? I assume the bootloader needs to know,
doing a linear read of a randomized image is not going to end well.

      Andrew
diff mbox series

Patch

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 1c3d5b9..a3eeab6 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2474,7 +2474,8 @@  SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
 	if (p->flags & SWP_CONTINUED)
 		free_swap_count_continuations(p);
 
-	if (!p->bdev || !bdev_nonrot(p->bdev))
+	if (!p->bdev || (p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE)
+			|| !bdev_nonrot(p->bdev))
 		atomic_dec(&nr_rotate_swap);
 
 	mutex_lock(&swapon_mutex);
@@ -3065,7 +3066,8 @@  SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	if (p->bdev && p->bdev->bd_disk->fops->rw_page)
 		p->flags |= SWP_SYNCHRONOUS_IO;
 
-	if (p->bdev && bdev_nonrot(p->bdev)) {
+	if (p->bdev && !(p->bdev->bd_disk->flags & GENHD_FL_NO_RANDOMIZE) &&
+				bdev_nonrot(p->bdev)) {
 		int cpu;
 		unsigned long ci, nr_cluster;