Skip to contentSkip to conversation

mm-memfd-add-write-seals-when-apply-seal_exec-to-executable-memfd.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jan 19, 2023

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/memfd: add write seals when apply SEAL_EXEC to executable memfd
has been removed from the -mm tree. Its filename was
mm-memfd-add-write-seals-when-apply-seal_exec-to-executable-memfd.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Jeff Xu <[email protected]>
Subject: mm/memfd: add write seals when apply SEAL_EXEC to executable memfd
Date: Thu, 15 Dec 2022 00:12:04 +0000

In order to avoid WX mappings, add F_SEAL_WRITE when apply F_SEAL_EXEC to an executable memfd, so W^X from start.

This implys application need to fill the content of the memfd first, after F_SEAL_EXEC is applied, application can no longer modify the content of the memfd.

Typically, application seals the memfd right after writing to it. For example:
1. memfd_create(MFD_EXEC).
2. write() code to the memfd.
3. fcntl(F_ADD_SEALS, F_SEAL_EXEC) to convert the memfd to W^X.
4. call exec() on the memfd.

Cc Daniel Verkamp <[email protected]>
Cc David Herrmann <[email protected]>
Cc Dmitry Torokhov <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Jann Horn <[email protected]>
Cc Jorge Lucangeli Obes <[email protected]>
Cc kernel test robot <[email protected]>
Cc Shuah Khan <[email protected]>

---

 mm/memfd.c |    6 ++++++
 1 file changed, 6 insertions(+)
mm/memfd.c renamed from mm/memfd.c~mm-memfd-add-write-seals-when-apply-seal_exec-to-executable-memfd +6 -0
@@ -222,6 +222,12 @@ static int memfd_add_seals(struct file *
 		}
 	}
 
+	/*
+	 * SEAL_EXEC implys SEAL_WRITE, making W^X from the start.
+	 */
+	if (seals & F_SEAL_EXEC && inode->i_mode & 0111)
+		seals |= F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_FUTURE_WRITE;
+
 	*file_seals |= seals;
 	error = 0;
 

_

Patches currently in -mm which might be from [email protected] are