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

Message ID 20230310112554.1261731-2-gscrivan@redhat.com
State New
Headers
Series [v4,1/3] exec: add PR_HIDE_SELF_EXE prctl |

Commit Message

Giuseppe Scrivano March 10, 2023, 11:25 a.m. UTC
  extend the new prctl(PR_HIDE_SELF_EXE) to prevent using
/proc/self/map_files as well.

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

Patch

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);
 }