mm-memfd-add-mfd_noexec_seal-and-mfd_exec.patch removed from -mm tree
The quilt patch titled
Subject: mm/memfd: add MFD_NOEXEC_SEAL and MFD_EXEC
has been removed from the -mm tree. Its filename was
mm-memfd-add-mfd_noexec_seal-and-mfd_exec.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 MFD_NOEXEC_SEAL and MFD_EXEC
Date: Thu, 15 Dec 2022 00:12:03 +0000
The new MFD_NOEXEC_SEAL and MFD_EXEC flags allows application to set executable bit at creation time (memfd_create).
When MFD_NOEXEC_SEAL is set, memfd is created without executable bit (mode:0666), and sealed with F_SEAL_EXEC, so it can't be chmod to be executable (mode: 0777) after creation.
when MFD_EXEC flag is set, memfd is created with executable bit (mode:0777), this is the same as the old behavior of memfd_create.
The new pid namespaced sysctl vm.memfd_noexec has 3 values:
0: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like
MFD_EXEC was set.
1: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like
MFD_NOEXEC_SEAL was set.
2: memfd_create() without MFD_NOEXEC_SEAL will be rejected.
The sysctl allows finer control of memfd_create for old-software that doesn't set the executable bit, for example, a container with vm.memfd_noexec=1 means the old-software will create non-executable memfd by default. Also, the value of memfd_noexec is passed to child namespace at creation time. For example, if the init namespace has vm.memfd_noexec=2, all its children namespaces will be created with 2.
---
include/linux/pid_namespace.h | 19 ++++++++++ include/uapi/linux/memfd.h | 4 ++ kernel/pid_namespace.c | 5 ++ kernel/pid_sysctl.h | 60 ++++++++++++++++++++++++++++++++ mm/memfd.c | 48 ++++++++++++++++++++++++- 5 files changed, 134 insertions(+), 2 deletions(-)
include/linux/pid_namespace.h renamed from include/linux/pid_namespace.h~mm-memfd-add-mfd_noexec_seal-and-mfd_exec +19 -0
@@ -16,6 +16,21 @@struct fs_pin ; +#if defined(CONFIG_SYSCTL ) && defined(CONFIG_MEMFD_CREATE ) +/* +* sysctl for vm.memfd_noexec +* 0: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL +* acts like MFD_EXEC was set. +* 1: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL +* acts like MFD_NOEXEC_SEAL was set. +* 2: memfd_create() without MFD_NOEXEC_SEAL will be +* rejected. +*/ +#define MEMFD_NOEXEC_SCOPE_EXEC 0 +#define MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL 1 +#define MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED 2 +#endif +struct pid_namespace {struct idr idr;struct rcu_head rcu;
@@ -31,6 +46,10 @@ struct pid_namespace {struct ucounts *ucounts;int reboot;/* group exit code if this pidns was rebooted */ struct ns_common ns; +#if defined(CONFIG_SYSCTL ) && defined(CONFIG_MEMFD_CREATE ) +/* sysctl for vm.memfd_noexec */ +int memfd_noexec_scope; +#endif } __randomize_layout;extern struct pid_namespace init_pid_ns;
include/uapi/linux/memfd.h renamed from include/uapi/linux/memfd.h~mm-memfd-add-mfd_noexec_seal-and-mfd_exec +4 -0
@@ -8,6 +8,10 @@#define MFD_CLOEXEC 0x0001U#define MFD_ALLOW_SEALING 0x0002U#define MFD_HUGETLB 0x0004U +/* not executable and sealed to prevent changing to executable. */ +#define MFD_NOEXEC_SEAL 0x0008U +/* executable */ +#define MFD_EXEC 0x0010U/* * Huge page size encoding when MFD_HUGETLB is specified, and a huge page
kernel/pid_namespace.c renamed from kernel/pid_namespace.c~mm-memfd-add-mfd_noexec_seal-and-mfd_exec +5 -0
@@ -23,6 +23,7 @@#include <linux/sched/task.h> #include <linux/sched/signal.h> #include <linux/idr.h> +#include "pid_sysctl.h" static DEFINE_MUTEX (pid_caches_mutex);static struct kmem_cache *pid_ns_cachep;
@@ -110,6 +111,8 @@ static struct pid_namespace *create_pid_ ns->ucounts = ucounts; ns->pid_allocated =PIDNS_ADDING ; +initialize_memfd_noexec_scope (ns); +return ns; out_free_idr:
@@ -455,6 +458,8 @@ static __init int pid_namespaces_init(vo#ifdef CONFIG_CHECKPOINT_RESTORE register_sysctl_paths (kern_path, pid_ns_ctl_table);#endif + +register_pid_ns_sysctl_table_vm ();return 0 ; }
kernel/pid_sysctl.h new file +60 -0
60 lines not on this page · raw message
mm/memfd.c renamed from mm/memfd.c~mm-memfd-add-mfd_noexec_seal-and-mfd_exec +46 -2
77 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are