linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Martins Alves <lucas.alves@lumal21.net.br>
To: "linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Question: Block swap in mtd partition
Date: Tue, 1 Nov 2022 11:15:08 +0000	[thread overview]
Message-ID: <CP4P284MB08027A76101EA1CC7AB9DB17C4369@CP4P284MB0802.BRAP284.PROD.OUTLOOK.COM> (raw)

[-- Attachment #1: Type: text/plain, Size: 1718 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: 3857 bytes --]

                 reply	other threads:[~2022-11-01 11:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CP4P284MB08027A76101EA1CC7AB9DB17C4369@CP4P284MB0802.BRAP284.PROD.OUTLOOK.COM \
    --to=lucas.alves@lumal21.net.br \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox