* [RFC] mm: block swap in mtd partition
@ 2022-11-04 11:28 Lucas Martins Alves
0 siblings, 0 replies; only message in thread
From: Lucas Martins Alves @ 2022-11-04 11:28 UTC (permalink / raw)
To: akpm; +Cc: linux-mm
[-- Attachment #1: Type: text/plain, Size: 1720 bytes --]
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))
[-- Attachment #2: Type: text/html, Size: 4911 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-04 11:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 11:28 [RFC] mm: block swap in mtd partition Lucas Martins Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox