Question: Block swap in mtd partition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, 

I'm enabling swap in kernel version 4.9.206 for an embedded system, however I want users of that kernel to not be able to use mtd partitions for swap, so I made the change below. Is there a better way to do this within the kernel? Can this change have undesirable effects on the kernel?

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 855f62ab8c1b..92fed4eb7a97 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2450,6 +2450,22 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
      mapping = swap_file->f_mapping;
      inode = mapping->host;
 
+     if( S_ISBLK(inode->i_mode) )
+           if( imajor(inode) == MTD_BLOCK_MAJOR )
+           {
+                 pr_warn("It is not allowed to use internal flash partitions for swap.\n");
+                 error = -EINVAL;
+                 goto bad_swap;
+           }
+
+     if( S_ISREG(inode->i_mode) )
+           if( MAJOR(inode->i_sb->s_dev) == MTD_BLOCK_MAJOR )
+           {
+                 pr_warn("It is not allowed to use files in internal flash for swap.\n");
+                 error = -EINVAL;
+                 goto bad_swap;
+           }
+
      /* If S_ISREG(inode->i_mode) will do inode_lock(inode); */
      error = claim_swapfile(p, inode);
      if (unlikely(error))

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux