hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/proc/fd.c
....@@ -6,6 +6,7 @@
66 #include <linux/fdtable.h>
77 #include <linux/namei.h>
88 #include <linux/pid.h>
9
+#include <linux/ptrace.h>
910 #include <linux/security.h>
1011 #include <linux/file.h>
1112 #include <linux/seq_file.h>
....@@ -53,9 +54,10 @@
5354 if (ret)
5455 return ret;
5556
56
- seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n",
57
+ seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\nino:\t%lu\n",
5758 (long long)file->f_pos, f_flags,
58
- real_mount(file->f_path.mnt)->mnt_id);
59
+ real_mount(file->f_path.mnt)->mnt_id,
60
+ file_inode(file)->i_ino);
5961
6062 show_fd_locks(m, file, files);
6163 if (seq_has_overflowed(m))
....@@ -69,8 +71,30 @@
6971 return 0;
7072 }
7173
74
+static int proc_fdinfo_access_allowed(struct inode *inode)
75
+{
76
+ bool allowed = false;
77
+ struct task_struct *task = get_proc_task(inode);
78
+
79
+ if (!task)
80
+ return -ESRCH;
81
+
82
+ allowed = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS);
83
+ put_task_struct(task);
84
+
85
+ if (!allowed)
86
+ return -EACCES;
87
+
88
+ return 0;
89
+}
90
+
7291 static int seq_fdinfo_open(struct inode *inode, struct file *file)
7392 {
93
+ int ret = proc_fdinfo_access_allowed(inode);
94
+
95
+ if (ret)
96
+ return ret;
97
+
7498 return single_open(file, seq_show, inode);
7599 }
76100
....@@ -325,7 +349,7 @@
325349 struct proc_inode *ei;
326350 struct inode *inode;
327351
328
- inode = proc_pid_make_inode(dentry->d_sb, task, S_IFREG | S_IRUSR);
352
+ inode = proc_pid_make_inode(dentry->d_sb, task, S_IFREG | S_IRUGO);
329353 if (!inode)
330354 return ERR_PTR(-ENOENT);
331355
....@@ -351,12 +375,23 @@
351375 proc_fdinfo_instantiate);
352376 }
353377
378
+static int proc_open_fdinfo(struct inode *inode, struct file *file)
379
+{
380
+ int ret = proc_fdinfo_access_allowed(inode);
381
+
382
+ if (ret)
383
+ return ret;
384
+
385
+ return 0;
386
+}
387
+
354388 const struct inode_operations proc_fdinfo_inode_operations = {
355389 .lookup = proc_lookupfdinfo,
356390 .setattr = proc_setattr,
357391 };
358392
359393 const struct file_operations proc_fdinfo_operations = {
394
+ .open = proc_open_fdinfo,
360395 .read = generic_read_dir,
361396 .iterate_shared = proc_readfdinfo,
362397 .llseek = generic_file_llseek,