[PATCH v4 2/3] exec: PR_HIDE_SELF_EXE hides /proc/self/map_files

From: Giuseppe Scrivano
Date: Fri Mar 10 2023 - 06:27:17 EST


extend the new prctl(PR_HIDE_SELF_EXE) to prevent using
/proc/self/map_files as well.

Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
---
fs/proc/base.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 14102a133655..72f1cb44691f 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2255,9 +2255,21 @@ proc_map_files_get_link(struct dentry *dentry,
struct inode *inode,
struct delayed_call *done)
{
+ struct task_struct *task;
+ bool hide_self_exe;
+
if (!checkpoint_restore_ns_capable(&init_user_ns))
return ERR_PTR(-EPERM);

+ task = get_proc_task(d_inode(dentry));
+ if (!task)
+ return ERR_PTR(-ENOENT);
+ hide_self_exe = is_hide_self_exe_blocked(task);
+ put_task_struct(task);
+
+ if (hide_self_exe)
+ return ERR_PTR(-EPERM);
+
return proc_pid_get_link(dentry, inode, done);
}

--
2.39.2