eBPF-based security platform
patches: Add an LSM hook for read-only remote mm access
John Fastabend9bce821b911c
diff --git a/testing/kernel/patches/0024-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch b/testing/kernel/patches/0024-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patchnew file mode 100644index 00000000..850b0a45--- /dev/null+++ b/testing/kernel/patches/0024-mm-Let-LSMs-check-read-only-remote-mm-access-under-CAP_PERFMON.patch@@ -0,0 +1,113 @@+From 94eb18b95c122ad0747d3c4030dce92c65ce9a97 Mon Sep 17 00:00:00 2001+From: Daniel Borkmann <[email protected]>+Date: Tue, 17 Nov 2026 12:20:31 +0000+Subject: [PATCH] mm: Let LSMs check read-only remote mm access under+ CAP_PERFMON++Since commit 0c555a3c1bc9 ("mm,procfs: allow read-only remote mm access+under CAP_PERFMON"), mm_access() grants a read-mode access to a caller+with CAP_PERFMON or CAP_SYS_ADMIN after ptrace_may_access() refused it.+The refusal may have come from an LSM's ptrace_access_check hook, which+then has no say: /proc/<pid>/environ, maps, smaps, numa_maps, pagemap+and auxv of a task the LSM keeps others away from open all the same.++Shirudo marks the processes that run its runtime binary and refuses+every ptrace access to them from tasks without its authority. With the+perfmon path, root reads their environment and their memory layout.++Call a new mm_read_access hook before mm_access() grants a read-mode+access that way. It sees the target task and the PTRACE_MODE flags of+the access, as ptrace_access_check does, and is consulted only on the+CAP_PERFMON path, so an access ptrace_may_access() allows is not+checked twice.++Signed-off-by: Daniel Borkmann <[email protected]>+---+ include/linux/lsm_hook_defs.h | 1 ++ include/linux/security.h | 7 ++++++++ kernel/fork.c | 3 ++-+ security/security.c | 17 ++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-)++diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h+index 90209bf5cf6f..c52571d8ee65 100644+--- a/include/linux/lsm_hook_defs.h++++ b/include/linux/lsm_hook_defs.h+@@ -36,6 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from,+ LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,+ unsigned int mode)+ LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent)++LSM_HOOK(int, 0, mm_read_access, struct task_struct *task, unsigned int mode)+ LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective,+ kernel_cap_t *inheritable, kernel_cap_t *permitted)+ LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old,+diff --git a/include/linux/security.h b/include/linux/security.h+index f017412d5adb..e44a065b1145 100644+--- a/include/linux/security.h++++ b/include/linux/security.h+@@ -340,6 +340,7 @@ int security_binder_transfer_file(const struct cred *from,+ const struct cred *to, const struct file *file);+ int security_ptrace_access_check(struct task_struct *child, unsigned int mode);+ int security_ptrace_traceme(struct task_struct *parent);++int security_mm_read_access(struct task_struct *task, unsigned int mode);+ int security_capget(const struct task_struct *target,+ kernel_cap_t *effective,+ kernel_cap_t *inheritable,+@@ -687,6 +688,12 @@ static inline int security_ptrace_traceme(struct task_struct *parent)+ return cap_ptrace_traceme(parent);+ }+++static inline int security_mm_read_access(struct task_struct *task,++ unsigned int mode)++{++ return 0;++}+++ static inline int security_capget(const struct task_struct *target,+ kernel_cap_t *effective,+ kernel_cap_t *inheritable,+diff --git a/kernel/fork.c b/kernel/fork.c+index 8b108ed37152..f8da387a126e 100644+--- a/kernel/fork.c++++ b/kernel/fork.c+@@ -1402,7 +1402,8 @@ static bool may_access_mm(struct mm_struct *mm, struct task_struct *task, unsign+ return true;+ if (ptrace_may_access(task, mode))+ return true;+- if ((mode & PTRACE_MODE_READ) && perfmon_capable())++ if ((mode & PTRACE_MODE_READ) && perfmon_capable() &&++ !security_mm_read_access(task, mode))+ return true;+ return false;+ }+diff --git a/security/security.c b/security/security.c+index 86636c894ebe..45869f746bcb 100644+--- a/security/security.c++++ b/security/security.c+@@ -609,6 +609,23 @@ int security_ptrace_traceme(struct task_struct *parent)+ return call_int_hook(ptrace_traceme, parent);+ }+++/**++ * security_mm_read_access() - Check a read-only access granted by CAP_PERFMON++ * @task: task whose memory is accessed++ * @mode: PTRACE_MODE flags of the access, read mode++ *++ * mm_access() grants a read-only access to the memory of @task to a caller++ * with CAP_PERFMON even when ptrace_may_access(), and so the++ * ptrace_access_check hook, refused it. Check that access before it is++ * granted that way.++ *++ * Return: Returns 0 if permission is granted.++ */++int security_mm_read_access(struct task_struct *task, unsigned int mode)++{++ return call_int_hook(mm_read_access, task, mode);++}+++ /**+ * security_capget() - Get the capability sets for a process+ * @target: target process+--+2.43.0+