Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/proc/base.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * proc base directory handling functions |
| 7 | * |
| 8 | * 1999, Al Viro. Rewritten. Now it covers the whole per-process part. |
| 9 | * Instead of using magical inumbers to determine the kind of object |
| 10 | * we allocate and fill in-core inodes upon lookup. They don't even |
| 11 | * go into icache. We cache the reference to task_struct upon lookup too. |
| 12 | * Eventually it should become a filesystem in its own. We don't use the |
| 13 | * rest of procfs anymore. |
Mauricio Lin | e070ad4 | 2005-09-03 15:55:10 -0700 | [diff] [blame] | 14 | * |
| 15 | * |
| 16 | * Changelog: |
| 17 | * 17-Jan-2005 |
| 18 | * Allan Bezerra |
| 19 | * Bruna Moreira <bruna.moreira@indt.org.br> |
| 20 | * Edjard Mota <edjard.mota@indt.org.br> |
| 21 | * Ilias Biris <ilias.biris@indt.org.br> |
| 22 | * Mauricio Lin <mauricio.lin@indt.org.br> |
| 23 | * |
| 24 | * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT |
| 25 | * |
| 26 | * A new process specific entry (smaps) included in /proc. It shows the |
| 27 | * size of rss for each memory area. The maps entry lacks information |
| 28 | * about physical memory size (rss) for each mapped file, i.e., |
| 29 | * rss information for executables and library files. |
| 30 | * This additional information is useful for any tools that need to know |
| 31 | * about physical memory consumption for a process specific library. |
| 32 | * |
| 33 | * Changelog: |
| 34 | * 21-Feb-2005 |
| 35 | * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT |
| 36 | * Pud inclusion in the page table walking. |
| 37 | * |
| 38 | * ChangeLog: |
| 39 | * 10-Mar-2005 |
| 40 | * 10LE Instituto Nokia de Tecnologia - INdT: |
| 41 | * A better way to walks through the page table as suggested by Hugh Dickins. |
| 42 | * |
| 43 | * Simo Piiroinen <simo.piiroinen@nokia.com>: |
| 44 | * Smaps information related to shared, private, clean and dirty pages. |
| 45 | * |
| 46 | * Paul Mundt <paul.mundt@nokia.com>: |
| 47 | * Overall revision about smaps. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | #include <asm/uaccess.h> |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/errno.h> |
| 53 | #include <linux/time.h> |
| 54 | #include <linux/proc_fs.h> |
| 55 | #include <linux/stat.h> |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 56 | #include <linux/task_io_accounting_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/init.h> |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 58 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <linux/file.h> |
Al Viro | 9f3acc3 | 2008-04-24 07:44:08 -0400 | [diff] [blame] | 60 | #include <linux/fdtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <linux/string.h> |
| 62 | #include <linux/seq_file.h> |
| 63 | #include <linux/namei.h> |
Kirill Korotaev | 6b3286e | 2006-12-08 02:37:56 -0800 | [diff] [blame] | 64 | #include <linux/mnt_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <linux/mm.h> |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 66 | #include <linux/swap.h> |
Dipankar Sarma | b835996 | 2005-09-09 13:04:14 -0700 | [diff] [blame] | 67 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/kallsyms.h> |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 69 | #include <linux/stacktrace.h> |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 70 | #include <linux/resource.h> |
Kees Cook | 5096add | 2007-05-08 00:26:04 -0700 | [diff] [blame] | 71 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <linux/mount.h> |
| 73 | #include <linux/security.h> |
| 74 | #include <linux/ptrace.h> |
Roland McGrath | 0d094ef | 2008-07-25 19:45:49 -0700 | [diff] [blame] | 75 | #include <linux/tracehook.h> |
Andrew Morton | 87ebdc0 | 2013-02-27 17:03:16 -0800 | [diff] [blame] | 76 | #include <linux/printk.h> |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 77 | #include <linux/cgroup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include <linux/cpuset.h> |
| 79 | #include <linux/audit.h> |
Al Viro | 5addc5d | 2005-11-07 17:15:49 -0500 | [diff] [blame] | 80 | #include <linux/poll.h> |
Serge E. Hallyn | 1651e14 | 2006-10-02 02:18:08 -0700 | [diff] [blame] | 81 | #include <linux/nsproxy.h> |
Alexey Dobriyan | 8ac773b | 2006-10-19 23:28:32 -0700 | [diff] [blame] | 82 | #include <linux/oom.h> |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 83 | #include <linux/elf.h> |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 84 | #include <linux/pid_namespace.h> |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 85 | #include <linux/user_namespace.h> |
Al Viro | 5ad4e53 | 2009-03-29 19:50:06 -0400 | [diff] [blame] | 86 | #include <linux/fs_struct.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 87 | #include <linux/slab.h> |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 88 | #include <linux/flex_array.h> |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 89 | #include <linux/posix-timers.h> |
Connor O'Brien | 6e7b83d | 2018-01-31 18:11:57 -0800 | [diff] [blame] | 90 | #include <linux/cpufreq_times.h> |
Chris Metcalf | f133ecc | 2011-05-26 12:40:09 -0400 | [diff] [blame] | 91 | #ifdef CONFIG_HARDWALL |
| 92 | #include <asm/hardwall.h> |
| 93 | #endif |
KAMEZAWA Hiroyuki | 43d2b11 | 2012-01-10 15:08:09 -0800 | [diff] [blame] | 94 | #include <trace/events/oom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #include "internal.h" |
Cyrill Gorcunov | faf60af | 2012-08-23 14:43:24 +0400 | [diff] [blame] | 96 | #include "fd.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Alexey Dobriyan | e0a1a01 | 2018-02-06 15:36:59 -0800 | [diff] [blame] | 98 | #include "../../lib/kstrtox.h" |
| 99 | |
Eric W. Biederman | 0f2fe20 | 2006-06-26 00:25:46 -0700 | [diff] [blame] | 100 | /* NOTE: |
| 101 | * Implementing inode permission operations in /proc is almost |
| 102 | * certainly an error. Permission checks need to happen during |
| 103 | * each system call not at open time. The reason is that most of |
| 104 | * what we wish to check for permissions in /proc varies at runtime. |
| 105 | * |
| 106 | * The classic example of a problem is opening file descriptors |
| 107 | * in /proc for a task before it execs a suid executable. |
| 108 | */ |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | struct pid_entry { |
Alexey Dobriyan | cedbcca | 2014-08-08 14:21:33 -0700 | [diff] [blame] | 111 | const char *name; |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 112 | int len; |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 113 | umode_t mode; |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 114 | const struct inode_operations *iop; |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 115 | const struct file_operations *fop; |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 116 | union proc_op op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 119 | #define NOD(NAME, MODE, IOP, FOP, OP) { \ |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 120 | .name = (NAME), \ |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 121 | .len = sizeof(NAME) - 1, \ |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 122 | .mode = MODE, \ |
| 123 | .iop = IOP, \ |
| 124 | .fop = FOP, \ |
| 125 | .op = OP, \ |
| 126 | } |
| 127 | |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 128 | #define DIR(NAME, MODE, iops, fops) \ |
| 129 | NOD(NAME, (S_IFDIR|(MODE)), &iops, &fops, {} ) |
| 130 | #define LNK(NAME, get_link) \ |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 131 | NOD(NAME, (S_IFLNK|S_IRWXUGO), \ |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 132 | &proc_pid_link_inode_operations, NULL, \ |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 133 | { .proc_get_link = get_link } ) |
| 134 | #define REG(NAME, MODE, fops) \ |
| 135 | NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {}) |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 136 | #define ONE(NAME, MODE, show) \ |
Eric W. Biederman | be61408 | 2008-02-08 04:18:30 -0800 | [diff] [blame] | 137 | NOD(NAME, (S_IFREG|(MODE)), \ |
| 138 | NULL, &proc_single_file_operations, \ |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 139 | { .proc_show = show } ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Vegard Nossum | aed5417 | 2008-06-05 22:46:53 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Count the number of hardlinks for the pid_entry table, excluding the . |
| 143 | * and .. links. |
| 144 | */ |
| 145 | static unsigned int pid_entry_count_dirs(const struct pid_entry *entries, |
| 146 | unsigned int n) |
| 147 | { |
| 148 | unsigned int i; |
| 149 | unsigned int count; |
| 150 | |
| 151 | count = 0; |
| 152 | for (i = 0; i < n; ++i) { |
| 153 | if (S_ISDIR(entries[i].mode)) |
| 154 | ++count; |
| 155 | } |
| 156 | |
| 157 | return count; |
| 158 | } |
| 159 | |
Miklos Szeredi | f7ad3c6 | 2010-08-10 11:41:36 +0200 | [diff] [blame] | 160 | static int get_task_root(struct task_struct *task, struct path *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Hugh Dickins | 7c2c7d9 | 2009-03-28 23:21:27 +0000 | [diff] [blame] | 162 | int result = -ENOENT; |
| 163 | |
Miklos Szeredi | 0494f6e | 2005-09-06 15:18:22 -0700 | [diff] [blame] | 164 | task_lock(task); |
Miklos Szeredi | f7ad3c6 | 2010-08-10 11:41:36 +0200 | [diff] [blame] | 165 | if (task->fs) { |
| 166 | get_fs_root(task->fs, root); |
Hugh Dickins | 7c2c7d9 | 2009-03-28 23:21:27 +0000 | [diff] [blame] | 167 | result = 0; |
| 168 | } |
Miklos Szeredi | 0494f6e | 2005-09-06 15:18:22 -0700 | [diff] [blame] | 169 | task_unlock(task); |
Hugh Dickins | 7c2c7d9 | 2009-03-28 23:21:27 +0000 | [diff] [blame] | 170 | return result; |
Miklos Szeredi | 0494f6e | 2005-09-06 15:18:22 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Cyrill Gorcunov | 7773fbc | 2012-01-10 15:11:20 -0800 | [diff] [blame] | 173 | static int proc_cwd_link(struct dentry *dentry, struct path *path) |
Miklos Szeredi | 0494f6e | 2005-09-06 15:18:22 -0700 | [diff] [blame] | 174 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 175 | struct task_struct *task = get_proc_task(d_inode(dentry)); |
Miklos Szeredi | 0494f6e | 2005-09-06 15:18:22 -0700 | [diff] [blame] | 176 | int result = -ENOENT; |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 177 | |
| 178 | if (task) { |
Miklos Szeredi | f7ad3c6 | 2010-08-10 11:41:36 +0200 | [diff] [blame] | 179 | task_lock(task); |
| 180 | if (task->fs) { |
| 181 | get_fs_pwd(task->fs, path); |
| 182 | result = 0; |
| 183 | } |
| 184 | task_unlock(task); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 185 | put_task_struct(task); |
| 186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | return result; |
| 188 | } |
| 189 | |
Cyrill Gorcunov | 7773fbc | 2012-01-10 15:11:20 -0800 | [diff] [blame] | 190 | static int proc_root_link(struct dentry *dentry, struct path *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 192 | struct task_struct *task = get_proc_task(d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int result = -ENOENT; |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 194 | |
| 195 | if (task) { |
Miklos Szeredi | f7ad3c6 | 2010-08-10 11:41:36 +0200 | [diff] [blame] | 196 | result = get_task_root(task, path); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 197 | put_task_struct(task); |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return result; |
| 200 | } |
| 201 | |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 202 | static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, |
| 203 | size_t _count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 205 | struct task_struct *tsk; |
| 206 | struct mm_struct *mm; |
| 207 | char *page; |
| 208 | unsigned long count = _count; |
| 209 | unsigned long arg_start, arg_end, env_start, env_end; |
| 210 | unsigned long len1, len2, len; |
| 211 | unsigned long p; |
| 212 | char c; |
| 213 | ssize_t rv; |
| 214 | |
| 215 | BUG_ON(*pos < 0); |
| 216 | |
| 217 | tsk = get_proc_task(file_inode(file)); |
| 218 | if (!tsk) |
| 219 | return -ESRCH; |
| 220 | mm = get_task_mm(tsk); |
| 221 | put_task_struct(tsk); |
| 222 | if (!mm) |
| 223 | return 0; |
| 224 | /* Check if process spawned far enough to have cmdline. */ |
| 225 | if (!mm->env_end) { |
| 226 | rv = 0; |
| 227 | goto out_mmput; |
| 228 | } |
| 229 | |
| 230 | page = (char *)__get_free_page(GFP_TEMPORARY); |
| 231 | if (!page) { |
| 232 | rv = -ENOMEM; |
| 233 | goto out_mmput; |
| 234 | } |
| 235 | |
| 236 | down_read(&mm->mmap_sem); |
| 237 | arg_start = mm->arg_start; |
| 238 | arg_end = mm->arg_end; |
| 239 | env_start = mm->env_start; |
| 240 | env_end = mm->env_end; |
| 241 | up_read(&mm->mmap_sem); |
| 242 | |
| 243 | BUG_ON(arg_start > arg_end); |
| 244 | BUG_ON(env_start > env_end); |
| 245 | |
| 246 | len1 = arg_end - arg_start; |
| 247 | len2 = env_end - env_start; |
| 248 | |
Alexey Dobriyan | 3581d45 | 2015-07-17 16:24:09 -0700 | [diff] [blame] | 249 | /* Empty ARGV. */ |
| 250 | if (len1 == 0) { |
| 251 | rv = 0; |
| 252 | goto out_free_page; |
| 253 | } |
Alexey Dobriyan | 2ca66ff | 2014-08-08 14:21:41 -0700 | [diff] [blame] | 254 | /* |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 255 | * Inherently racy -- command line shares address space |
| 256 | * with code and data. |
Alexey Dobriyan | 2ca66ff | 2014-08-08 14:21:41 -0700 | [diff] [blame] | 257 | */ |
Willy Tarreau | 6f1abf8 | 2018-05-11 08:11:44 +0200 | [diff] [blame] | 258 | rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_ANON); |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 259 | if (rv <= 0) |
| 260 | goto out_free_page; |
| 261 | |
| 262 | rv = 0; |
| 263 | |
| 264 | if (c == '\0') { |
| 265 | /* Command line (set of strings) occupies whole ARGV. */ |
| 266 | if (len1 <= *pos) |
| 267 | goto out_free_page; |
| 268 | |
| 269 | p = arg_start + *pos; |
| 270 | len = len1 - *pos; |
| 271 | while (count > 0 && len > 0) { |
| 272 | unsigned int _count; |
| 273 | int nr_read; |
| 274 | |
| 275 | _count = min3(count, len, PAGE_SIZE); |
Willy Tarreau | 6f1abf8 | 2018-05-11 08:11:44 +0200 | [diff] [blame] | 276 | nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON); |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 277 | if (nr_read < 0) |
| 278 | rv = nr_read; |
| 279 | if (nr_read <= 0) |
| 280 | goto out_free_page; |
| 281 | |
| 282 | if (copy_to_user(buf, page, nr_read)) { |
| 283 | rv = -EFAULT; |
| 284 | goto out_free_page; |
| 285 | } |
| 286 | |
| 287 | p += nr_read; |
| 288 | len -= nr_read; |
| 289 | buf += nr_read; |
| 290 | count -= nr_read; |
| 291 | rv += nr_read; |
| 292 | } |
| 293 | } else { |
| 294 | /* |
| 295 | * Command line (1 string) occupies ARGV and maybe |
| 296 | * extends into ENVP. |
| 297 | */ |
| 298 | if (len1 + len2 <= *pos) |
| 299 | goto skip_argv_envp; |
| 300 | if (len1 <= *pos) |
| 301 | goto skip_argv; |
| 302 | |
| 303 | p = arg_start + *pos; |
| 304 | len = len1 - *pos; |
| 305 | while (count > 0 && len > 0) { |
| 306 | unsigned int _count, l; |
| 307 | int nr_read; |
| 308 | bool final; |
| 309 | |
| 310 | _count = min3(count, len, PAGE_SIZE); |
Willy Tarreau | 6f1abf8 | 2018-05-11 08:11:44 +0200 | [diff] [blame] | 311 | nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON); |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 312 | if (nr_read < 0) |
| 313 | rv = nr_read; |
| 314 | if (nr_read <= 0) |
| 315 | goto out_free_page; |
| 316 | |
| 317 | /* |
| 318 | * Command line can be shorter than whole ARGV |
| 319 | * even if last "marker" byte says it is not. |
| 320 | */ |
| 321 | final = false; |
| 322 | l = strnlen(page, nr_read); |
| 323 | if (l < nr_read) { |
| 324 | nr_read = l; |
| 325 | final = true; |
| 326 | } |
| 327 | |
| 328 | if (copy_to_user(buf, page, nr_read)) { |
| 329 | rv = -EFAULT; |
| 330 | goto out_free_page; |
| 331 | } |
| 332 | |
| 333 | p += nr_read; |
| 334 | len -= nr_read; |
| 335 | buf += nr_read; |
| 336 | count -= nr_read; |
| 337 | rv += nr_read; |
| 338 | |
| 339 | if (final) |
| 340 | goto out_free_page; |
| 341 | } |
| 342 | skip_argv: |
| 343 | /* |
| 344 | * Command line (1 string) occupies ARGV and |
| 345 | * extends into ENVP. |
| 346 | */ |
| 347 | if (len1 <= *pos) { |
| 348 | p = env_start + *pos - len1; |
| 349 | len = len1 + len2 - *pos; |
| 350 | } else { |
| 351 | p = env_start; |
| 352 | len = len2; |
| 353 | } |
| 354 | while (count > 0 && len > 0) { |
| 355 | unsigned int _count, l; |
| 356 | int nr_read; |
| 357 | bool final; |
| 358 | |
| 359 | _count = min3(count, len, PAGE_SIZE); |
Willy Tarreau | 6f1abf8 | 2018-05-11 08:11:44 +0200 | [diff] [blame] | 360 | nr_read = access_remote_vm(mm, p, page, _count, FOLL_ANON); |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 361 | if (nr_read < 0) |
| 362 | rv = nr_read; |
| 363 | if (nr_read <= 0) |
| 364 | goto out_free_page; |
| 365 | |
| 366 | /* Find EOS. */ |
| 367 | final = false; |
| 368 | l = strnlen(page, nr_read); |
| 369 | if (l < nr_read) { |
| 370 | nr_read = l; |
| 371 | final = true; |
| 372 | } |
| 373 | |
| 374 | if (copy_to_user(buf, page, nr_read)) { |
| 375 | rv = -EFAULT; |
| 376 | goto out_free_page; |
| 377 | } |
| 378 | |
| 379 | p += nr_read; |
| 380 | len -= nr_read; |
| 381 | buf += nr_read; |
| 382 | count -= nr_read; |
| 383 | rv += nr_read; |
| 384 | |
| 385 | if (final) |
| 386 | goto out_free_page; |
| 387 | } |
| 388 | skip_argv_envp: |
| 389 | ; |
| 390 | } |
| 391 | |
| 392 | out_free_page: |
| 393 | free_page((unsigned long)page); |
| 394 | out_mmput: |
| 395 | mmput(mm); |
| 396 | if (rv > 0) |
| 397 | *pos += rv; |
| 398 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 401 | static const struct file_operations proc_pid_cmdline_ops = { |
| 402 | .read = proc_pid_cmdline_read, |
| 403 | .llseek = generic_file_llseek, |
| 404 | }; |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | #ifdef CONFIG_KALLSYMS |
| 407 | /* |
| 408 | * Provides a wchan file via kallsyms in a proper one-value-per-file format. |
| 409 | * Returns the resolved symbol. If that fails, simply return the address. |
| 410 | */ |
Alexey Dobriyan | edfcd60 | 2014-08-08 14:21:44 -0700 | [diff] [blame] | 411 | static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, |
| 412 | struct pid *pid, struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Alexey Dobriyan | ffb4512 | 2007-05-08 00:28:41 -0700 | [diff] [blame] | 414 | unsigned long wchan; |
Tejun Heo | 9281ace | 2007-07-17 04:03:51 -0700 | [diff] [blame] | 415 | char symname[KSYM_NAME_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | wchan = get_wchan(task); |
| 418 | |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 419 | if (wchan && ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS) |
| 420 | && !lookup_symbol_name(wchan, symname)) |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 421 | seq_printf(m, "%s", symname); |
Ingo Molnar | b2f7392 | 2015-09-30 15:59:17 +0200 | [diff] [blame] | 422 | else |
Robin Humble | 1e92a61 | 2016-05-09 16:28:46 -0700 | [diff] [blame] | 423 | seq_putc(m, '0'); |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 424 | |
| 425 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | #endif /* CONFIG_KALLSYMS */ |
| 428 | |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 429 | static int lock_trace(struct task_struct *task) |
| 430 | { |
| 431 | int err = mutex_lock_killable(&task->signal->cred_guard_mutex); |
| 432 | if (err) |
| 433 | return err; |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 434 | if (!ptrace_may_access(task, PTRACE_MODE_ATTACH_FSCREDS)) { |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 435 | mutex_unlock(&task->signal->cred_guard_mutex); |
| 436 | return -EPERM; |
| 437 | } |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static void unlock_trace(struct task_struct *task) |
| 442 | { |
| 443 | mutex_unlock(&task->signal->cred_guard_mutex); |
| 444 | } |
| 445 | |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 446 | #ifdef CONFIG_STACKTRACE |
| 447 | |
| 448 | #define MAX_STACK_TRACE_DEPTH 64 |
| 449 | |
| 450 | static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns, |
| 451 | struct pid *pid, struct task_struct *task) |
| 452 | { |
| 453 | struct stack_trace trace; |
| 454 | unsigned long *entries; |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 455 | int err; |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 456 | int i; |
| 457 | |
Jann Horn | 3c5dc3f | 2018-10-05 15:51:58 -0700 | [diff] [blame] | 458 | /* |
| 459 | * The ability to racily run the kernel stack unwinder on a running task |
| 460 | * and then observe the unwinder output is scary; while it is useful for |
| 461 | * debugging kernel issues, it can also allow an attacker to leak kernel |
| 462 | * stack contents. |
| 463 | * Doing this in a manner that is at least safe from races would require |
| 464 | * some work to ensure that the remote task can not be scheduled; and |
| 465 | * even then, this would still expose the unwinder as local attack |
| 466 | * surface. |
| 467 | * Therefore, this interface is restricted to root. |
| 468 | */ |
| 469 | if (!file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN)) |
| 470 | return -EACCES; |
| 471 | |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 472 | entries = kmalloc(MAX_STACK_TRACE_DEPTH * sizeof(*entries), GFP_KERNEL); |
| 473 | if (!entries) |
| 474 | return -ENOMEM; |
| 475 | |
| 476 | trace.nr_entries = 0; |
| 477 | trace.max_entries = MAX_STACK_TRACE_DEPTH; |
| 478 | trace.entries = entries; |
| 479 | trace.skip = 0; |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 480 | |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 481 | err = lock_trace(task); |
| 482 | if (!err) { |
| 483 | save_stack_trace_tsk(task, &trace); |
| 484 | |
| 485 | for (i = 0; i < trace.nr_entries; i++) { |
Josh Poimboeuf | 8b927d7 | 2016-08-18 10:59:07 -0500 | [diff] [blame] | 486 | seq_printf(m, "[<%pK>] %pB\n", |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 487 | (void *)entries[i], (void *)entries[i]); |
| 488 | } |
| 489 | unlock_trace(task); |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 490 | } |
| 491 | kfree(entries); |
| 492 | |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 493 | return err; |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 494 | } |
| 495 | #endif |
| 496 | |
Naveen N. Rao | 5968cec | 2015-06-30 14:36:03 +0530 | [diff] [blame] | 497 | #ifdef CONFIG_SCHED_INFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* |
| 499 | * Provides /proc/PID/schedstat |
| 500 | */ |
Alexey Dobriyan | f6e826c | 2014-08-08 14:21:46 -0700 | [diff] [blame] | 501 | static int proc_pid_schedstat(struct seq_file *m, struct pid_namespace *ns, |
| 502 | struct pid *pid, struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Naveen N. Rao | 5968cec | 2015-06-30 14:36:03 +0530 | [diff] [blame] | 504 | if (unlikely(!sched_info_on())) |
| 505 | seq_printf(m, "0 0 0\n"); |
| 506 | else |
| 507 | seq_printf(m, "%llu %llu %lu\n", |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 508 | (unsigned long long)task->se.sum_exec_runtime, |
| 509 | (unsigned long long)task->sched_info.run_delay, |
| 510 | task->sched_info.pcount); |
| 511 | |
| 512 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | #endif |
| 515 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 516 | #ifdef CONFIG_LATENCYTOP |
| 517 | static int lstats_show_proc(struct seq_file *m, void *v) |
| 518 | { |
| 519 | int i; |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 520 | struct inode *inode = m->private; |
| 521 | struct task_struct *task = get_proc_task(inode); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 522 | |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 523 | if (!task) |
| 524 | return -ESRCH; |
| 525 | seq_puts(m, "Latency Top version : v0.1\n"); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 526 | for (i = 0; i < 32; i++) { |
Joe Perches | 34e49d4 | 2011-01-12 17:00:30 -0800 | [diff] [blame] | 527 | struct latency_record *lr = &task->latency_record[i]; |
| 528 | if (lr->backtrace[0]) { |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 529 | int q; |
Joe Perches | 34e49d4 | 2011-01-12 17:00:30 -0800 | [diff] [blame] | 530 | seq_printf(m, "%i %li %li", |
| 531 | lr->count, lr->time, lr->max); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 532 | for (q = 0; q < LT_BACKTRACEDEPTH; q++) { |
Joe Perches | 34e49d4 | 2011-01-12 17:00:30 -0800 | [diff] [blame] | 533 | unsigned long bt = lr->backtrace[q]; |
| 534 | if (!bt) |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 535 | break; |
Joe Perches | 34e49d4 | 2011-01-12 17:00:30 -0800 | [diff] [blame] | 536 | if (bt == ULONG_MAX) |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 537 | break; |
Joe Perches | 34e49d4 | 2011-01-12 17:00:30 -0800 | [diff] [blame] | 538 | seq_printf(m, " %ps", (void *)bt); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 539 | } |
Alexey Dobriyan | 9d6de12 | 2011-01-12 17:00:32 -0800 | [diff] [blame] | 540 | seq_putc(m, '\n'); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | } |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 544 | put_task_struct(task); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static int lstats_open(struct inode *inode, struct file *file) |
| 549 | { |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 550 | return single_open(file, lstats_show_proc, inode); |
Hiroshi Shimamoto | d6643d1 | 2008-02-14 10:27:00 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 553 | static ssize_t lstats_write(struct file *file, const char __user *buf, |
| 554 | size_t count, loff_t *offs) |
| 555 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 556 | struct task_struct *task = get_proc_task(file_inode(file)); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 557 | |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 558 | if (!task) |
| 559 | return -ESRCH; |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 560 | clear_all_latency_tracing(task); |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 561 | put_task_struct(task); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 562 | |
| 563 | return count; |
| 564 | } |
| 565 | |
| 566 | static const struct file_operations proc_lstats_operations = { |
| 567 | .open = lstats_open, |
| 568 | .read = seq_read, |
| 569 | .write = lstats_write, |
| 570 | .llseek = seq_lseek, |
Hiroshi Shimamoto | 13d77c3 | 2008-02-20 16:53:29 -0800 | [diff] [blame] | 571 | .release = single_release, |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | #endif |
| 575 | |
Alexey Dobriyan | 6ba51e3 | 2014-08-08 14:21:48 -0700 | [diff] [blame] | 576 | static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns, |
| 577 | struct pid *pid, struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
David Rientjes | a7f638f | 2012-05-29 15:06:47 -0700 | [diff] [blame] | 579 | unsigned long totalpages = totalram_pages + total_swap_pages; |
Oleg Nesterov | b95c35e | 2010-04-01 15:13:57 +0200 | [diff] [blame] | 580 | unsigned long points = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Oleg Nesterov | ef41939 | 2016-08-02 14:03:19 -0700 | [diff] [blame] | 582 | points = oom_badness(task, NULL, NULL, totalpages) * |
| 583 | 1000 / totalpages; |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 584 | seq_printf(m, "%lu\n", points); |
| 585 | |
| 586 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 589 | struct limit_names { |
Alexey Dobriyan | cedbcca | 2014-08-08 14:21:33 -0700 | [diff] [blame] | 590 | const char *name; |
| 591 | const char *unit; |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 592 | }; |
| 593 | |
| 594 | static const struct limit_names lnames[RLIM_NLIMITS] = { |
Kees Cook | cff4edb | 2009-09-22 16:45:32 -0700 | [diff] [blame] | 595 | [RLIMIT_CPU] = {"Max cpu time", "seconds"}, |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 596 | [RLIMIT_FSIZE] = {"Max file size", "bytes"}, |
| 597 | [RLIMIT_DATA] = {"Max data size", "bytes"}, |
| 598 | [RLIMIT_STACK] = {"Max stack size", "bytes"}, |
| 599 | [RLIMIT_CORE] = {"Max core file size", "bytes"}, |
| 600 | [RLIMIT_RSS] = {"Max resident set", "bytes"}, |
| 601 | [RLIMIT_NPROC] = {"Max processes", "processes"}, |
| 602 | [RLIMIT_NOFILE] = {"Max open files", "files"}, |
| 603 | [RLIMIT_MEMLOCK] = {"Max locked memory", "bytes"}, |
| 604 | [RLIMIT_AS] = {"Max address space", "bytes"}, |
| 605 | [RLIMIT_LOCKS] = {"Max file locks", "locks"}, |
| 606 | [RLIMIT_SIGPENDING] = {"Max pending signals", "signals"}, |
| 607 | [RLIMIT_MSGQUEUE] = {"Max msgqueue size", "bytes"}, |
| 608 | [RLIMIT_NICE] = {"Max nice priority", NULL}, |
| 609 | [RLIMIT_RTPRIO] = {"Max realtime priority", NULL}, |
Eugene Teo | 8808117 | 2008-02-23 15:23:52 -0800 | [diff] [blame] | 610 | [RLIMIT_RTTIME] = {"Max realtime timeout", "us"}, |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 611 | }; |
| 612 | |
| 613 | /* Display limits for a process */ |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 614 | static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns, |
| 615 | struct pid *pid, struct task_struct *task) |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 616 | { |
| 617 | unsigned int i; |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 618 | unsigned long flags; |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 619 | |
| 620 | struct rlimit rlim[RLIM_NLIMITS]; |
| 621 | |
Lai Jiangshan | a6bebbc | 2008-10-05 00:51:15 +0400 | [diff] [blame] | 622 | if (!lock_task_sighand(task, &flags)) |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 623 | return 0; |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 624 | memcpy(rlim, task->signal->rlim, sizeof(struct rlimit) * RLIM_NLIMITS); |
| 625 | unlock_task_sighand(task, &flags); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | * print the file header |
| 629 | */ |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 630 | seq_printf(m, "%-25s %-20s %-20s %-10s\n", |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 631 | "Limit", "Soft Limit", "Hard Limit", "Units"); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 632 | |
| 633 | for (i = 0; i < RLIM_NLIMITS; i++) { |
| 634 | if (rlim[i].rlim_cur == RLIM_INFINITY) |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 635 | seq_printf(m, "%-25s %-20s ", |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 636 | lnames[i].name, "unlimited"); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 637 | else |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 638 | seq_printf(m, "%-25s %-20lu ", |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 639 | lnames[i].name, rlim[i].rlim_cur); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 640 | |
| 641 | if (rlim[i].rlim_max == RLIM_INFINITY) |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 642 | seq_printf(m, "%-20s ", "unlimited"); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 643 | else |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 644 | seq_printf(m, "%-20lu ", rlim[i].rlim_max); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 645 | |
| 646 | if (lnames[i].unit) |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 647 | seq_printf(m, "%-10s\n", lnames[i].unit); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 648 | else |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 649 | seq_putc(m, '\n'); |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 652 | return 0; |
Neil Horman | d85f50d | 2007-10-18 23:40:37 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 655 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 656 | static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns, |
| 657 | struct pid *pid, struct task_struct *task) |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 658 | { |
| 659 | long nr; |
| 660 | unsigned long args[6], sp, pc; |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 661 | int res; |
| 662 | |
| 663 | res = lock_trace(task); |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 664 | if (res) |
| 665 | return res; |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 666 | |
| 667 | if (task_current_syscall(task, &nr, args, 6, &sp, &pc)) |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 668 | seq_puts(m, "running\n"); |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 669 | else if (nr < 0) |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 670 | seq_printf(m, "%ld 0x%lx 0x%lx\n", nr, sp, pc); |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 671 | else |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 672 | seq_printf(m, |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 673 | "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", |
| 674 | nr, |
| 675 | args[0], args[1], args[2], args[3], args[4], args[5], |
| 676 | sp, pc); |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 677 | unlock_trace(task); |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 678 | |
| 679 | return 0; |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 680 | } |
| 681 | #endif /* CONFIG_HAVE_ARCH_TRACEHOOK */ |
| 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | /************************************************************************/ |
| 684 | /* Here the fs part begins */ |
| 685 | /************************************************************************/ |
| 686 | |
| 687 | /* permission checks */ |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 688 | static int proc_fd_access_allowed(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 690 | struct task_struct *task; |
| 691 | int allowed = 0; |
Eric W. Biederman | df26c40 | 2006-06-26 00:25:59 -0700 | [diff] [blame] | 692 | /* Allow access to a task's file descriptors if it is us or we |
| 693 | * may use ptrace attach to the process and find out that |
| 694 | * information. |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 695 | */ |
| 696 | task = get_proc_task(inode); |
Eric W. Biederman | df26c40 | 2006-06-26 00:25:59 -0700 | [diff] [blame] | 697 | if (task) { |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 698 | allowed = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS); |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 699 | put_task_struct(task); |
Eric W. Biederman | df26c40 | 2006-06-26 00:25:59 -0700 | [diff] [blame] | 700 | } |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 701 | return allowed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 704 | int proc_setattr(struct dentry *dentry, struct iattr *attr) |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 705 | { |
| 706 | int error; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 707 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 708 | |
| 709 | if (attr->ia_valid & ATTR_MODE) |
| 710 | return -EPERM; |
| 711 | |
Jan Kara | 31051c8 | 2016-05-26 16:55:18 +0200 | [diff] [blame] | 712 | error = setattr_prepare(dentry, attr); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 713 | if (error) |
| 714 | return error; |
| 715 | |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 716 | setattr_copy(inode, attr); |
| 717 | mark_inode_dirty(inode); |
| 718 | return 0; |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 721 | /* |
| 722 | * May current process learn task's sched/cmdline info (for hide_pid_min=1) |
| 723 | * or euid/egid (for hide_pid_min=2)? |
| 724 | */ |
| 725 | static bool has_pid_permissions(struct pid_namespace *pid, |
| 726 | struct task_struct *task, |
| 727 | int hide_pid_min) |
| 728 | { |
| 729 | if (pid->hide_pid < hide_pid_min) |
| 730 | return true; |
| 731 | if (in_group_p(pid->pid_gid)) |
| 732 | return true; |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 733 | return ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS); |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | |
| 737 | static int proc_pid_permission(struct inode *inode, int mask) |
| 738 | { |
| 739 | struct pid_namespace *pid = inode->i_sb->s_fs_info; |
| 740 | struct task_struct *task; |
| 741 | bool has_perms; |
| 742 | |
| 743 | task = get_proc_task(inode); |
Xiaotian Feng | a2ef990 | 2012-01-12 17:17:08 -0800 | [diff] [blame] | 744 | if (!task) |
| 745 | return -ESRCH; |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 746 | has_perms = has_pid_permissions(pid, task, 1); |
| 747 | put_task_struct(task); |
| 748 | |
| 749 | if (!has_perms) { |
| 750 | if (pid->hide_pid == 2) { |
| 751 | /* |
| 752 | * Let's make getdents(), stat(), and open() |
| 753 | * consistent with each other. If a process |
| 754 | * may not stat() a file, it shouldn't be seen |
| 755 | * in procfs at all. |
| 756 | */ |
| 757 | return -ENOENT; |
| 758 | } |
| 759 | |
| 760 | return -EPERM; |
| 761 | } |
| 762 | return generic_permission(inode, mask); |
| 763 | } |
| 764 | |
| 765 | |
| 766 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 767 | static const struct inode_operations proc_def_inode_operations = { |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 768 | .setattr = proc_setattr, |
| 769 | }; |
| 770 | |
Eric W. Biederman | be61408 | 2008-02-08 04:18:30 -0800 | [diff] [blame] | 771 | static int proc_single_show(struct seq_file *m, void *v) |
| 772 | { |
| 773 | struct inode *inode = m->private; |
| 774 | struct pid_namespace *ns; |
| 775 | struct pid *pid; |
| 776 | struct task_struct *task; |
| 777 | int ret; |
| 778 | |
| 779 | ns = inode->i_sb->s_fs_info; |
| 780 | pid = proc_pid(inode); |
| 781 | task = get_pid_task(pid, PIDTYPE_PID); |
| 782 | if (!task) |
| 783 | return -ESRCH; |
| 784 | |
| 785 | ret = PROC_I(inode)->op.proc_show(m, ns, pid, task); |
| 786 | |
| 787 | put_task_struct(task); |
| 788 | return ret; |
| 789 | } |
| 790 | |
| 791 | static int proc_single_open(struct inode *inode, struct file *filp) |
| 792 | { |
Jovi Zhang | c6a3405 | 2011-01-12 17:00:34 -0800 | [diff] [blame] | 793 | return single_open(filp, proc_single_show, inode); |
Eric W. Biederman | be61408 | 2008-02-08 04:18:30 -0800 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | static const struct file_operations proc_single_file_operations = { |
| 797 | .open = proc_single_open, |
| 798 | .read = seq_read, |
| 799 | .llseek = seq_lseek, |
| 800 | .release = single_release, |
| 801 | }; |
| 802 | |
Oleg Nesterov | 5381e16 | 2014-10-09 15:25:24 -0700 | [diff] [blame] | 803 | |
| 804 | struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode) |
| 805 | { |
| 806 | struct task_struct *task = get_proc_task(inode); |
| 807 | struct mm_struct *mm = ERR_PTR(-ESRCH); |
| 808 | |
| 809 | if (task) { |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 810 | mm = mm_access(task, mode | PTRACE_MODE_FSCREDS); |
Oleg Nesterov | 5381e16 | 2014-10-09 15:25:24 -0700 | [diff] [blame] | 811 | put_task_struct(task); |
| 812 | |
| 813 | if (!IS_ERR_OR_NULL(mm)) { |
| 814 | /* ensure this mm_struct can't be freed */ |
| 815 | atomic_inc(&mm->mm_count); |
| 816 | /* but do not pin its memory */ |
| 817 | mmput(mm); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | return mm; |
| 822 | } |
| 823 | |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 824 | static int __mem_open(struct inode *inode, struct file *file, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { |
Oleg Nesterov | 5381e16 | 2014-10-09 15:25:24 -0700 | [diff] [blame] | 826 | struct mm_struct *mm = proc_mem_open(inode, mode); |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 827 | |
| 828 | if (IS_ERR(mm)) |
| 829 | return PTR_ERR(mm); |
| 830 | |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 831 | file->private_data = mm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 835 | static int mem_open(struct inode *inode, struct file *file) |
| 836 | { |
Djalal Harouni | bc452b4 | 2012-07-30 14:42:28 -0700 | [diff] [blame] | 837 | int ret = __mem_open(inode, file, PTRACE_MODE_ATTACH); |
| 838 | |
| 839 | /* OK to pass negative loff_t, we can catch out-of-range */ |
| 840 | file->f_mode |= FMODE_UNSIGNED_OFFSET; |
| 841 | |
| 842 | return ret; |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 845 | static ssize_t mem_rw(struct file *file, char __user *buf, |
| 846 | size_t count, loff_t *ppos, int write) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 848 | struct mm_struct *mm = file->private_data; |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 849 | unsigned long addr = *ppos; |
| 850 | ssize_t copied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | char *page; |
Linus Torvalds | 272ddc8 | 2016-10-24 19:00:44 -0700 | [diff] [blame] | 852 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 854 | if (!mm) |
| 855 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Mel Gorman | e12ba74 | 2007-10-16 01:25:52 -0700 | [diff] [blame] | 857 | page = (char *)__get_free_page(GFP_TEMPORARY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | if (!page) |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 859 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Frederik Deweerdt | f7ca54f | 2006-09-29 02:01:02 -0700 | [diff] [blame] | 861 | copied = 0; |
Oleg Nesterov | 6d08f2c | 2012-01-31 17:15:11 +0100 | [diff] [blame] | 862 | if (!atomic_inc_not_zero(&mm->mm_users)) |
| 863 | goto free; |
| 864 | |
Linus Torvalds | 272ddc8 | 2016-10-24 19:00:44 -0700 | [diff] [blame] | 865 | /* Maybe we should limit FOLL_FORCE to actual ptrace users? */ |
| 866 | flags = FOLL_FORCE; |
Lorenzo Stoakes | 6347e8d | 2016-10-13 01:20:19 +0100 | [diff] [blame] | 867 | if (write) |
| 868 | flags |= FOLL_WRITE; |
| 869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | while (count > 0) { |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 871 | int this_len = min_t(int, count, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 873 | if (write && copy_from_user(page, buf, this_len)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | copied = -EFAULT; |
| 875 | break; |
| 876 | } |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 877 | |
Lorenzo Stoakes | 6347e8d | 2016-10-13 01:20:19 +0100 | [diff] [blame] | 878 | this_len = access_remote_vm(mm, addr, page, this_len, flags); |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 879 | if (!this_len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | if (!copied) |
| 881 | copied = -EIO; |
| 882 | break; |
| 883 | } |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 884 | |
| 885 | if (!write && copy_to_user(buf, page, this_len)) { |
| 886 | copied = -EFAULT; |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | buf += this_len; |
| 891 | addr += this_len; |
| 892 | copied += this_len; |
| 893 | count -= this_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 895 | *ppos = addr; |
KOSAKI Motohiro | 30cd890 | 2011-05-26 16:25:52 -0700 | [diff] [blame] | 896 | |
Oleg Nesterov | 6d08f2c | 2012-01-31 17:15:11 +0100 | [diff] [blame] | 897 | mmput(mm); |
| 898 | free: |
KOSAKI Motohiro | 30cd890 | 2011-05-26 16:25:52 -0700 | [diff] [blame] | 899 | free_page((unsigned long) page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | return copied; |
| 901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Oleg Nesterov | 572d34b | 2012-01-31 17:14:54 +0100 | [diff] [blame] | 903 | static ssize_t mem_read(struct file *file, char __user *buf, |
| 904 | size_t count, loff_t *ppos) |
| 905 | { |
| 906 | return mem_rw(file, buf, count, ppos, 0); |
| 907 | } |
| 908 | |
| 909 | static ssize_t mem_write(struct file *file, const char __user *buf, |
| 910 | size_t count, loff_t *ppos) |
| 911 | { |
| 912 | return mem_rw(file, (char __user*)buf, count, ppos, 1); |
| 913 | } |
| 914 | |
Matt Mackall | 85863e4 | 2008-02-04 22:29:04 -0800 | [diff] [blame] | 915 | loff_t mem_lseek(struct file *file, loff_t offset, int orig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | { |
| 917 | switch (orig) { |
| 918 | case 0: |
| 919 | file->f_pos = offset; |
| 920 | break; |
| 921 | case 1: |
| 922 | file->f_pos += offset; |
| 923 | break; |
| 924 | default: |
| 925 | return -EINVAL; |
| 926 | } |
| 927 | force_successful_syscall_return(); |
| 928 | return file->f_pos; |
| 929 | } |
| 930 | |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 931 | static int mem_release(struct inode *inode, struct file *file) |
| 932 | { |
| 933 | struct mm_struct *mm = file->private_data; |
Oleg Nesterov | 71879d3 | 2012-01-31 17:14:38 +0100 | [diff] [blame] | 934 | if (mm) |
Oleg Nesterov | 6d08f2c | 2012-01-31 17:15:11 +0100 | [diff] [blame] | 935 | mmdrop(mm); |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 939 | static const struct file_operations proc_mem_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | .llseek = mem_lseek, |
| 941 | .read = mem_read, |
| 942 | .write = mem_write, |
| 943 | .open = mem_open, |
Linus Torvalds | e268337 | 2012-01-17 15:21:19 -0800 | [diff] [blame] | 944 | .release = mem_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | }; |
| 946 | |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 947 | static int environ_open(struct inode *inode, struct file *file) |
| 948 | { |
| 949 | return __mem_open(inode, file, PTRACE_MODE_READ); |
| 950 | } |
| 951 | |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 952 | static ssize_t environ_read(struct file *file, char __user *buf, |
| 953 | size_t count, loff_t *ppos) |
| 954 | { |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 955 | char *page; |
| 956 | unsigned long src = *ppos; |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 957 | int ret = 0; |
| 958 | struct mm_struct *mm = file->private_data; |
Mateusz Guzik | a3b609e | 2016-01-20 15:01:05 -0800 | [diff] [blame] | 959 | unsigned long env_start, env_end; |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 960 | |
Mathias Krause | 8148a73 | 2016-05-05 16:22:26 -0700 | [diff] [blame] | 961 | /* Ensure the process spawned far enough to have an environment. */ |
| 962 | if (!mm || !mm->env_end) |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 963 | return 0; |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 964 | |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 965 | page = (char *)__get_free_page(GFP_TEMPORARY); |
| 966 | if (!page) |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 967 | return -ENOMEM; |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 968 | |
Al Viro | d6f64b8 | 2011-02-15 22:26:01 -0500 | [diff] [blame] | 969 | ret = 0; |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 970 | if (!atomic_inc_not_zero(&mm->mm_users)) |
| 971 | goto free; |
Mateusz Guzik | a3b609e | 2016-01-20 15:01:05 -0800 | [diff] [blame] | 972 | |
| 973 | down_read(&mm->mmap_sem); |
| 974 | env_start = mm->env_start; |
| 975 | env_end = mm->env_end; |
| 976 | up_read(&mm->mmap_sem); |
| 977 | |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 978 | while (count > 0) { |
Djalal Harouni | e8905ec | 2012-07-30 14:42:26 -0700 | [diff] [blame] | 979 | size_t this_len, max_len; |
| 980 | int retval; |
| 981 | |
Mateusz Guzik | a3b609e | 2016-01-20 15:01:05 -0800 | [diff] [blame] | 982 | if (src >= (env_end - env_start)) |
Djalal Harouni | e8905ec | 2012-07-30 14:42:26 -0700 | [diff] [blame] | 983 | break; |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 984 | |
Mateusz Guzik | a3b609e | 2016-01-20 15:01:05 -0800 | [diff] [blame] | 985 | this_len = env_end - (env_start + src); |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 986 | |
Djalal Harouni | e8905ec | 2012-07-30 14:42:26 -0700 | [diff] [blame] | 987 | max_len = min_t(size_t, PAGE_SIZE, count); |
| 988 | this_len = min(max_len, this_len); |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 989 | |
Willy Tarreau | 6f1abf8 | 2018-05-11 08:11:44 +0200 | [diff] [blame] | 990 | retval = access_remote_vm(mm, (env_start + src), page, this_len, FOLL_ANON); |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 991 | |
| 992 | if (retval <= 0) { |
| 993 | ret = retval; |
| 994 | break; |
| 995 | } |
| 996 | |
| 997 | if (copy_to_user(buf, page, retval)) { |
| 998 | ret = -EFAULT; |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | ret += retval; |
| 1003 | src += retval; |
| 1004 | buf += retval; |
| 1005 | count -= retval; |
| 1006 | } |
| 1007 | *ppos = src; |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 1008 | mmput(mm); |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 1009 | |
| 1010 | free: |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 1011 | free_page((unsigned long) page); |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 1012 | return ret; |
| 1013 | } |
| 1014 | |
| 1015 | static const struct file_operations proc_environ_operations = { |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 1016 | .open = environ_open, |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 1017 | .read = environ_read, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 1018 | .llseek = generic_file_llseek, |
Cong Wang | b409e57 | 2012-05-31 16:26:17 -0700 | [diff] [blame] | 1019 | .release = mem_release, |
James Pearson | 315e28c | 2007-10-16 23:30:17 -0700 | [diff] [blame] | 1020 | }; |
| 1021 | |
Al Viro | c531716 | 2016-10-05 18:43:43 -0400 | [diff] [blame] | 1022 | static int auxv_open(struct inode *inode, struct file *file) |
| 1023 | { |
| 1024 | return __mem_open(inode, file, PTRACE_MODE_READ_FSCREDS); |
| 1025 | } |
| 1026 | |
| 1027 | static ssize_t auxv_read(struct file *file, char __user *buf, |
| 1028 | size_t count, loff_t *ppos) |
| 1029 | { |
| 1030 | struct mm_struct *mm = file->private_data; |
| 1031 | unsigned int nwords = 0; |
Leon Yu | 06b2849 | 2016-10-27 17:46:50 -0700 | [diff] [blame] | 1032 | |
| 1033 | if (!mm) |
| 1034 | return 0; |
Al Viro | c531716 | 2016-10-05 18:43:43 -0400 | [diff] [blame] | 1035 | do { |
| 1036 | nwords += 2; |
| 1037 | } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */ |
| 1038 | return simple_read_from_buffer(buf, count, ppos, mm->saved_auxv, |
| 1039 | nwords * sizeof(mm->saved_auxv[0])); |
| 1040 | } |
| 1041 | |
| 1042 | static const struct file_operations proc_auxv_operations = { |
| 1043 | .open = auxv_open, |
| 1044 | .read = auxv_read, |
| 1045 | .llseek = generic_file_llseek, |
| 1046 | .release = mem_release, |
| 1047 | }; |
| 1048 | |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1049 | static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count, |
| 1050 | loff_t *ppos) |
| 1051 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1052 | struct task_struct *task = get_proc_task(file_inode(file)); |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1053 | char buffer[PROC_NUMBUF]; |
| 1054 | int oom_adj = OOM_ADJUST_MIN; |
| 1055 | size_t len; |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1056 | |
| 1057 | if (!task) |
| 1058 | return -ESRCH; |
Michal Hocko | f913da5 | 2016-07-28 15:44:37 -0700 | [diff] [blame] | 1059 | if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX) |
| 1060 | oom_adj = OOM_ADJUST_MAX; |
| 1061 | else |
| 1062 | oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) / |
| 1063 | OOM_SCORE_ADJ_MAX; |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1064 | put_task_struct(task); |
| 1065 | len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj); |
| 1066 | return simple_read_from_buffer(buf, count, ppos, buffer, len); |
| 1067 | } |
| 1068 | |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1069 | static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) |
| 1070 | { |
| 1071 | static DEFINE_MUTEX(oom_adj_mutex); |
Michal Hocko | 44a70ade | 2016-07-28 15:44:43 -0700 | [diff] [blame] | 1072 | struct mm_struct *mm = NULL; |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1073 | struct task_struct *task; |
| 1074 | int err = 0; |
| 1075 | |
| 1076 | task = get_proc_task(file_inode(file)); |
| 1077 | if (!task) |
| 1078 | return -ESRCH; |
| 1079 | |
| 1080 | mutex_lock(&oom_adj_mutex); |
| 1081 | if (legacy) { |
| 1082 | if (oom_adj < task->signal->oom_score_adj && |
| 1083 | !capable(CAP_SYS_RESOURCE)) { |
| 1084 | err = -EACCES; |
| 1085 | goto err_unlock; |
| 1086 | } |
| 1087 | /* |
| 1088 | * /proc/pid/oom_adj is provided for legacy purposes, ask users to use |
| 1089 | * /proc/pid/oom_score_adj instead. |
| 1090 | */ |
| 1091 | pr_warn_once("%s (%d): /proc/%d/oom_adj is deprecated, please use /proc/%d/oom_score_adj instead.\n", |
| 1092 | current->comm, task_pid_nr(current), task_pid_nr(task), |
| 1093 | task_pid_nr(task)); |
| 1094 | } else { |
| 1095 | if ((short)oom_adj < task->signal->oom_score_adj_min && |
| 1096 | !capable(CAP_SYS_RESOURCE)) { |
| 1097 | err = -EACCES; |
| 1098 | goto err_unlock; |
| 1099 | } |
| 1100 | } |
| 1101 | |
Michal Hocko | 44a70ade | 2016-07-28 15:44:43 -0700 | [diff] [blame] | 1102 | /* |
| 1103 | * Make sure we will check other processes sharing the mm if this is |
| 1104 | * not vfrok which wants its own oom_score_adj. |
| 1105 | * pin the mm so it doesn't go away and get reused after task_unlock |
| 1106 | */ |
| 1107 | if (!task->vfork_done) { |
| 1108 | struct task_struct *p = find_lock_task_mm(task); |
| 1109 | |
| 1110 | if (p) { |
| 1111 | if (atomic_read(&p->mm->mm_users) > 1) { |
| 1112 | mm = p->mm; |
| 1113 | atomic_inc(&mm->mm_count); |
| 1114 | } |
| 1115 | task_unlock(p); |
| 1116 | } |
| 1117 | } |
| 1118 | |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1119 | task->signal->oom_score_adj = oom_adj; |
| 1120 | if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) |
| 1121 | task->signal->oom_score_adj_min = (short)oom_adj; |
| 1122 | trace_oom_score_adj_update(task); |
Michal Hocko | 44a70ade | 2016-07-28 15:44:43 -0700 | [diff] [blame] | 1123 | |
| 1124 | if (mm) { |
| 1125 | struct task_struct *p; |
| 1126 | |
| 1127 | rcu_read_lock(); |
| 1128 | for_each_process(p) { |
| 1129 | if (same_thread_group(task, p)) |
| 1130 | continue; |
| 1131 | |
| 1132 | /* do not touch kernel threads or the global init */ |
| 1133 | if (p->flags & PF_KTHREAD || is_global_init(p)) |
| 1134 | continue; |
| 1135 | |
| 1136 | task_lock(p); |
| 1137 | if (!p->vfork_done && process_shares_mm(p, mm)) { |
Michal Hocko | 44a70ade | 2016-07-28 15:44:43 -0700 | [diff] [blame] | 1138 | p->signal->oom_score_adj = oom_adj; |
| 1139 | if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) |
| 1140 | p->signal->oom_score_adj_min = (short)oom_adj; |
| 1141 | } |
| 1142 | task_unlock(p); |
| 1143 | } |
| 1144 | rcu_read_unlock(); |
| 1145 | mmdrop(mm); |
| 1146 | } |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1147 | err_unlock: |
| 1148 | mutex_unlock(&oom_adj_mutex); |
| 1149 | put_task_struct(task); |
| 1150 | return err; |
| 1151 | } |
Michal Hocko | f913da5 | 2016-07-28 15:44:37 -0700 | [diff] [blame] | 1152 | |
David Rientjes | b72bdfa | 2015-11-05 18:50:32 -0800 | [diff] [blame] | 1153 | /* |
| 1154 | * /proc/pid/oom_adj exists solely for backwards compatibility with previous |
| 1155 | * kernels. The effective policy is defined by oom_score_adj, which has a |
| 1156 | * different scale: oom_adj grew exponentially and oom_score_adj grows linearly. |
| 1157 | * Values written to oom_adj are simply mapped linearly to oom_score_adj. |
| 1158 | * Processes that become oom disabled via oom_adj will still be oom disabled |
| 1159 | * with this implementation. |
| 1160 | * |
| 1161 | * oom_adj cannot be removed since existing userspace binaries use it. |
| 1162 | */ |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1163 | static ssize_t oom_adj_write(struct file *file, const char __user *buf, |
| 1164 | size_t count, loff_t *ppos) |
| 1165 | { |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1166 | char buffer[PROC_NUMBUF]; |
| 1167 | int oom_adj; |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1168 | int err; |
| 1169 | |
| 1170 | memset(buffer, 0, sizeof(buffer)); |
| 1171 | if (count > sizeof(buffer) - 1) |
| 1172 | count = sizeof(buffer) - 1; |
| 1173 | if (copy_from_user(buffer, buf, count)) { |
| 1174 | err = -EFAULT; |
| 1175 | goto out; |
| 1176 | } |
| 1177 | |
| 1178 | err = kstrtoint(strstrip(buffer), 0, &oom_adj); |
| 1179 | if (err) |
| 1180 | goto out; |
| 1181 | if ((oom_adj < OOM_ADJUST_MIN || oom_adj > OOM_ADJUST_MAX) && |
| 1182 | oom_adj != OOM_DISABLE) { |
| 1183 | err = -EINVAL; |
| 1184 | goto out; |
| 1185 | } |
| 1186 | |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1187 | /* |
| 1188 | * Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum |
| 1189 | * value is always attainable. |
| 1190 | */ |
| 1191 | if (oom_adj == OOM_ADJUST_MAX) |
| 1192 | oom_adj = OOM_SCORE_ADJ_MAX; |
| 1193 | else |
| 1194 | oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE; |
| 1195 | |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1196 | err = __set_oom_adj(file, oom_adj, true); |
David Rientjes | fa0cbbf | 2012-11-12 17:53:04 -0800 | [diff] [blame] | 1197 | out: |
| 1198 | return err < 0 ? err : count; |
| 1199 | } |
| 1200 | |
| 1201 | static const struct file_operations proc_oom_adj_operations = { |
| 1202 | .read = oom_adj_read, |
| 1203 | .write = oom_adj_write, |
| 1204 | .llseek = generic_file_llseek, |
| 1205 | }; |
| 1206 | |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1207 | static ssize_t oom_score_adj_read(struct file *file, char __user *buf, |
| 1208 | size_t count, loff_t *ppos) |
| 1209 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1210 | struct task_struct *task = get_proc_task(file_inode(file)); |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1211 | char buffer[PROC_NUMBUF]; |
David Rientjes | a9c58b90 | 2012-12-11 16:02:54 -0800 | [diff] [blame] | 1212 | short oom_score_adj = OOM_SCORE_ADJ_MIN; |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1213 | size_t len; |
| 1214 | |
| 1215 | if (!task) |
| 1216 | return -ESRCH; |
Michal Hocko | f913da5 | 2016-07-28 15:44:37 -0700 | [diff] [blame] | 1217 | oom_score_adj = task->signal->oom_score_adj; |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1218 | put_task_struct(task); |
David Rientjes | a9c58b90 | 2012-12-11 16:02:54 -0800 | [diff] [blame] | 1219 | len = snprintf(buffer, sizeof(buffer), "%hd\n", oom_score_adj); |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1220 | return simple_read_from_buffer(buf, count, ppos, buffer, len); |
| 1221 | } |
| 1222 | |
| 1223 | static ssize_t oom_score_adj_write(struct file *file, const char __user *buf, |
| 1224 | size_t count, loff_t *ppos) |
| 1225 | { |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1226 | char buffer[PROC_NUMBUF]; |
Alexey Dobriyan | 0a8cb8e | 2011-05-26 16:25:50 -0700 | [diff] [blame] | 1227 | int oom_score_adj; |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1228 | int err; |
| 1229 | |
| 1230 | memset(buffer, 0, sizeof(buffer)); |
| 1231 | if (count > sizeof(buffer) - 1) |
| 1232 | count = sizeof(buffer) - 1; |
David Rientjes | 723548b | 2010-10-26 14:21:25 -0700 | [diff] [blame] | 1233 | if (copy_from_user(buffer, buf, count)) { |
| 1234 | err = -EFAULT; |
| 1235 | goto out; |
| 1236 | } |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1237 | |
Alexey Dobriyan | 0a8cb8e | 2011-05-26 16:25:50 -0700 | [diff] [blame] | 1238 | err = kstrtoint(strstrip(buffer), 0, &oom_score_adj); |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1239 | if (err) |
David Rientjes | 723548b | 2010-10-26 14:21:25 -0700 | [diff] [blame] | 1240 | goto out; |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1241 | if (oom_score_adj < OOM_SCORE_ADJ_MIN || |
David Rientjes | 723548b | 2010-10-26 14:21:25 -0700 | [diff] [blame] | 1242 | oom_score_adj > OOM_SCORE_ADJ_MAX) { |
| 1243 | err = -EINVAL; |
| 1244 | goto out; |
| 1245 | } |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1246 | |
Michal Hocko | 1d5f0ac | 2016-07-28 15:44:40 -0700 | [diff] [blame] | 1247 | err = __set_oom_adj(file, oom_score_adj, false); |
David Rientjes | 723548b | 2010-10-26 14:21:25 -0700 | [diff] [blame] | 1248 | out: |
| 1249 | return err < 0 ? err : count; |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static const struct file_operations proc_oom_score_adj_operations = { |
| 1253 | .read = oom_score_adj_read, |
| 1254 | .write = oom_score_adj_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1255 | .llseek = default_llseek, |
David Rientjes | a63d83f | 2010-08-09 17:19:46 -0700 | [diff] [blame] | 1256 | }; |
| 1257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | #ifdef CONFIG_AUDITSYSCALL |
| 1259 | #define TMPBUFLEN 21 |
| 1260 | static ssize_t proc_loginuid_read(struct file * file, char __user * buf, |
| 1261 | size_t count, loff_t *ppos) |
| 1262 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1263 | struct inode * inode = file_inode(file); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 1264 | struct task_struct *task = get_proc_task(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | ssize_t length; |
| 1266 | char tmpbuf[TMPBUFLEN]; |
| 1267 | |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 1268 | if (!task) |
| 1269 | return -ESRCH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", |
Eric W. Biederman | e1760bd | 2012-09-10 22:39:43 -0700 | [diff] [blame] | 1271 | from_kuid(file->f_cred->user_ns, |
| 1272 | audit_get_loginuid(task))); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 1273 | put_task_struct(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); |
| 1275 | } |
| 1276 | |
| 1277 | static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, |
| 1278 | size_t count, loff_t *ppos) |
| 1279 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1280 | struct inode * inode = file_inode(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | uid_t loginuid; |
Eric W. Biederman | e1760bd | 2012-09-10 22:39:43 -0700 | [diff] [blame] | 1282 | kuid_t kloginuid; |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1283 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Paul E. McKenney | 7dc5215 | 2010-02-22 17:04:52 -0800 | [diff] [blame] | 1285 | rcu_read_lock(); |
| 1286 | if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) { |
| 1287 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | return -EPERM; |
Paul E. McKenney | 7dc5215 | 2010-02-22 17:04:52 -0800 | [diff] [blame] | 1289 | } |
| 1290 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | if (*ppos != 0) { |
| 1293 | /* No partial writes. */ |
| 1294 | return -EINVAL; |
| 1295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1297 | rv = kstrtou32_from_user(buf, count, 10, &loginuid); |
| 1298 | if (rv < 0) |
| 1299 | return rv; |
Eric Paris | 81407c8 | 2013-05-24 09:49:14 -0400 | [diff] [blame] | 1300 | |
| 1301 | /* is userspace tring to explicitly UNSET the loginuid? */ |
| 1302 | if (loginuid == AUDIT_UID_UNSET) { |
| 1303 | kloginuid = INVALID_UID; |
| 1304 | } else { |
| 1305 | kloginuid = make_kuid(file->f_cred->user_ns, loginuid); |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1306 | if (!uid_valid(kloginuid)) |
| 1307 | return -EINVAL; |
Eric W. Biederman | e1760bd | 2012-09-10 22:39:43 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1310 | rv = audit_set_loginuid(kloginuid); |
| 1311 | if (rv < 0) |
| 1312 | return rv; |
| 1313 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1316 | static const struct file_operations proc_loginuid_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | .read = proc_loginuid_read, |
| 1318 | .write = proc_loginuid_write, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 1319 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | }; |
Eric Paris | 1e0bd75 | 2008-03-13 08:15:31 -0400 | [diff] [blame] | 1321 | |
| 1322 | static ssize_t proc_sessionid_read(struct file * file, char __user * buf, |
| 1323 | size_t count, loff_t *ppos) |
| 1324 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1325 | struct inode * inode = file_inode(file); |
Eric Paris | 1e0bd75 | 2008-03-13 08:15:31 -0400 | [diff] [blame] | 1326 | struct task_struct *task = get_proc_task(inode); |
| 1327 | ssize_t length; |
| 1328 | char tmpbuf[TMPBUFLEN]; |
| 1329 | |
| 1330 | if (!task) |
| 1331 | return -ESRCH; |
| 1332 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", |
| 1333 | audit_get_sessionid(task)); |
| 1334 | put_task_struct(task); |
| 1335 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); |
| 1336 | } |
| 1337 | |
| 1338 | static const struct file_operations proc_sessionid_operations = { |
| 1339 | .read = proc_sessionid_read, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 1340 | .llseek = generic_file_llseek, |
Eric Paris | 1e0bd75 | 2008-03-13 08:15:31 -0400 | [diff] [blame] | 1341 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | #endif |
| 1343 | |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1344 | #ifdef CONFIG_FAULT_INJECTION |
| 1345 | static ssize_t proc_fault_inject_read(struct file * file, char __user * buf, |
| 1346 | size_t count, loff_t *ppos) |
| 1347 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1348 | struct task_struct *task = get_proc_task(file_inode(file)); |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1349 | char buffer[PROC_NUMBUF]; |
| 1350 | size_t len; |
| 1351 | int make_it_fail; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1352 | |
| 1353 | if (!task) |
| 1354 | return -ESRCH; |
| 1355 | make_it_fail = task->make_it_fail; |
| 1356 | put_task_struct(task); |
| 1357 | |
| 1358 | len = snprintf(buffer, sizeof(buffer), "%i\n", make_it_fail); |
Akinobu Mita | 0c28f28 | 2007-05-08 00:31:41 -0700 | [diff] [blame] | 1359 | |
| 1360 | return simple_read_from_buffer(buf, count, ppos, buffer, len); |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static ssize_t proc_fault_inject_write(struct file * file, |
| 1364 | const char __user * buf, size_t count, loff_t *ppos) |
| 1365 | { |
| 1366 | struct task_struct *task; |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1367 | char buffer[PROC_NUMBUF]; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1368 | int make_it_fail; |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1369 | int rv; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1370 | |
| 1371 | if (!capable(CAP_SYS_RESOURCE)) |
| 1372 | return -EPERM; |
| 1373 | memset(buffer, 0, sizeof(buffer)); |
| 1374 | if (count > sizeof(buffer) - 1) |
| 1375 | count = sizeof(buffer) - 1; |
| 1376 | if (copy_from_user(buffer, buf, count)) |
| 1377 | return -EFAULT; |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 1378 | rv = kstrtoint(strstrip(buffer), 0, &make_it_fail); |
| 1379 | if (rv < 0) |
| 1380 | return rv; |
Dave Jones | 16caed3 | 2014-04-07 15:39:15 -0700 | [diff] [blame] | 1381 | if (make_it_fail < 0 || make_it_fail > 1) |
| 1382 | return -EINVAL; |
| 1383 | |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1384 | task = get_proc_task(file_inode(file)); |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1385 | if (!task) |
| 1386 | return -ESRCH; |
| 1387 | task->make_it_fail = make_it_fail; |
| 1388 | put_task_struct(task); |
Vincent Li | cba8aaf | 2009-09-22 16:45:38 -0700 | [diff] [blame] | 1389 | |
| 1390 | return count; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1393 | static const struct file_operations proc_fault_inject_operations = { |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1394 | .read = proc_fault_inject_read, |
| 1395 | .write = proc_fault_inject_write, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 1396 | .llseek = generic_file_llseek, |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 1397 | }; |
| 1398 | #endif |
| 1399 | |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 1400 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1401 | #ifdef CONFIG_SCHED_DEBUG |
| 1402 | /* |
| 1403 | * Print out various scheduling related per-task fields: |
| 1404 | */ |
| 1405 | static int sched_show(struct seq_file *m, void *v) |
| 1406 | { |
| 1407 | struct inode *inode = m->private; |
| 1408 | struct task_struct *p; |
| 1409 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1410 | p = get_proc_task(inode); |
| 1411 | if (!p) |
| 1412 | return -ESRCH; |
| 1413 | proc_sched_show_task(p, m); |
| 1414 | |
| 1415 | put_task_struct(p); |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | static ssize_t |
| 1421 | sched_write(struct file *file, const char __user *buf, |
| 1422 | size_t count, loff_t *offset) |
| 1423 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1424 | struct inode *inode = file_inode(file); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1425 | struct task_struct *p; |
| 1426 | |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1427 | p = get_proc_task(inode); |
| 1428 | if (!p) |
| 1429 | return -ESRCH; |
| 1430 | proc_sched_set_task(p); |
| 1431 | |
| 1432 | put_task_struct(p); |
| 1433 | |
| 1434 | return count; |
| 1435 | } |
| 1436 | |
| 1437 | static int sched_open(struct inode *inode, struct file *filp) |
| 1438 | { |
Jovi Zhang | c6a3405 | 2011-01-12 17:00:34 -0800 | [diff] [blame] | 1439 | return single_open(filp, sched_show, inode); |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | static const struct file_operations proc_pid_sched_operations = { |
| 1443 | .open = sched_open, |
| 1444 | .read = seq_read, |
| 1445 | .write = sched_write, |
| 1446 | .llseek = seq_lseek, |
Alexey Dobriyan | 5ea473a | 2007-07-31 00:38:50 -0700 | [diff] [blame] | 1447 | .release = single_release, |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 1448 | }; |
| 1449 | |
| 1450 | #endif |
| 1451 | |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1452 | #ifdef CONFIG_SCHED_AUTOGROUP |
| 1453 | /* |
| 1454 | * Print out autogroup related information: |
| 1455 | */ |
| 1456 | static int sched_autogroup_show(struct seq_file *m, void *v) |
| 1457 | { |
| 1458 | struct inode *inode = m->private; |
| 1459 | struct task_struct *p; |
| 1460 | |
| 1461 | p = get_proc_task(inode); |
| 1462 | if (!p) |
| 1463 | return -ESRCH; |
| 1464 | proc_sched_autogroup_show_task(p, m); |
| 1465 | |
| 1466 | put_task_struct(p); |
| 1467 | |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | static ssize_t |
| 1472 | sched_autogroup_write(struct file *file, const char __user *buf, |
| 1473 | size_t count, loff_t *offset) |
| 1474 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1475 | struct inode *inode = file_inode(file); |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1476 | struct task_struct *p; |
| 1477 | char buffer[PROC_NUMBUF]; |
Alexey Dobriyan | 0a8cb8e | 2011-05-26 16:25:50 -0700 | [diff] [blame] | 1478 | int nice; |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1479 | int err; |
| 1480 | |
| 1481 | memset(buffer, 0, sizeof(buffer)); |
| 1482 | if (count > sizeof(buffer) - 1) |
| 1483 | count = sizeof(buffer) - 1; |
| 1484 | if (copy_from_user(buffer, buf, count)) |
| 1485 | return -EFAULT; |
| 1486 | |
Alexey Dobriyan | 0a8cb8e | 2011-05-26 16:25:50 -0700 | [diff] [blame] | 1487 | err = kstrtoint(strstrip(buffer), 0, &nice); |
| 1488 | if (err < 0) |
| 1489 | return err; |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1490 | |
| 1491 | p = get_proc_task(inode); |
| 1492 | if (!p) |
| 1493 | return -ESRCH; |
| 1494 | |
Hiroshi Shimamoto | 2e5b5b3 | 2012-02-23 17:41:27 +0900 | [diff] [blame] | 1495 | err = proc_sched_autogroup_set_nice(p, nice); |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 1496 | if (err) |
| 1497 | count = err; |
| 1498 | |
| 1499 | put_task_struct(p); |
| 1500 | |
| 1501 | return count; |
| 1502 | } |
| 1503 | |
| 1504 | static int sched_autogroup_open(struct inode *inode, struct file *filp) |
| 1505 | { |
| 1506 | int ret; |
| 1507 | |
| 1508 | ret = single_open(filp, sched_autogroup_show, NULL); |
| 1509 | if (!ret) { |
| 1510 | struct seq_file *m = filp->private_data; |
| 1511 | |
| 1512 | m->private = inode; |
| 1513 | } |
| 1514 | return ret; |
| 1515 | } |
| 1516 | |
| 1517 | static const struct file_operations proc_pid_sched_autogroup_operations = { |
| 1518 | .open = sched_autogroup_open, |
| 1519 | .read = seq_read, |
| 1520 | .write = sched_autogroup_write, |
| 1521 | .llseek = seq_lseek, |
| 1522 | .release = single_release, |
| 1523 | }; |
| 1524 | |
| 1525 | #endif /* CONFIG_SCHED_AUTOGROUP */ |
| 1526 | |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 1527 | static ssize_t comm_write(struct file *file, const char __user *buf, |
| 1528 | size_t count, loff_t *offset) |
| 1529 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1530 | struct inode *inode = file_inode(file); |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 1531 | struct task_struct *p; |
| 1532 | char buffer[TASK_COMM_LEN]; |
David Rientjes | 830e0fc | 2013-04-30 15:28:18 -0700 | [diff] [blame] | 1533 | const size_t maxlen = sizeof(buffer) - 1; |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 1534 | |
| 1535 | memset(buffer, 0, sizeof(buffer)); |
David Rientjes | 830e0fc | 2013-04-30 15:28:18 -0700 | [diff] [blame] | 1536 | if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count)) |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 1537 | return -EFAULT; |
| 1538 | |
| 1539 | p = get_proc_task(inode); |
| 1540 | if (!p) |
| 1541 | return -ESRCH; |
| 1542 | |
| 1543 | if (same_thread_group(current, p)) |
| 1544 | set_task_comm(p, buffer); |
| 1545 | else |
| 1546 | count = -EINVAL; |
| 1547 | |
| 1548 | put_task_struct(p); |
| 1549 | |
| 1550 | return count; |
| 1551 | } |
| 1552 | |
| 1553 | static int comm_show(struct seq_file *m, void *v) |
| 1554 | { |
| 1555 | struct inode *inode = m->private; |
| 1556 | struct task_struct *p; |
| 1557 | |
| 1558 | p = get_proc_task(inode); |
| 1559 | if (!p) |
| 1560 | return -ESRCH; |
| 1561 | |
| 1562 | task_lock(p); |
| 1563 | seq_printf(m, "%s\n", p->comm); |
| 1564 | task_unlock(p); |
| 1565 | |
| 1566 | put_task_struct(p); |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | static int comm_open(struct inode *inode, struct file *filp) |
| 1572 | { |
Jovi Zhang | c6a3405 | 2011-01-12 17:00:34 -0800 | [diff] [blame] | 1573 | return single_open(filp, comm_show, inode); |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | static const struct file_operations proc_pid_set_comm_operations = { |
| 1577 | .open = comm_open, |
| 1578 | .read = seq_read, |
| 1579 | .write = comm_write, |
| 1580 | .llseek = seq_lseek, |
| 1581 | .release = single_release, |
| 1582 | }; |
| 1583 | |
Cyrill Gorcunov | 7773fbc | 2012-01-10 15:11:20 -0800 | [diff] [blame] | 1584 | static int proc_exe_link(struct dentry *dentry, struct path *exe_path) |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 1585 | { |
| 1586 | struct task_struct *task; |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 1587 | struct file *exe_file; |
| 1588 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1589 | task = get_proc_task(d_inode(dentry)); |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 1590 | if (!task) |
| 1591 | return -ENOENT; |
Mateusz Guzik | cd81a91 | 2016-08-23 16:20:38 +0200 | [diff] [blame] | 1592 | exe_file = get_task_exe_file(task); |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 1593 | put_task_struct(task); |
Matt Helsley | 925d1c4 | 2008-04-29 01:01:36 -0700 | [diff] [blame] | 1594 | if (exe_file) { |
| 1595 | *exe_path = exe_file->f_path; |
| 1596 | path_get(&exe_file->f_path); |
| 1597 | fput(exe_file); |
| 1598 | return 0; |
| 1599 | } else |
| 1600 | return -ENOENT; |
| 1601 | } |
| 1602 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1603 | static const char *proc_pid_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 1604 | struct inode *inode, |
| 1605 | struct delayed_call *done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
Christoph Hellwig | 408ef01 | 2012-06-18 10:47:03 -0400 | [diff] [blame] | 1607 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | int error = -EACCES; |
| 1609 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1610 | if (!dentry) |
| 1611 | return ERR_PTR(-ECHILD); |
| 1612 | |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 1613 | /* Are we allowed to snoop on the tasks file descriptors? */ |
| 1614 | if (!proc_fd_access_allowed(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Christoph Hellwig | 408ef01 | 2012-06-18 10:47:03 -0400 | [diff] [blame] | 1617 | error = PROC_I(inode)->op.proc_get_link(dentry, &path); |
| 1618 | if (error) |
| 1619 | goto out; |
| 1620 | |
Al Viro | 6e77137 | 2015-05-02 13:37:52 -0400 | [diff] [blame] | 1621 | nd_jump_link(&path); |
Christoph Hellwig | 408ef01 | 2012-06-18 10:47:03 -0400 | [diff] [blame] | 1622 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | out: |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 1624 | return ERR_PTR(error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1627 | static int do_proc_readlink(struct path *path, char __user *buffer, int buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
Mel Gorman | e12ba74 | 2007-10-16 01:25:52 -0700 | [diff] [blame] | 1629 | char *tmp = (char*)__get_free_page(GFP_TEMPORARY); |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1630 | char *pathname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | int len; |
| 1632 | |
| 1633 | if (!tmp) |
| 1634 | return -ENOMEM; |
Akinobu Mita | 0c28f28 | 2007-05-08 00:31:41 -0700 | [diff] [blame] | 1635 | |
Eric W. Biederman | 7b2a69b | 2010-12-05 15:51:21 -0800 | [diff] [blame] | 1636 | pathname = d_path(path, tmp, PAGE_SIZE); |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1637 | len = PTR_ERR(pathname); |
| 1638 | if (IS_ERR(pathname)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | goto out; |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1640 | len = tmp + PAGE_SIZE - 1 - pathname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
| 1642 | if (len > buflen) |
| 1643 | len = buflen; |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1644 | if (copy_to_user(buffer, pathname, len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | len = -EFAULT; |
| 1646 | out: |
| 1647 | free_page((unsigned long)tmp); |
| 1648 | return len; |
| 1649 | } |
| 1650 | |
| 1651 | static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen) |
| 1652 | { |
| 1653 | int error = -EACCES; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1654 | struct inode *inode = d_inode(dentry); |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1655 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
Eric W. Biederman | 778c114 | 2006-06-26 00:25:58 -0700 | [diff] [blame] | 1657 | /* Are we allowed to snoop on the tasks file descriptors? */ |
| 1658 | if (!proc_fd_access_allowed(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Cyrill Gorcunov | 7773fbc | 2012-01-10 15:11:20 -0800 | [diff] [blame] | 1661 | error = PROC_I(inode)->op.proc_get_link(dentry, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | if (error) |
| 1663 | goto out; |
| 1664 | |
Jan Blunck | 3dcd25f | 2008-02-14 19:38:35 -0800 | [diff] [blame] | 1665 | error = do_proc_readlink(&path, buffer, buflen); |
| 1666 | path_put(&path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | return error; |
| 1669 | } |
| 1670 | |
Cyrill Gorcunov | faf60af | 2012-08-23 14:43:24 +0400 | [diff] [blame] | 1671 | const struct inode_operations proc_pid_link_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | .readlink = proc_pid_readlink, |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1673 | .get_link = proc_pid_get_link, |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 1674 | .setattr = proc_setattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | }; |
| 1676 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1677 | |
| 1678 | /* building an inode */ |
| 1679 | |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 1680 | struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1681 | { |
| 1682 | struct inode * inode; |
| 1683 | struct proc_inode *ei; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1684 | const struct cred *cred; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1685 | |
| 1686 | /* We need a new inode */ |
| 1687 | |
| 1688 | inode = new_inode(sb); |
| 1689 | if (!inode) |
| 1690 | goto out; |
| 1691 | |
| 1692 | /* Common stuff */ |
| 1693 | ei = PROC_I(inode); |
Christoph Hellwig | 85fe402 | 2010-10-23 11:19:54 -0400 | [diff] [blame] | 1694 | inode->i_ino = get_next_ino(); |
Deepa Dinamani | 078cd82 | 2016-09-14 07:48:04 -0700 | [diff] [blame] | 1695 | inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1696 | inode->i_op = &proc_def_inode_operations; |
| 1697 | |
| 1698 | /* |
| 1699 | * grab the reference to task. |
| 1700 | */ |
Oleg Nesterov | 1a657f78 | 2006-10-02 02:18:59 -0700 | [diff] [blame] | 1701 | ei->pid = get_task_pid(task, PIDTYPE_PID); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1702 | if (!ei->pid) |
| 1703 | goto out_unlock; |
| 1704 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1705 | if (task_dumpable(task)) { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1706 | rcu_read_lock(); |
| 1707 | cred = __task_cred(task); |
| 1708 | inode->i_uid = cred->euid; |
| 1709 | inode->i_gid = cred->egid; |
| 1710 | rcu_read_unlock(); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1711 | } |
| 1712 | security_task_to_inode(task, inode); |
| 1713 | |
| 1714 | out: |
| 1715 | return inode; |
| 1716 | |
| 1717 | out_unlock: |
| 1718 | iput(inode); |
| 1719 | return NULL; |
| 1720 | } |
| 1721 | |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 1722 | int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1723 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1724 | struct inode *inode = d_inode(dentry); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1725 | struct task_struct *task; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1726 | const struct cred *cred; |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 1727 | struct pid_namespace *pid = dentry->d_sb->s_fs_info; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1728 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1729 | generic_fillattr(inode, stat); |
| 1730 | |
| 1731 | rcu_read_lock(); |
Eric W. Biederman | dcb0f22 | 2012-02-09 08:48:21 -0800 | [diff] [blame] | 1732 | stat->uid = GLOBAL_ROOT_UID; |
| 1733 | stat->gid = GLOBAL_ROOT_GID; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1734 | task = pid_task(proc_pid(inode), PIDTYPE_PID); |
| 1735 | if (task) { |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 1736 | if (!has_pid_permissions(pid, task, 2)) { |
| 1737 | rcu_read_unlock(); |
| 1738 | /* |
| 1739 | * This doesn't prevent learning whether PID exists, |
| 1740 | * it only makes getattr() consistent with readdir(). |
| 1741 | */ |
| 1742 | return -ENOENT; |
| 1743 | } |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1744 | if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) || |
| 1745 | task_dumpable(task)) { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1746 | cred = __task_cred(task); |
| 1747 | stat->uid = cred->euid; |
| 1748 | stat->gid = cred->egid; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | rcu_read_unlock(); |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /* dentry stuff */ |
| 1756 | |
| 1757 | /* |
| 1758 | * Exceptional case: normally we are not allowed to unhash a busy |
| 1759 | * directory. In this case, however, we can do it - no aliasing problems |
| 1760 | * due to the way we treat inodes. |
| 1761 | * |
| 1762 | * Rewrite the inode's ownerships here because the owning task may have |
| 1763 | * performed a setuid(), etc. |
| 1764 | * |
| 1765 | * Before the /proc/pid/status file was created the only way to read |
| 1766 | * the effective uid of a /process was to stat /proc/pid. Reading |
| 1767 | * /proc/pid/status is slow enough that procps and other packages |
| 1768 | * kept stating /proc/pid. To keep the rules in /proc simple I have |
| 1769 | * made this apply to all per process world readable and executable |
| 1770 | * directories. |
| 1771 | */ |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1772 | int pid_revalidate(struct dentry *dentry, unsigned int flags) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1773 | { |
Nick Piggin | 34286d6 | 2011-01-07 17:49:57 +1100 | [diff] [blame] | 1774 | struct inode *inode; |
| 1775 | struct task_struct *task; |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1776 | const struct cred *cred; |
| 1777 | |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1778 | if (flags & LOOKUP_RCU) |
Nick Piggin | 34286d6 | 2011-01-07 17:49:57 +1100 | [diff] [blame] | 1779 | return -ECHILD; |
| 1780 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1781 | inode = d_inode(dentry); |
Nick Piggin | 34286d6 | 2011-01-07 17:49:57 +1100 | [diff] [blame] | 1782 | task = get_proc_task(inode); |
| 1783 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1784 | if (task) { |
| 1785 | if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) || |
| 1786 | task_dumpable(task)) { |
David Howells | c69e8d9 | 2008-11-14 10:39:19 +1100 | [diff] [blame] | 1787 | rcu_read_lock(); |
| 1788 | cred = __task_cred(task); |
| 1789 | inode->i_uid = cred->euid; |
| 1790 | inode->i_gid = cred->egid; |
| 1791 | rcu_read_unlock(); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1792 | } else { |
Eric W. Biederman | dcb0f22 | 2012-02-09 08:48:21 -0800 | [diff] [blame] | 1793 | inode->i_uid = GLOBAL_ROOT_UID; |
| 1794 | inode->i_gid = GLOBAL_ROOT_GID; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1795 | } |
| 1796 | inode->i_mode &= ~(S_ISUID | S_ISGID); |
| 1797 | security_task_to_inode(task, inode); |
| 1798 | put_task_struct(task); |
| 1799 | return 1; |
| 1800 | } |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1801 | return 0; |
| 1802 | } |
| 1803 | |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 1804 | static inline bool proc_inode_is_dead(struct inode *inode) |
| 1805 | { |
| 1806 | return !proc_pid(inode)->tasks[PIDTYPE_PID].first; |
| 1807 | } |
| 1808 | |
David Howells | 1dd704b | 2013-04-12 01:08:50 +0100 | [diff] [blame] | 1809 | int pid_delete_dentry(const struct dentry *dentry) |
| 1810 | { |
| 1811 | /* Is the task we represent dead? |
| 1812 | * If so, then don't put the dentry on the lru list, |
| 1813 | * kill it immediately. |
| 1814 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1815 | return proc_inode_is_dead(d_inode(dentry)); |
David Howells | 1dd704b | 2013-04-12 01:08:50 +0100 | [diff] [blame] | 1816 | } |
| 1817 | |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 1818 | const struct dentry_operations pid_dentry_operations = |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 1819 | { |
| 1820 | .d_revalidate = pid_revalidate, |
| 1821 | .d_delete = pid_delete_dentry, |
| 1822 | }; |
| 1823 | |
| 1824 | /* Lookups */ |
| 1825 | |
Eric W. Biederman | 1c0d04c | 2006-10-02 02:18:57 -0700 | [diff] [blame] | 1826 | /* |
| 1827 | * Fill a directory entry. |
| 1828 | * |
| 1829 | * If possible create the dcache entry and derive our inode number and |
| 1830 | * file type from dcache entry. |
| 1831 | * |
| 1832 | * Since all of the proc inode numbers are dynamically generated, the inode |
| 1833 | * numbers do not exist until the inode is cache. This means creating the |
| 1834 | * the dcache entry in readdir is necessary to keep the inode numbers |
| 1835 | * reported by readdir in sync with the inode numbers reported |
| 1836 | * by stat. |
| 1837 | */ |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 1838 | bool proc_fill_cache(struct file *file, struct dir_context *ctx, |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 1839 | const char *name, int len, |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 1840 | instantiate_t instantiate, struct task_struct *task, const void *ptr) |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1841 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 1842 | struct dentry *child, *dir = file->f_path.dentry; |
Al Viro | 1df98b8 | 2013-06-15 11:33:10 +0400 | [diff] [blame] | 1843 | struct qstr qname = QSTR_INIT(name, len); |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1844 | struct inode *inode; |
Al Viro | 1df98b8 | 2013-06-15 11:33:10 +0400 | [diff] [blame] | 1845 | unsigned type; |
| 1846 | ino_t ino; |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1847 | |
Al Viro | 1df98b8 | 2013-06-15 11:33:10 +0400 | [diff] [blame] | 1848 | child = d_hash_and_lookup(dir, &qname); |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1849 | if (!child) { |
Al Viro | 3781764 | 2016-04-20 16:31:31 -0400 | [diff] [blame] | 1850 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); |
| 1851 | child = d_alloc_parallel(dir, &qname, &wq); |
| 1852 | if (IS_ERR(child)) |
Al Viro | 1df98b8 | 2013-06-15 11:33:10 +0400 | [diff] [blame] | 1853 | goto end_instantiate; |
Al Viro | 3781764 | 2016-04-20 16:31:31 -0400 | [diff] [blame] | 1854 | if (d_in_lookup(child)) { |
| 1855 | int err = instantiate(d_inode(dir), child, task, ptr); |
| 1856 | d_lookup_done(child); |
| 1857 | if (err < 0) { |
| 1858 | dput(child); |
| 1859 | goto end_instantiate; |
| 1860 | } |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1861 | } |
| 1862 | } |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1863 | inode = d_inode(child); |
Al Viro | 147ce69 | 2013-06-15 10:26:35 +0400 | [diff] [blame] | 1864 | ino = inode->i_ino; |
| 1865 | type = inode->i_mode >> 12; |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1866 | dput(child); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 1867 | return dir_emit(ctx, name, len, ino, type); |
Al Viro | 1df98b8 | 2013-06-15 11:33:10 +0400 | [diff] [blame] | 1868 | |
| 1869 | end_instantiate: |
| 1870 | return dir_emit(ctx, name, len, 1, DT_UNKNOWN); |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1873 | /* |
| 1874 | * dname_to_vma_addr - maps a dentry name into two unsigned longs |
| 1875 | * which represent vma start and end addresses. |
| 1876 | */ |
| 1877 | static int dname_to_vma_addr(struct dentry *dentry, |
| 1878 | unsigned long *start, unsigned long *end) |
| 1879 | { |
Alexey Dobriyan | e0a1a01 | 2018-02-06 15:36:59 -0800 | [diff] [blame] | 1880 | const char *str = dentry->d_name.name; |
| 1881 | unsigned long long sval, eval; |
| 1882 | unsigned int len; |
| 1883 | |
| 1884 | len = _parse_integer(str, 16, &sval); |
| 1885 | if (len & KSTRTOX_OVERFLOW) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1886 | return -EINVAL; |
Alexey Dobriyan | e0a1a01 | 2018-02-06 15:36:59 -0800 | [diff] [blame] | 1887 | if (sval != (unsigned long)sval) |
| 1888 | return -EINVAL; |
| 1889 | str += len; |
| 1890 | |
| 1891 | if (*str != '-') |
| 1892 | return -EINVAL; |
| 1893 | str++; |
| 1894 | |
| 1895 | len = _parse_integer(str, 16, &eval); |
| 1896 | if (len & KSTRTOX_OVERFLOW) |
| 1897 | return -EINVAL; |
| 1898 | if (eval != (unsigned long)eval) |
| 1899 | return -EINVAL; |
| 1900 | str += len; |
| 1901 | |
| 1902 | if (*str != '\0') |
| 1903 | return -EINVAL; |
| 1904 | |
| 1905 | *start = sval; |
| 1906 | *end = eval; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1907 | |
| 1908 | return 0; |
| 1909 | } |
| 1910 | |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1911 | static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1912 | { |
| 1913 | unsigned long vm_start, vm_end; |
| 1914 | bool exact_vma_exists = false; |
| 1915 | struct mm_struct *mm = NULL; |
| 1916 | struct task_struct *task; |
| 1917 | const struct cred *cred; |
| 1918 | struct inode *inode; |
| 1919 | int status = 0; |
| 1920 | |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1921 | if (flags & LOOKUP_RCU) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1922 | return -ECHILD; |
| 1923 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1924 | inode = d_inode(dentry); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1925 | task = get_proc_task(inode); |
| 1926 | if (!task) |
| 1927 | goto out_notask; |
| 1928 | |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 1929 | mm = mm_access(task, PTRACE_MODE_READ_FSCREDS); |
Cong Wang | 2344bec | 2012-05-31 16:26:18 -0700 | [diff] [blame] | 1930 | if (IS_ERR_OR_NULL(mm)) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1931 | goto out; |
| 1932 | |
| 1933 | if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) { |
| 1934 | down_read(&mm->mmap_sem); |
| 1935 | exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end); |
| 1936 | up_read(&mm->mmap_sem); |
| 1937 | } |
| 1938 | |
| 1939 | mmput(mm); |
| 1940 | |
| 1941 | if (exact_vma_exists) { |
| 1942 | if (task_dumpable(task)) { |
| 1943 | rcu_read_lock(); |
| 1944 | cred = __task_cred(task); |
| 1945 | inode->i_uid = cred->euid; |
| 1946 | inode->i_gid = cred->egid; |
| 1947 | rcu_read_unlock(); |
| 1948 | } else { |
Eric W. Biederman | dcb0f22 | 2012-02-09 08:48:21 -0800 | [diff] [blame] | 1949 | inode->i_uid = GLOBAL_ROOT_UID; |
| 1950 | inode->i_gid = GLOBAL_ROOT_GID; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1951 | } |
| 1952 | security_task_to_inode(task, inode); |
| 1953 | status = 1; |
| 1954 | } |
| 1955 | |
| 1956 | out: |
| 1957 | put_task_struct(task); |
| 1958 | |
| 1959 | out_notask: |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1960 | return status; |
| 1961 | } |
| 1962 | |
| 1963 | static const struct dentry_operations tid_map_files_dentry_operations = { |
| 1964 | .d_revalidate = map_files_d_revalidate, |
| 1965 | .d_delete = pid_delete_dentry, |
| 1966 | }; |
| 1967 | |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1968 | static int map_files_get_link(struct dentry *dentry, struct path *path) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1969 | { |
| 1970 | unsigned long vm_start, vm_end; |
| 1971 | struct vm_area_struct *vma; |
| 1972 | struct task_struct *task; |
| 1973 | struct mm_struct *mm; |
| 1974 | int rc; |
| 1975 | |
| 1976 | rc = -ENOENT; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1977 | task = get_proc_task(d_inode(dentry)); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1978 | if (!task) |
| 1979 | goto out; |
| 1980 | |
| 1981 | mm = get_task_mm(task); |
| 1982 | put_task_struct(task); |
| 1983 | if (!mm) |
| 1984 | goto out; |
| 1985 | |
| 1986 | rc = dname_to_vma_addr(dentry, &vm_start, &vm_end); |
| 1987 | if (rc) |
| 1988 | goto out_mmput; |
| 1989 | |
Artem Fetishev | 70335ab | 2014-03-10 15:49:45 -0700 | [diff] [blame] | 1990 | rc = -ENOENT; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 1991 | down_read(&mm->mmap_sem); |
| 1992 | vma = find_exact_vma(mm, vm_start, vm_end); |
| 1993 | if (vma && vma->vm_file) { |
| 1994 | *path = vma->vm_file->f_path; |
| 1995 | path_get(path); |
| 1996 | rc = 0; |
| 1997 | } |
| 1998 | up_read(&mm->mmap_sem); |
| 1999 | |
| 2000 | out_mmput: |
| 2001 | mmput(mm); |
| 2002 | out: |
| 2003 | return rc; |
| 2004 | } |
| 2005 | |
| 2006 | struct map_files_info { |
Al Viro | 7b540d0 | 2012-08-27 14:55:26 -0400 | [diff] [blame] | 2007 | fmode_t mode; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2008 | unsigned long len; |
| 2009 | unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */ |
| 2010 | }; |
| 2011 | |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2012 | /* |
| 2013 | * Only allow CAP_SYS_ADMIN to follow the links, due to concerns about how the |
| 2014 | * symlinks may be used to bypass permissions on ancestor directories in the |
| 2015 | * path to the file in question. |
| 2016 | */ |
| 2017 | static const char * |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 2018 | proc_map_files_get_link(struct dentry *dentry, |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 2019 | struct inode *inode, |
| 2020 | struct delayed_call *done) |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2021 | { |
| 2022 | if (!capable(CAP_SYS_ADMIN)) |
| 2023 | return ERR_PTR(-EPERM); |
| 2024 | |
Al Viro | fceef39 | 2015-12-29 15:58:39 -0500 | [diff] [blame] | 2025 | return proc_pid_get_link(dentry, inode, done); |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /* |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 2029 | * Identical to proc_pid_link_inode_operations except for get_link() |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2030 | */ |
| 2031 | static const struct inode_operations proc_map_files_link_inode_operations = { |
| 2032 | .readlink = proc_pid_readlink, |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 2033 | .get_link = proc_map_files_get_link, |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2034 | .setattr = proc_setattr, |
| 2035 | }; |
| 2036 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2037 | static int |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2038 | proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, |
| 2039 | struct task_struct *task, const void *ptr) |
| 2040 | { |
Al Viro | 7b540d0 | 2012-08-27 14:55:26 -0400 | [diff] [blame] | 2041 | fmode_t mode = (fmode_t)(unsigned long)ptr; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2042 | struct proc_inode *ei; |
| 2043 | struct inode *inode; |
| 2044 | |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2045 | inode = proc_pid_make_inode(dir->i_sb, task); |
| 2046 | if (!inode) |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2047 | return -ENOENT; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2048 | |
| 2049 | ei = PROC_I(inode); |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 2050 | ei->op.proc_get_link = map_files_get_link; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2051 | |
Calvin Owens | bdb4d10 | 2015-09-09 15:35:54 -0700 | [diff] [blame] | 2052 | inode->i_op = &proc_map_files_link_inode_operations; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2053 | inode->i_size = 64; |
| 2054 | inode->i_mode = S_IFLNK; |
| 2055 | |
Al Viro | 7b540d0 | 2012-08-27 14:55:26 -0400 | [diff] [blame] | 2056 | if (mode & FMODE_READ) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2057 | inode->i_mode |= S_IRUSR; |
Al Viro | 7b540d0 | 2012-08-27 14:55:26 -0400 | [diff] [blame] | 2058 | if (mode & FMODE_WRITE) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2059 | inode->i_mode |= S_IWUSR; |
| 2060 | |
| 2061 | d_set_d_op(dentry, &tid_map_files_dentry_operations); |
| 2062 | d_add(dentry, inode); |
| 2063 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2064 | return 0; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | static struct dentry *proc_map_files_lookup(struct inode *dir, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 2068 | struct dentry *dentry, unsigned int flags) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2069 | { |
| 2070 | unsigned long vm_start, vm_end; |
| 2071 | struct vm_area_struct *vma; |
| 2072 | struct task_struct *task; |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2073 | int result; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2074 | struct mm_struct *mm; |
| 2075 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2076 | result = -ENOENT; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2077 | task = get_proc_task(dir); |
| 2078 | if (!task) |
| 2079 | goto out; |
| 2080 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2081 | result = -EACCES; |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 2082 | if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2083 | goto out_put_task; |
| 2084 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2085 | result = -ENOENT; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2086 | if (dname_to_vma_addr(dentry, &vm_start, &vm_end)) |
Cyrill Gorcunov | eb94cd9 | 2012-05-17 17:03:25 -0700 | [diff] [blame] | 2087 | goto out_put_task; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2088 | |
| 2089 | mm = get_task_mm(task); |
| 2090 | if (!mm) |
Cyrill Gorcunov | eb94cd9 | 2012-05-17 17:03:25 -0700 | [diff] [blame] | 2091 | goto out_put_task; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2092 | |
| 2093 | down_read(&mm->mmap_sem); |
| 2094 | vma = find_exact_vma(mm, vm_start, vm_end); |
| 2095 | if (!vma) |
| 2096 | goto out_no_vma; |
| 2097 | |
Stanislav Kinsbursky | 05f5648 | 2012-11-26 16:29:42 -0800 | [diff] [blame] | 2098 | if (vma->vm_file) |
| 2099 | result = proc_map_files_instantiate(dir, dentry, task, |
| 2100 | (void *)(unsigned long)vma->vm_file->f_mode); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2101 | |
| 2102 | out_no_vma: |
| 2103 | up_read(&mm->mmap_sem); |
| 2104 | mmput(mm); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2105 | out_put_task: |
| 2106 | put_task_struct(task); |
| 2107 | out: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2108 | return ERR_PTR(result); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | static const struct inode_operations proc_map_files_inode_operations = { |
| 2112 | .lookup = proc_map_files_lookup, |
| 2113 | .permission = proc_fd_permission, |
| 2114 | .setattr = proc_setattr, |
| 2115 | }; |
| 2116 | |
| 2117 | static int |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2118 | proc_map_files_readdir(struct file *file, struct dir_context *ctx) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2119 | { |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2120 | struct vm_area_struct *vma; |
| 2121 | struct task_struct *task; |
| 2122 | struct mm_struct *mm; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2123 | unsigned long nr_files, pos, i; |
| 2124 | struct flex_array *fa = NULL; |
| 2125 | struct map_files_info info; |
| 2126 | struct map_files_info *p; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2127 | int ret; |
| 2128 | |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2129 | ret = -ENOENT; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2130 | task = get_proc_task(file_inode(file)); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2131 | if (!task) |
| 2132 | goto out; |
| 2133 | |
| 2134 | ret = -EACCES; |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 2135 | if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2136 | goto out_put_task; |
| 2137 | |
| 2138 | ret = 0; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2139 | if (!dir_emit_dots(file, ctx)) |
| 2140 | goto out_put_task; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2141 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2142 | mm = get_task_mm(task); |
| 2143 | if (!mm) |
| 2144 | goto out_put_task; |
| 2145 | down_read(&mm->mmap_sem); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2146 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2147 | nr_files = 0; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2148 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2149 | /* |
| 2150 | * We need two passes here: |
| 2151 | * |
| 2152 | * 1) Collect vmas of mapped files with mmap_sem taken |
| 2153 | * 2) Release mmap_sem and instantiate entries |
| 2154 | * |
| 2155 | * otherwise we get lockdep complained, since filldir() |
| 2156 | * routine might require mmap_sem taken in might_fault(). |
| 2157 | */ |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2158 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2159 | for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) { |
| 2160 | if (vma->vm_file && ++pos > ctx->pos) |
| 2161 | nr_files++; |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2162 | } |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2163 | |
| 2164 | if (nr_files) { |
| 2165 | fa = flex_array_alloc(sizeof(info), nr_files, |
| 2166 | GFP_KERNEL); |
| 2167 | if (!fa || flex_array_prealloc(fa, 0, nr_files, |
| 2168 | GFP_KERNEL)) { |
| 2169 | ret = -ENOMEM; |
| 2170 | if (fa) |
| 2171 | flex_array_free(fa); |
| 2172 | up_read(&mm->mmap_sem); |
| 2173 | mmput(mm); |
| 2174 | goto out_put_task; |
| 2175 | } |
| 2176 | for (i = 0, vma = mm->mmap, pos = 2; vma; |
| 2177 | vma = vma->vm_next) { |
| 2178 | if (!vma->vm_file) |
| 2179 | continue; |
| 2180 | if (++pos <= ctx->pos) |
| 2181 | continue; |
| 2182 | |
| 2183 | info.mode = vma->vm_file->f_mode; |
| 2184 | info.len = snprintf(info.name, |
| 2185 | sizeof(info.name), "%lx-%lx", |
| 2186 | vma->vm_start, vma->vm_end); |
| 2187 | if (flex_array_put(fa, i++, &info, GFP_KERNEL)) |
| 2188 | BUG(); |
| 2189 | } |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2190 | } |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2191 | up_read(&mm->mmap_sem); |
| 2192 | |
| 2193 | for (i = 0; i < nr_files; i++) { |
| 2194 | p = flex_array_get(fa, i); |
| 2195 | if (!proc_fill_cache(file, ctx, |
| 2196 | p->name, p->len, |
| 2197 | proc_map_files_instantiate, |
| 2198 | task, |
| 2199 | (void *)(unsigned long)p->mode)) |
| 2200 | break; |
| 2201 | ctx->pos++; |
| 2202 | } |
| 2203 | if (fa) |
| 2204 | flex_array_free(fa); |
| 2205 | mmput(mm); |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2206 | |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2207 | out_put_task: |
| 2208 | put_task_struct(task); |
| 2209 | out: |
| 2210 | return ret; |
| 2211 | } |
| 2212 | |
| 2213 | static const struct file_operations proc_map_files_operations = { |
| 2214 | .read = generic_read_dir, |
Al Viro | f50752e | 2016-04-20 17:13:54 -0400 | [diff] [blame] | 2215 | .iterate_shared = proc_map_files_readdir, |
| 2216 | .llseek = generic_file_llseek, |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2217 | }; |
| 2218 | |
Eric Engestrom | b5946be | 2016-03-17 14:20:57 -0700 | [diff] [blame] | 2219 | #ifdef CONFIG_CHECKPOINT_RESTORE |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2220 | struct timers_private { |
| 2221 | struct pid *pid; |
| 2222 | struct task_struct *task; |
| 2223 | struct sighand_struct *sighand; |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2224 | struct pid_namespace *ns; |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2225 | unsigned long flags; |
| 2226 | }; |
| 2227 | |
| 2228 | static void *timers_start(struct seq_file *m, loff_t *pos) |
| 2229 | { |
| 2230 | struct timers_private *tp = m->private; |
| 2231 | |
| 2232 | tp->task = get_pid_task(tp->pid, PIDTYPE_PID); |
| 2233 | if (!tp->task) |
| 2234 | return ERR_PTR(-ESRCH); |
| 2235 | |
| 2236 | tp->sighand = lock_task_sighand(tp->task, &tp->flags); |
| 2237 | if (!tp->sighand) |
| 2238 | return ERR_PTR(-ESRCH); |
| 2239 | |
| 2240 | return seq_list_start(&tp->task->signal->posix_timers, *pos); |
| 2241 | } |
| 2242 | |
| 2243 | static void *timers_next(struct seq_file *m, void *v, loff_t *pos) |
| 2244 | { |
| 2245 | struct timers_private *tp = m->private; |
| 2246 | return seq_list_next(v, &tp->task->signal->posix_timers, pos); |
| 2247 | } |
| 2248 | |
| 2249 | static void timers_stop(struct seq_file *m, void *v) |
| 2250 | { |
| 2251 | struct timers_private *tp = m->private; |
| 2252 | |
| 2253 | if (tp->sighand) { |
| 2254 | unlock_task_sighand(tp->task, &tp->flags); |
| 2255 | tp->sighand = NULL; |
| 2256 | } |
| 2257 | |
| 2258 | if (tp->task) { |
| 2259 | put_task_struct(tp->task); |
| 2260 | tp->task = NULL; |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | static int show_timer(struct seq_file *m, void *v) |
| 2265 | { |
| 2266 | struct k_itimer *timer; |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2267 | struct timers_private *tp = m->private; |
| 2268 | int notify; |
Alexey Dobriyan | cedbcca | 2014-08-08 14:21:33 -0700 | [diff] [blame] | 2269 | static const char * const nstr[] = { |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2270 | [SIGEV_SIGNAL] = "signal", |
| 2271 | [SIGEV_NONE] = "none", |
| 2272 | [SIGEV_THREAD] = "thread", |
| 2273 | }; |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2274 | |
| 2275 | timer = list_entry((struct list_head *)v, struct k_itimer, list); |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2276 | notify = timer->it_sigev_notify; |
| 2277 | |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2278 | seq_printf(m, "ID: %d\n", timer->it_id); |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 2279 | seq_printf(m, "signal: %d/%p\n", |
| 2280 | timer->sigq->info.si_signo, |
| 2281 | timer->sigq->info.si_value.sival_ptr); |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2282 | seq_printf(m, "notify: %s/%s.%d\n", |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 2283 | nstr[notify & ~SIGEV_THREAD_ID], |
| 2284 | (notify & SIGEV_THREAD_ID) ? "tid" : "pid", |
| 2285 | pid_nr_ns(timer->it_pid, tp->ns)); |
Pavel Tikhomirov | 15ef029 | 2013-05-17 02:12:03 +0400 | [diff] [blame] | 2286 | seq_printf(m, "ClockID: %d\n", timer->it_clock); |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2287 | |
| 2288 | return 0; |
| 2289 | } |
| 2290 | |
| 2291 | static const struct seq_operations proc_timers_seq_ops = { |
| 2292 | .start = timers_start, |
| 2293 | .next = timers_next, |
| 2294 | .stop = timers_stop, |
| 2295 | .show = show_timer, |
| 2296 | }; |
| 2297 | |
| 2298 | static int proc_timers_open(struct inode *inode, struct file *file) |
| 2299 | { |
| 2300 | struct timers_private *tp; |
| 2301 | |
| 2302 | tp = __seq_open_private(file, &proc_timers_seq_ops, |
| 2303 | sizeof(struct timers_private)); |
| 2304 | if (!tp) |
| 2305 | return -ENOMEM; |
| 2306 | |
| 2307 | tp->pid = proc_pid(inode); |
Pavel Emelyanov | 57b8015 | 2013-03-11 13:13:08 +0400 | [diff] [blame] | 2308 | tp->ns = inode->i_sb->s_fs_info; |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | static const struct file_operations proc_timers_operations = { |
| 2313 | .open = proc_timers_open, |
| 2314 | .read = seq_read, |
| 2315 | .llseek = seq_lseek, |
| 2316 | .release = seq_release_private, |
| 2317 | }; |
Eric Engestrom | b5946be | 2016-03-17 14:20:57 -0700 | [diff] [blame] | 2318 | #endif |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2319 | |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2320 | static ssize_t timerslack_ns_write(struct file *file, const char __user *buf, |
| 2321 | size_t count, loff_t *offset) |
| 2322 | { |
| 2323 | struct inode *inode = file_inode(file); |
| 2324 | struct task_struct *p; |
| 2325 | u64 slack_ns; |
| 2326 | int err; |
| 2327 | |
| 2328 | err = kstrtoull_from_user(buf, count, 10, &slack_ns); |
| 2329 | if (err < 0) |
| 2330 | return err; |
| 2331 | |
| 2332 | p = get_proc_task(inode); |
| 2333 | if (!p) |
| 2334 | return -ESRCH; |
| 2335 | |
John Stultz | 4b2bd5f | 2016-10-07 17:02:33 -0700 | [diff] [blame] | 2336 | if (p != current) { |
| 2337 | if (!capable(CAP_SYS_NICE)) { |
| 2338 | count = -EPERM; |
| 2339 | goto out; |
| 2340 | } |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2341 | |
John Stultz | 4b2bd5f | 2016-10-07 17:02:33 -0700 | [diff] [blame] | 2342 | err = security_task_setscheduler(p); |
| 2343 | if (err) { |
| 2344 | count = err; |
| 2345 | goto out; |
| 2346 | } |
John Stultz | 904763e | 2016-10-07 17:02:29 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
John Stultz | 7abbaf9 | 2016-10-07 17:02:26 -0700 | [diff] [blame] | 2349 | task_lock(p); |
| 2350 | if (slack_ns == 0) |
| 2351 | p->timer_slack_ns = p->default_timer_slack_ns; |
| 2352 | else |
| 2353 | p->timer_slack_ns = slack_ns; |
| 2354 | task_unlock(p); |
| 2355 | |
| 2356 | out: |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2357 | put_task_struct(p); |
| 2358 | |
| 2359 | return count; |
| 2360 | } |
| 2361 | |
| 2362 | static int timerslack_ns_show(struct seq_file *m, void *v) |
| 2363 | { |
| 2364 | struct inode *inode = m->private; |
| 2365 | struct task_struct *p; |
John Stultz | 7abbaf9 | 2016-10-07 17:02:26 -0700 | [diff] [blame] | 2366 | int err = 0; |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2367 | |
| 2368 | p = get_proc_task(inode); |
| 2369 | if (!p) |
| 2370 | return -ESRCH; |
| 2371 | |
John Stultz | 4b2bd5f | 2016-10-07 17:02:33 -0700 | [diff] [blame] | 2372 | if (p != current) { |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2373 | |
John Stultz | 4b2bd5f | 2016-10-07 17:02:33 -0700 | [diff] [blame] | 2374 | if (!capable(CAP_SYS_NICE)) { |
| 2375 | err = -EPERM; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | err = security_task_getscheduler(p); |
| 2379 | if (err) |
| 2380 | goto out; |
| 2381 | } |
John Stultz | 904763e | 2016-10-07 17:02:29 -0700 | [diff] [blame] | 2382 | |
John Stultz | 7abbaf9 | 2016-10-07 17:02:26 -0700 | [diff] [blame] | 2383 | task_lock(p); |
| 2384 | seq_printf(m, "%llu\n", p->timer_slack_ns); |
| 2385 | task_unlock(p); |
| 2386 | |
| 2387 | out: |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2388 | put_task_struct(p); |
| 2389 | |
| 2390 | return err; |
| 2391 | } |
| 2392 | |
| 2393 | static int timerslack_ns_open(struct inode *inode, struct file *filp) |
| 2394 | { |
| 2395 | return single_open(filp, timerslack_ns_show, inode); |
| 2396 | } |
| 2397 | |
| 2398 | static const struct file_operations proc_pid_set_timerslack_ns_operations = { |
| 2399 | .open = timerslack_ns_open, |
| 2400 | .read = seq_read, |
| 2401 | .write = timerslack_ns_write, |
| 2402 | .llseek = seq_lseek, |
| 2403 | .release = single_release, |
| 2404 | }; |
| 2405 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2406 | static int proc_pident_instantiate(struct inode *dir, |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2407 | struct dentry *dentry, struct task_struct *task, const void *ptr) |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2408 | { |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2409 | const struct pid_entry *p = ptr; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2410 | struct inode *inode; |
| 2411 | struct proc_inode *ei; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2412 | |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2413 | inode = proc_pid_make_inode(dir->i_sb, task); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2414 | if (!inode) |
| 2415 | goto out; |
| 2416 | |
| 2417 | ei = PROC_I(inode); |
| 2418 | inode->i_mode = p->mode; |
| 2419 | if (S_ISDIR(inode->i_mode)) |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 2420 | set_nlink(inode, 2); /* Use getattr to fix if necessary */ |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2421 | if (p->iop) |
| 2422 | inode->i_op = p->iop; |
| 2423 | if (p->fop) |
| 2424 | inode->i_fop = p->fop; |
| 2425 | ei->op = p->op; |
Nick Piggin | fb045ad | 2011-01-07 17:49:55 +1100 | [diff] [blame] | 2426 | d_set_d_op(dentry, &pid_dentry_operations); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2427 | d_add(dentry, inode); |
| 2428 | /* Close the race of the process dying before we return the dentry */ |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 2429 | if (pid_revalidate(dentry, 0)) |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2430 | return 0; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2431 | out: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2432 | return -ENOENT; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | static struct dentry *proc_pident_lookup(struct inode *dir, |
| 2436 | struct dentry *dentry, |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2437 | const struct pid_entry *ents, |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 2438 | unsigned int nents) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | { |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2440 | int error; |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 2441 | struct task_struct *task = get_proc_task(dir); |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2442 | const struct pid_entry *p, *last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2444 | error = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 2446 | if (!task) |
| 2447 | goto out_no_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 2449 | /* |
| 2450 | * Yes, it does not scale. And it should not. Don't add |
| 2451 | * new entries into /proc/<tgid>/ without very good reasons. |
| 2452 | */ |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 2453 | last = &ents[nents - 1]; |
| 2454 | for (p = ents; p <= last; p++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | if (p->len != dentry->d_name.len) |
| 2456 | continue; |
| 2457 | if (!memcmp(dentry->d_name.name, p->name, p->len)) |
| 2458 | break; |
| 2459 | } |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 2460 | if (p > last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | goto out; |
| 2462 | |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2463 | error = proc_pident_instantiate(dir, dentry, task, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | out: |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 2465 | put_task_struct(task); |
| 2466 | out_no_task: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 2467 | return ERR_PTR(error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2470 | static int proc_pident_readdir(struct file *file, struct dir_context *ctx, |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2471 | const struct pid_entry *ents, unsigned int nents) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2472 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2473 | struct task_struct *task = get_proc_task(file_inode(file)); |
| 2474 | const struct pid_entry *p; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2475 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2476 | if (!task) |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2477 | return -ENOENT; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2478 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2479 | if (!dir_emit_dots(file, ctx)) |
| 2480 | goto out; |
| 2481 | |
| 2482 | if (ctx->pos >= nents + 2) |
| 2483 | goto out; |
| 2484 | |
| 2485 | for (p = ents + (ctx->pos - 2); p <= ents + nents - 1; p++) { |
| 2486 | if (!proc_fill_cache(file, ctx, p->name, p->len, |
| 2487 | proc_pident_instantiate, task, p)) |
| 2488 | break; |
| 2489 | ctx->pos++; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2490 | } |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2491 | out: |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 2492 | put_task_struct(task); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2493 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | #ifdef CONFIG_SECURITY |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2497 | static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, |
| 2498 | size_t count, loff_t *ppos) |
| 2499 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 2500 | struct inode * inode = file_inode(file); |
Al Viro | 04ff970 | 2007-03-12 16:17:58 +0000 | [diff] [blame] | 2501 | char *p = NULL; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2502 | ssize_t length; |
| 2503 | struct task_struct *task = get_proc_task(inode); |
| 2504 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2505 | if (!task) |
Al Viro | 04ff970 | 2007-03-12 16:17:58 +0000 | [diff] [blame] | 2506 | return -ESRCH; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2507 | |
| 2508 | length = security_getprocattr(task, |
Josef "Jeff" Sipek | 2fddfee | 2006-12-08 02:36:36 -0800 | [diff] [blame] | 2509 | (char*)file->f_path.dentry->d_name.name, |
Al Viro | 04ff970 | 2007-03-12 16:17:58 +0000 | [diff] [blame] | 2510 | &p); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2511 | put_task_struct(task); |
Al Viro | 04ff970 | 2007-03-12 16:17:58 +0000 | [diff] [blame] | 2512 | if (length > 0) |
| 2513 | length = simple_read_from_buffer(buf, count, ppos, p, length); |
| 2514 | kfree(p); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2515 | return length; |
| 2516 | } |
| 2517 | |
| 2518 | static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, |
| 2519 | size_t count, loff_t *ppos) |
| 2520 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 2521 | struct inode * inode = file_inode(file); |
Al Viro | bb646cd | 2015-12-24 00:16:30 -0500 | [diff] [blame] | 2522 | void *page; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2523 | ssize_t length; |
| 2524 | struct task_struct *task = get_proc_task(inode); |
| 2525 | |
| 2526 | length = -ESRCH; |
| 2527 | if (!task) |
| 2528 | goto out_no_task; |
| 2529 | if (count > PAGE_SIZE) |
| 2530 | count = PAGE_SIZE; |
| 2531 | |
| 2532 | /* No partial writes. */ |
| 2533 | length = -EINVAL; |
| 2534 | if (*ppos != 0) |
| 2535 | goto out; |
| 2536 | |
Al Viro | bb646cd | 2015-12-24 00:16:30 -0500 | [diff] [blame] | 2537 | page = memdup_user(buf, count); |
| 2538 | if (IS_ERR(page)) { |
| 2539 | length = PTR_ERR(page); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2540 | goto out; |
Al Viro | bb646cd | 2015-12-24 00:16:30 -0500 | [diff] [blame] | 2541 | } |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2542 | |
David Howells | 107db7c | 2009-05-08 13:55:27 +0100 | [diff] [blame] | 2543 | /* Guard against adverse ptrace interaction */ |
KOSAKI Motohiro | 9b1bf12 | 2010-10-27 15:34:08 -0700 | [diff] [blame] | 2544 | length = mutex_lock_interruptible(&task->signal->cred_guard_mutex); |
David Howells | 107db7c | 2009-05-08 13:55:27 +0100 | [diff] [blame] | 2545 | if (length < 0) |
| 2546 | goto out_free; |
| 2547 | |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2548 | length = security_setprocattr(task, |
Josef "Jeff" Sipek | 2fddfee | 2006-12-08 02:36:36 -0800 | [diff] [blame] | 2549 | (char*)file->f_path.dentry->d_name.name, |
Al Viro | bb646cd | 2015-12-24 00:16:30 -0500 | [diff] [blame] | 2550 | page, count); |
KOSAKI Motohiro | 9b1bf12 | 2010-10-27 15:34:08 -0700 | [diff] [blame] | 2551 | mutex_unlock(&task->signal->cred_guard_mutex); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2552 | out_free: |
Al Viro | bb646cd | 2015-12-24 00:16:30 -0500 | [diff] [blame] | 2553 | kfree(page); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2554 | out: |
| 2555 | put_task_struct(task); |
| 2556 | out_no_task: |
| 2557 | return length; |
| 2558 | } |
| 2559 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 2560 | static const struct file_operations proc_pid_attr_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2561 | .read = proc_pid_attr_read, |
| 2562 | .write = proc_pid_attr_write, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 2563 | .llseek = generic_file_llseek, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2564 | }; |
| 2565 | |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2566 | static const struct pid_entry attr_dir_stuff[] = { |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2567 | REG("current", S_IRUGO|S_IWUGO, proc_pid_attr_operations), |
| 2568 | REG("prev", S_IRUGO, proc_pid_attr_operations), |
| 2569 | REG("exec", S_IRUGO|S_IWUGO, proc_pid_attr_operations), |
| 2570 | REG("fscreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), |
| 2571 | REG("keycreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), |
| 2572 | REG("sockcreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2573 | }; |
| 2574 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2575 | static int proc_attr_dir_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2577 | return proc_pident_readdir(file, ctx, |
| 2578 | attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 2581 | static const struct file_operations proc_attr_dir_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | .read = generic_read_dir, |
Al Viro | f50752e | 2016-04-20 17:13:54 -0400 | [diff] [blame] | 2583 | .iterate_shared = proc_attr_dir_readdir, |
| 2584 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | }; |
| 2586 | |
Eric W. Biederman | 72d9dcf | 2006-10-02 02:18:50 -0700 | [diff] [blame] | 2587 | static struct dentry *proc_attr_dir_lookup(struct inode *dir, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 2588 | struct dentry *dentry, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | { |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 2590 | return proc_pident_lookup(dir, dentry, |
| 2591 | attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 2594 | static const struct inode_operations proc_attr_dir_inode_operations = { |
Eric W. Biederman | 72d9dcf | 2006-10-02 02:18:50 -0700 | [diff] [blame] | 2595 | .lookup = proc_attr_dir_lookup, |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 2596 | .getattr = pid_getattr, |
Linus Torvalds | 6d76fa5 | 2006-07-15 12:26:45 -0700 | [diff] [blame] | 2597 | .setattr = proc_setattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | }; |
| 2599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | #endif |
| 2601 | |
Christoph Hellwig | 698ba7b | 2009-12-15 16:47:37 -0800 | [diff] [blame] | 2602 | #ifdef CONFIG_ELF_CORE |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2603 | static ssize_t proc_coredump_filter_read(struct file *file, char __user *buf, |
| 2604 | size_t count, loff_t *ppos) |
| 2605 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 2606 | struct task_struct *task = get_proc_task(file_inode(file)); |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2607 | struct mm_struct *mm; |
| 2608 | char buffer[PROC_NUMBUF]; |
| 2609 | size_t len; |
| 2610 | int ret; |
| 2611 | |
| 2612 | if (!task) |
| 2613 | return -ESRCH; |
| 2614 | |
| 2615 | ret = 0; |
| 2616 | mm = get_task_mm(task); |
| 2617 | if (mm) { |
| 2618 | len = snprintf(buffer, sizeof(buffer), "%08lx\n", |
| 2619 | ((mm->flags & MMF_DUMP_FILTER_MASK) >> |
| 2620 | MMF_DUMP_FILTER_SHIFT)); |
| 2621 | mmput(mm); |
| 2622 | ret = simple_read_from_buffer(buf, count, ppos, buffer, len); |
| 2623 | } |
| 2624 | |
| 2625 | put_task_struct(task); |
| 2626 | |
| 2627 | return ret; |
| 2628 | } |
| 2629 | |
| 2630 | static ssize_t proc_coredump_filter_write(struct file *file, |
| 2631 | const char __user *buf, |
| 2632 | size_t count, |
| 2633 | loff_t *ppos) |
| 2634 | { |
| 2635 | struct task_struct *task; |
| 2636 | struct mm_struct *mm; |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2637 | unsigned int val; |
| 2638 | int ret; |
| 2639 | int i; |
| 2640 | unsigned long mask; |
| 2641 | |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 2642 | ret = kstrtouint_from_user(buf, count, 0, &val); |
| 2643 | if (ret < 0) |
| 2644 | return ret; |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2645 | |
| 2646 | ret = -ESRCH; |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 2647 | task = get_proc_task(file_inode(file)); |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2648 | if (!task) |
| 2649 | goto out_no_task; |
| 2650 | |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2651 | mm = get_task_mm(task); |
| 2652 | if (!mm) |
| 2653 | goto out_no_mm; |
Colin Ian King | 41a0c249 | 2015-12-18 14:22:01 -0800 | [diff] [blame] | 2654 | ret = 0; |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2655 | |
| 2656 | for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) { |
| 2657 | if (val & mask) |
| 2658 | set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags); |
| 2659 | else |
| 2660 | clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags); |
| 2661 | } |
| 2662 | |
| 2663 | mmput(mm); |
| 2664 | out_no_mm: |
| 2665 | put_task_struct(task); |
| 2666 | out_no_task: |
Alexey Dobriyan | 774636e | 2015-09-09 15:36:59 -0700 | [diff] [blame] | 2667 | if (ret < 0) |
| 2668 | return ret; |
| 2669 | return count; |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | static const struct file_operations proc_coredump_filter_operations = { |
| 2673 | .read = proc_coredump_filter_read, |
| 2674 | .write = proc_coredump_filter_write, |
Arnd Bergmann | 87df842 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 2675 | .llseek = generic_file_llseek, |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2676 | }; |
| 2677 | #endif |
| 2678 | |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2679 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2680 | static int do_io_accounting(struct task_struct *task, struct seq_file *m, int whole) |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2681 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 2682 | struct task_io_accounting acct = task->ioac; |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 2683 | unsigned long flags; |
Vasiliy Kulikov | 293eb1e | 2011-07-26 16:08:38 -0700 | [diff] [blame] | 2684 | int result; |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2685 | |
Vasiliy Kulikov | 293eb1e | 2011-07-26 16:08:38 -0700 | [diff] [blame] | 2686 | result = mutex_lock_killable(&task->signal->cred_guard_mutex); |
| 2687 | if (result) |
| 2688 | return result; |
| 2689 | |
Jann Horn | caaee62 | 2016-01-20 15:00:04 -0800 | [diff] [blame] | 2690 | if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { |
Vasiliy Kulikov | 293eb1e | 2011-07-26 16:08:38 -0700 | [diff] [blame] | 2691 | result = -EACCES; |
| 2692 | goto out_unlock; |
| 2693 | } |
Vasiliy Kulikov | 1d1221f | 2011-06-24 16:08:38 +0400 | [diff] [blame] | 2694 | |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 2695 | if (whole && lock_task_sighand(task, &flags)) { |
| 2696 | struct task_struct *t = task; |
Andrea Righi | b2d002d | 2008-07-26 15:22:27 -0700 | [diff] [blame] | 2697 | |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 2698 | task_io_accounting_add(&acct, &task->signal->ioac); |
| 2699 | while_each_thread(task, t) |
| 2700 | task_io_accounting_add(&acct, &t->ioac); |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2701 | |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 2702 | unlock_task_sighand(task, &flags); |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2703 | } |
Joe Perches | 25ce319 | 2015-04-15 16:18:17 -0700 | [diff] [blame] | 2704 | seq_printf(m, |
| 2705 | "rchar: %llu\n" |
| 2706 | "wchar: %llu\n" |
| 2707 | "syscr: %llu\n" |
| 2708 | "syscw: %llu\n" |
| 2709 | "read_bytes: %llu\n" |
| 2710 | "write_bytes: %llu\n" |
| 2711 | "cancelled_write_bytes: %llu\n", |
| 2712 | (unsigned long long)acct.rchar, |
| 2713 | (unsigned long long)acct.wchar, |
| 2714 | (unsigned long long)acct.syscr, |
| 2715 | (unsigned long long)acct.syscw, |
| 2716 | (unsigned long long)acct.read_bytes, |
| 2717 | (unsigned long long)acct.write_bytes, |
| 2718 | (unsigned long long)acct.cancelled_write_bytes); |
| 2719 | result = 0; |
| 2720 | |
Vasiliy Kulikov | 293eb1e | 2011-07-26 16:08:38 -0700 | [diff] [blame] | 2721 | out_unlock: |
| 2722 | mutex_unlock(&task->signal->cred_guard_mutex); |
| 2723 | return result; |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2724 | } |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2725 | |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2726 | static int proc_tid_io_accounting(struct seq_file *m, struct pid_namespace *ns, |
| 2727 | struct pid *pid, struct task_struct *task) |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2728 | { |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2729 | return do_io_accounting(task, m, 0); |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2732 | static int proc_tgid_io_accounting(struct seq_file *m, struct pid_namespace *ns, |
| 2733 | struct pid *pid, struct task_struct *task) |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2734 | { |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2735 | return do_io_accounting(task, m, 1); |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 2736 | } |
| 2737 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2738 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2739 | #ifdef CONFIG_USER_NS |
| 2740 | static int proc_id_map_open(struct inode *inode, struct file *file, |
Fabian Frederick | ccf94f1 | 2014-08-08 14:21:22 -0700 | [diff] [blame] | 2741 | const struct seq_operations *seq_ops) |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2742 | { |
| 2743 | struct user_namespace *ns = NULL; |
| 2744 | struct task_struct *task; |
| 2745 | struct seq_file *seq; |
| 2746 | int ret = -EINVAL; |
| 2747 | |
| 2748 | task = get_proc_task(inode); |
| 2749 | if (task) { |
| 2750 | rcu_read_lock(); |
| 2751 | ns = get_user_ns(task_cred_xxx(task, user_ns)); |
| 2752 | rcu_read_unlock(); |
| 2753 | put_task_struct(task); |
| 2754 | } |
| 2755 | if (!ns) |
| 2756 | goto err; |
| 2757 | |
| 2758 | ret = seq_open(file, seq_ops); |
| 2759 | if (ret) |
| 2760 | goto err_put_ns; |
| 2761 | |
| 2762 | seq = file->private_data; |
| 2763 | seq->private = ns; |
| 2764 | |
| 2765 | return 0; |
| 2766 | err_put_ns: |
| 2767 | put_user_ns(ns); |
| 2768 | err: |
| 2769 | return ret; |
| 2770 | } |
| 2771 | |
| 2772 | static int proc_id_map_release(struct inode *inode, struct file *file) |
| 2773 | { |
| 2774 | struct seq_file *seq = file->private_data; |
| 2775 | struct user_namespace *ns = seq->private; |
| 2776 | put_user_ns(ns); |
| 2777 | return seq_release(inode, file); |
| 2778 | } |
| 2779 | |
| 2780 | static int proc_uid_map_open(struct inode *inode, struct file *file) |
| 2781 | { |
| 2782 | return proc_id_map_open(inode, file, &proc_uid_seq_operations); |
| 2783 | } |
| 2784 | |
| 2785 | static int proc_gid_map_open(struct inode *inode, struct file *file) |
| 2786 | { |
| 2787 | return proc_id_map_open(inode, file, &proc_gid_seq_operations); |
| 2788 | } |
| 2789 | |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 2790 | static int proc_projid_map_open(struct inode *inode, struct file *file) |
| 2791 | { |
| 2792 | return proc_id_map_open(inode, file, &proc_projid_seq_operations); |
| 2793 | } |
| 2794 | |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2795 | static const struct file_operations proc_uid_map_operations = { |
| 2796 | .open = proc_uid_map_open, |
| 2797 | .write = proc_uid_map_write, |
| 2798 | .read = seq_read, |
| 2799 | .llseek = seq_lseek, |
| 2800 | .release = proc_id_map_release, |
| 2801 | }; |
| 2802 | |
| 2803 | static const struct file_operations proc_gid_map_operations = { |
| 2804 | .open = proc_gid_map_open, |
| 2805 | .write = proc_gid_map_write, |
| 2806 | .read = seq_read, |
| 2807 | .llseek = seq_lseek, |
| 2808 | .release = proc_id_map_release, |
| 2809 | }; |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 2810 | |
| 2811 | static const struct file_operations proc_projid_map_operations = { |
| 2812 | .open = proc_projid_map_open, |
| 2813 | .write = proc_projid_map_write, |
| 2814 | .read = seq_read, |
| 2815 | .llseek = seq_lseek, |
| 2816 | .release = proc_id_map_release, |
| 2817 | }; |
Eric W. Biederman | 9cc4651 | 2014-12-02 12:27:26 -0600 | [diff] [blame] | 2818 | |
| 2819 | static int proc_setgroups_open(struct inode *inode, struct file *file) |
| 2820 | { |
| 2821 | struct user_namespace *ns = NULL; |
| 2822 | struct task_struct *task; |
| 2823 | int ret; |
| 2824 | |
| 2825 | ret = -ESRCH; |
| 2826 | task = get_proc_task(inode); |
| 2827 | if (task) { |
| 2828 | rcu_read_lock(); |
| 2829 | ns = get_user_ns(task_cred_xxx(task, user_ns)); |
| 2830 | rcu_read_unlock(); |
| 2831 | put_task_struct(task); |
| 2832 | } |
| 2833 | if (!ns) |
| 2834 | goto err; |
| 2835 | |
| 2836 | if (file->f_mode & FMODE_WRITE) { |
| 2837 | ret = -EACCES; |
| 2838 | if (!ns_capable(ns, CAP_SYS_ADMIN)) |
| 2839 | goto err_put_ns; |
| 2840 | } |
| 2841 | |
| 2842 | ret = single_open(file, &proc_setgroups_show, ns); |
| 2843 | if (ret) |
| 2844 | goto err_put_ns; |
| 2845 | |
| 2846 | return 0; |
| 2847 | err_put_ns: |
| 2848 | put_user_ns(ns); |
| 2849 | err: |
| 2850 | return ret; |
| 2851 | } |
| 2852 | |
| 2853 | static int proc_setgroups_release(struct inode *inode, struct file *file) |
| 2854 | { |
| 2855 | struct seq_file *seq = file->private_data; |
| 2856 | struct user_namespace *ns = seq->private; |
| 2857 | int ret = single_release(inode, file); |
| 2858 | put_user_ns(ns); |
| 2859 | return ret; |
| 2860 | } |
| 2861 | |
| 2862 | static const struct file_operations proc_setgroups_operations = { |
| 2863 | .open = proc_setgroups_open, |
| 2864 | .write = proc_setgroups_write, |
| 2865 | .read = seq_read, |
| 2866 | .llseek = seq_lseek, |
| 2867 | .release = proc_setgroups_release, |
| 2868 | }; |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2869 | #endif /* CONFIG_USER_NS */ |
| 2870 | |
Kees Cook | 4783072 | 2008-10-06 03:11:58 +0400 | [diff] [blame] | 2871 | static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns, |
| 2872 | struct pid *pid, struct task_struct *task) |
| 2873 | { |
Al Viro | a9712bc | 2011-03-23 15:52:50 -0400 | [diff] [blame] | 2874 | int err = lock_trace(task); |
| 2875 | if (!err) { |
| 2876 | seq_printf(m, "%08x\n", task->personality); |
| 2877 | unlock_trace(task); |
| 2878 | } |
| 2879 | return err; |
Kees Cook | 4783072 | 2008-10-06 03:11:58 +0400 | [diff] [blame] | 2880 | } |
| 2881 | |
Eric W. Biederman | 801199c | 2006-10-02 02:18:48 -0700 | [diff] [blame] | 2882 | /* |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2883 | * Thread groups |
| 2884 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 2885 | static const struct file_operations proc_task_operations; |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 2886 | static const struct inode_operations proc_task_inode_operations; |
Eric W. Biederman | 20cdc89 | 2006-10-02 02:17:07 -0700 | [diff] [blame] | 2887 | |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 2888 | static const struct pid_entry tgid_base_stuff[] = { |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2889 | DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations), |
| 2890 | DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations), |
Pavel Emelyanov | 640708a | 2012-01-10 15:11:23 -0800 | [diff] [blame] | 2891 | DIR("map_files", S_IRUSR|S_IXUSR, proc_map_files_inode_operations, proc_map_files_operations), |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2892 | DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations), |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 2893 | DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations), |
Andrew Morton | b2211a3 | 2008-03-11 18:03:35 -0700 | [diff] [blame] | 2894 | #ifdef CONFIG_NET |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2895 | DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations), |
Andrew Morton | b2211a3 | 2008-03-11 18:03:35 -0700 | [diff] [blame] | 2896 | #endif |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2897 | REG("environ", S_IRUSR, proc_environ_operations), |
Al Viro | c531716 | 2016-10-05 18:43:43 -0400 | [diff] [blame] | 2898 | REG("auxv", S_IRUSR, proc_auxv_operations), |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2899 | ONE("status", S_IRUGO, proc_pid_status), |
Djalal Harouni | 35a3504 | 2014-04-07 15:38:36 -0700 | [diff] [blame] | 2900 | ONE("personality", S_IRUSR, proc_pid_personality), |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 2901 | ONE("limits", S_IRUGO, proc_pid_limits), |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 2902 | #ifdef CONFIG_SCHED_DEBUG |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2903 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 2904 | #endif |
Mike Galbraith | 5091faa | 2010-11-30 14:18:03 +0100 | [diff] [blame] | 2905 | #ifdef CONFIG_SCHED_AUTOGROUP |
| 2906 | REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations), |
| 2907 | #endif |
john stultz | 4614a696b | 2009-12-14 18:00:05 -0800 | [diff] [blame] | 2908 | REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations), |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 2909 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 2910 | ONE("syscall", S_IRUSR, proc_pid_syscall), |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 2911 | #endif |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 2912 | REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2913 | ONE("stat", S_IRUGO, proc_tgid_stat), |
| 2914 | ONE("statm", S_IRUGO, proc_pid_statm), |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 2915 | REG("maps", S_IRUGO, proc_pid_maps_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2916 | #ifdef CONFIG_NUMA |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 2917 | REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2918 | #endif |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2919 | REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), |
| 2920 | LNK("cwd", proc_cwd_link), |
| 2921 | LNK("root", proc_root_link), |
| 2922 | LNK("exe", proc_exe_link), |
| 2923 | REG("mounts", S_IRUGO, proc_mounts_operations), |
| 2924 | REG("mountinfo", S_IRUGO, proc_mountinfo_operations), |
| 2925 | REG("mountstats", S_IRUSR, proc_mountstats_operations), |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 2926 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2927 | REG("clear_refs", S_IWUSR, proc_clear_refs_operations), |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 2928 | REG("smaps", S_IRUGO, proc_pid_smaps_operations), |
Daniel Colascione | 6668962 | 2017-09-06 16:25:08 -0700 | [diff] [blame] | 2929 | REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), |
Djalal Harouni | 32ed74a | 2014-04-07 15:38:38 -0700 | [diff] [blame] | 2930 | REG("pagemap", S_IRUSR, proc_pagemap_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2931 | #endif |
| 2932 | #ifdef CONFIG_SECURITY |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2933 | DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2934 | #endif |
| 2935 | #ifdef CONFIG_KALLSYMS |
Alexey Dobriyan | edfcd60 | 2014-08-08 14:21:44 -0700 | [diff] [blame] | 2936 | ONE("wchan", S_IRUGO, proc_pid_wchan), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2937 | #endif |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 2938 | #ifdef CONFIG_STACKTRACE |
Djalal Harouni | 35a3504 | 2014-04-07 15:38:36 -0700 | [diff] [blame] | 2939 | ONE("stack", S_IRUSR, proc_pid_stack), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2940 | #endif |
Naveen N. Rao | 5968cec | 2015-06-30 14:36:03 +0530 | [diff] [blame] | 2941 | #ifdef CONFIG_SCHED_INFO |
Alexey Dobriyan | f6e826c | 2014-08-08 14:21:46 -0700 | [diff] [blame] | 2942 | ONE("schedstat", S_IRUGO, proc_pid_schedstat), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2943 | #endif |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 2944 | #ifdef CONFIG_LATENCYTOP |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2945 | REG("latency", S_IRUGO, proc_lstats_operations), |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 2946 | #endif |
Paul Menage | 8793d85 | 2007-10-18 23:39:39 -0700 | [diff] [blame] | 2947 | #ifdef CONFIG_PROC_PID_CPUSET |
Zefan Li | 52de477 | 2014-09-18 16:03:36 +0800 | [diff] [blame] | 2948 | ONE("cpuset", S_IRUGO, proc_cpuset_show), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2949 | #endif |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 2950 | #ifdef CONFIG_CGROUPS |
Zefan Li | 006f4ac | 2014-09-18 16:03:15 +0800 | [diff] [blame] | 2951 | ONE("cgroup", S_IRUGO, proc_cgroup_show), |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 2952 | #endif |
Alexey Dobriyan | 6ba51e3 | 2014-08-08 14:21:48 -0700 | [diff] [blame] | 2953 | ONE("oom_score", S_IRUGO, proc_oom_score), |
Greg Hackmann | 3a6594d | 2017-11-07 13:21:20 -0800 | [diff] [blame] | 2954 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), |
| 2955 | REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2956 | #ifdef CONFIG_AUDITSYSCALL |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2957 | REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), |
| 2958 | REG("sessionid", S_IRUGO, proc_sessionid_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2959 | #endif |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 2960 | #ifdef CONFIG_FAULT_INJECTION |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2961 | REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 2962 | #endif |
Christoph Hellwig | 698ba7b | 2009-12-15 16:47:37 -0800 | [diff] [blame] | 2963 | #ifdef CONFIG_ELF_CORE |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 2964 | REG("coredump_filter", S_IRUGO|S_IWUSR, proc_coredump_filter_operations), |
Kawai, Hidehiro | 3cb4a0b | 2007-07-19 01:48:28 -0700 | [diff] [blame] | 2965 | #endif |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2966 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 2967 | ONE("io", S_IRUSR, proc_tgid_io_accounting), |
Andrew Morton | aba76fd | 2006-12-10 02:19:48 -0800 | [diff] [blame] | 2968 | #endif |
Chris Metcalf | f133ecc | 2011-05-26 12:40:09 -0400 | [diff] [blame] | 2969 | #ifdef CONFIG_HARDWALL |
Alexey Dobriyan | d962c14 | 2014-08-08 14:21:52 -0700 | [diff] [blame] | 2970 | ONE("hardwall", S_IRUGO, proc_pid_hardwall), |
Chris Metcalf | f133ecc | 2011-05-26 12:40:09 -0400 | [diff] [blame] | 2971 | #endif |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2972 | #ifdef CONFIG_USER_NS |
| 2973 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), |
| 2974 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 2975 | REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations), |
Eric W. Biederman | 9cc4651 | 2014-12-02 12:27:26 -0600 | [diff] [blame] | 2976 | REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations), |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 2977 | #endif |
Pavel Emelyanov | 48f6a7a | 2013-03-11 13:12:45 +0400 | [diff] [blame] | 2978 | #ifdef CONFIG_CHECKPOINT_RESTORE |
| 2979 | REG("timers", S_IRUGO, proc_timers_operations), |
| 2980 | #endif |
John Stultz | 5de23d4 | 2016-03-17 14:20:54 -0700 | [diff] [blame] | 2981 | REG("timerslack_ns", S_IRUGO|S_IWUGO, proc_pid_set_timerslack_ns_operations), |
Connor O'Brien | 6e7b83d | 2018-01-31 18:11:57 -0800 | [diff] [blame] | 2982 | #ifdef CONFIG_CPU_FREQ_TIMES |
| 2983 | ONE("time_in_state", 0444, proc_time_in_state_show), |
| 2984 | #endif |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2985 | }; |
| 2986 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2987 | static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2988 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 2989 | return proc_pident_readdir(file, ctx, |
| 2990 | tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff)); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 2993 | static const struct file_operations proc_tgid_base_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2994 | .read = generic_read_dir, |
Al Viro | f50752e | 2016-04-20 17:13:54 -0400 | [diff] [blame] | 2995 | .iterate_shared = proc_tgid_base_readdir, |
| 2996 | .llseek = generic_file_llseek, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 2997 | }; |
| 2998 | |
Christian Brauner | cf9f829 | 2018-11-19 00:51:56 +0100 | [diff] [blame] | 2999 | struct pid *tgid_pidfd_to_pid(const struct file *file) |
| 3000 | { |
| 3001 | if (!d_is_dir(file->f_path.dentry) || |
| 3002 | (file->f_op != &proc_tgid_base_operations)) |
| 3003 | return ERR_PTR(-EBADF); |
| 3004 | |
| 3005 | return proc_pid(file_inode(file)); |
| 3006 | } |
| 3007 | |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 3008 | static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) |
| 3009 | { |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 3010 | return proc_pident_lookup(dir, dentry, |
| 3011 | tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff)); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 3014 | static const struct inode_operations proc_tgid_base_inode_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3015 | .lookup = proc_tgid_base_lookup, |
| 3016 | .getattr = pid_getattr, |
| 3017 | .setattr = proc_setattr, |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 3018 | .permission = proc_pid_permission, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3019 | }; |
| 3020 | |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3021 | static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | { |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3023 | struct dentry *dentry, *leader, *dir; |
Eric W. Biederman | 8578cea | 2006-06-26 00:25:54 -0700 | [diff] [blame] | 3024 | char buf[PROC_NUMBUF]; |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3025 | struct qstr name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3027 | name.name = buf; |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3028 | name.len = snprintf(buf, sizeof(buf), "%d", pid); |
Al Viro | 4f522a2 | 2013-02-11 23:20:37 -0500 | [diff] [blame] | 3029 | /* no ->d_hash() rejects on procfs */ |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3030 | dentry = d_hash_and_lookup(mnt->mnt_root, &name); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3031 | if (dentry) { |
Eric W. Biederman | bbd5192 | 2014-02-13 10:24:23 -0800 | [diff] [blame] | 3032 | d_invalidate(dentry); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3033 | dput(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | |
Oleg Nesterov | c35a7f1 | 2014-12-10 15:54:56 -0800 | [diff] [blame] | 3036 | if (pid == tgid) |
| 3037 | return; |
| 3038 | |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3039 | name.name = buf; |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3040 | name.len = snprintf(buf, sizeof(buf), "%d", tgid); |
| 3041 | leader = d_hash_and_lookup(mnt->mnt_root, &name); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3042 | if (!leader) |
| 3043 | goto out; |
| 3044 | |
| 3045 | name.name = "task"; |
| 3046 | name.len = strlen(name.name); |
| 3047 | dir = d_hash_and_lookup(leader, &name); |
| 3048 | if (!dir) |
| 3049 | goto out_put_leader; |
| 3050 | |
| 3051 | name.name = buf; |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3052 | name.len = snprintf(buf, sizeof(buf), "%d", pid); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3053 | dentry = d_hash_and_lookup(dir, &name); |
| 3054 | if (dentry) { |
Eric W. Biederman | bbd5192 | 2014-02-13 10:24:23 -0800 | [diff] [blame] | 3055 | d_invalidate(dentry); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3056 | dput(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | } |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3058 | |
| 3059 | dput(dir); |
| 3060 | out_put_leader: |
| 3061 | dput(leader); |
| 3062 | out: |
| 3063 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Randy Dunlap | 0895e91 | 2007-10-21 21:00:10 -0700 | [diff] [blame] | 3066 | /** |
| 3067 | * proc_flush_task - Remove dcache entries for @task from the /proc dcache. |
| 3068 | * @task: task that should be flushed. |
| 3069 | * |
| 3070 | * When flushing dentries from proc, one needs to flush them from global |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3071 | * proc (proc_mnt) and from all the namespaces' procs this task was seen |
Randy Dunlap | 0895e91 | 2007-10-21 21:00:10 -0700 | [diff] [blame] | 3072 | * in. This call is supposed to do all of this job. |
| 3073 | * |
| 3074 | * Looks in the dcache for |
| 3075 | * /proc/@pid |
| 3076 | * /proc/@tgid/task/@pid |
| 3077 | * if either directory is present flushes it and all of it'ts children |
| 3078 | * from the dcache. |
| 3079 | * |
| 3080 | * It is safe and reasonable to cache /proc entries for a task until |
| 3081 | * that task exits. After that they just clog up the dcache with |
| 3082 | * useless entries, possibly causing useful dcache entries to be |
| 3083 | * flushed instead. This routine is proved to flush those useless |
| 3084 | * dcache entries at process exit time. |
| 3085 | * |
| 3086 | * NOTE: This routine is just an optimization so it does not guarantee |
| 3087 | * that no dcache entries will exist at process exit time it |
| 3088 | * just makes it very unlikely that any will persist. |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3089 | */ |
| 3090 | |
| 3091 | void proc_flush_task(struct task_struct *task) |
| 3092 | { |
Eric W. Biederman | 9fcc2d1 | 2007-11-14 17:00:07 -0800 | [diff] [blame] | 3093 | int i; |
Oleg Nesterov | 9b4d1cbe | 2009-09-22 16:45:34 -0700 | [diff] [blame] | 3094 | struct pid *pid, *tgid; |
Pavel Emelyanov | 130f77e | 2007-10-18 23:40:11 -0700 | [diff] [blame] | 3095 | struct upid *upid; |
| 3096 | |
Pavel Emelyanov | 130f77e | 2007-10-18 23:40:11 -0700 | [diff] [blame] | 3097 | pid = task_pid(task); |
Oleg Nesterov | 9b4d1cbe | 2009-09-22 16:45:34 -0700 | [diff] [blame] | 3098 | tgid = task_tgid(task); |
Pavel Emelyanov | 130f77e | 2007-10-18 23:40:11 -0700 | [diff] [blame] | 3099 | |
Eric W. Biederman | 9fcc2d1 | 2007-11-14 17:00:07 -0800 | [diff] [blame] | 3100 | for (i = 0; i <= pid->level; i++) { |
Pavel Emelyanov | 130f77e | 2007-10-18 23:40:11 -0700 | [diff] [blame] | 3101 | upid = &pid->numbers[i]; |
| 3102 | proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr, |
Oleg Nesterov | 9b4d1cbe | 2009-09-22 16:45:34 -0700 | [diff] [blame] | 3103 | tgid->numbers[i].nr); |
Pavel Emelyanov | 130f77e | 2007-10-18 23:40:11 -0700 | [diff] [blame] | 3104 | } |
Pavel Emelyanov | 60347f6 | 2007-10-18 23:40:03 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3107 | static int proc_pid_instantiate(struct inode *dir, |
| 3108 | struct dentry * dentry, |
| 3109 | struct task_struct *task, const void *ptr) |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3110 | { |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3111 | struct inode *inode; |
| 3112 | |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3113 | inode = proc_pid_make_inode(dir->i_sb, task); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3114 | if (!inode) |
| 3115 | goto out; |
| 3116 | |
| 3117 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; |
| 3118 | inode->i_op = &proc_tgid_base_inode_operations; |
| 3119 | inode->i_fop = &proc_tgid_base_operations; |
| 3120 | inode->i_flags|=S_IMMUTABLE; |
Vegard Nossum | aed5417 | 2008-06-05 22:46:53 -0700 | [diff] [blame] | 3121 | |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 3122 | set_nlink(inode, 2 + pid_entry_count_dirs(tgid_base_stuff, |
| 3123 | ARRAY_SIZE(tgid_base_stuff))); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3124 | |
Nick Piggin | fb045ad | 2011-01-07 17:49:55 +1100 | [diff] [blame] | 3125 | d_set_d_op(dentry, &pid_dentry_operations); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3126 | |
| 3127 | d_add(dentry, inode); |
| 3128 | /* Close the race of the process dying before we return the dentry */ |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 3129 | if (pid_revalidate(dentry, 0)) |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3130 | return 0; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3131 | out: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3132 | return -ENOENT; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 3135 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | { |
Alexey Dobriyan | 335eb53 | 2014-08-08 14:21:27 -0700 | [diff] [blame] | 3137 | int result = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | struct task_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | unsigned tgid; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3140 | struct pid_namespace *ns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 3142 | tgid = name_to_int(&dentry->d_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | if (tgid == ~0U) |
| 3144 | goto out; |
| 3145 | |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3146 | ns = dentry->d_sb->s_fs_info; |
Eric W. Biederman | de75873 | 2006-06-26 00:25:51 -0700 | [diff] [blame] | 3147 | rcu_read_lock(); |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3148 | task = find_task_by_pid_ns(tgid, ns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | if (task) |
| 3150 | get_task_struct(task); |
Eric W. Biederman | de75873 | 2006-06-26 00:25:51 -0700 | [diff] [blame] | 3151 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | if (!task) |
| 3153 | goto out; |
| 3154 | |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3155 | result = proc_pid_instantiate(dir, dentry, task, NULL); |
Eric W. Biederman | 48e6484 | 2006-06-26 00:25:48 -0700 | [diff] [blame] | 3156 | put_task_struct(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | out: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3158 | return ERR_PTR(result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | /* |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3162 | * Find the first task with tgid >= tgid |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3163 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | */ |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3165 | struct tgid_iter { |
| 3166 | unsigned int tgid; |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3167 | struct task_struct *task; |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3168 | }; |
| 3169 | static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter iter) |
| 3170 | { |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3171 | struct pid *pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3173 | if (iter.task) |
| 3174 | put_task_struct(iter.task); |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3175 | rcu_read_lock(); |
| 3176 | retry: |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3177 | iter.task = NULL; |
| 3178 | pid = find_ge_pid(iter.tgid, ns); |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3179 | if (pid) { |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3180 | iter.tgid = pid_nr_ns(pid, ns); |
| 3181 | iter.task = pid_task(pid, PIDTYPE_PID); |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3182 | /* What we to know is if the pid we have find is the |
| 3183 | * pid of a thread_group_leader. Testing for task |
| 3184 | * being a thread_group_leader is the obvious thing |
| 3185 | * todo but there is a window when it fails, due to |
| 3186 | * the pid transfer logic in de_thread. |
| 3187 | * |
| 3188 | * So we perform the straight forward test of seeing |
| 3189 | * if the pid we have found is the pid of a thread |
| 3190 | * group leader, and don't worry if the task we have |
| 3191 | * found doesn't happen to be a thread group leader. |
| 3192 | * As we don't care in the case of readdir. |
| 3193 | */ |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3194 | if (!iter.task || !has_group_leader_pid(iter.task)) { |
| 3195 | iter.tgid += 1; |
Eric W. Biederman | 0804ef4 | 2006-10-02 02:17:04 -0700 | [diff] [blame] | 3196 | goto retry; |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3197 | } |
| 3198 | get_task_struct(iter.task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | } |
Eric W. Biederman | 454cc10 | 2006-06-26 00:25:51 -0700 | [diff] [blame] | 3200 | rcu_read_unlock(); |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3201 | return iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 3204 | #define TGID_OFFSET (FIRST_PROCESS_ENTRY + 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | |
| 3206 | /* for the /proc/ directory itself, after non-process stuff has been done */ |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3207 | int proc_pid_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | { |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3209 | struct tgid_iter iter; |
Al Viro | 3aa3377 | 2014-10-31 00:42:35 -0400 | [diff] [blame] | 3210 | struct pid_namespace *ns = file_inode(file)->i_sb->s_fs_info; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3211 | loff_t pos = ctx->pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Al Viro | 021ada7 | 2013-03-29 19:27:05 -0400 | [diff] [blame] | 3213 | if (pos >= PID_MAX_LIMIT + TGID_OFFSET) |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 3216 | if (pos == TGID_OFFSET - 2) { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3217 | struct inode *inode = d_inode(ns->proc_self); |
Al Viro | db96316 | 2013-06-15 10:45:10 +0400 | [diff] [blame] | 3218 | if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK)) |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3219 | return 0; |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 3220 | ctx->pos = pos = pos + 1; |
Al Viro | 021ada7 | 2013-03-29 19:27:05 -0400 | [diff] [blame] | 3221 | } |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 3222 | if (pos == TGID_OFFSET - 1) { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3223 | struct inode *inode = d_inode(ns->proc_thread_self); |
Eric W. Biederman | 0097875 | 2014-07-31 03:10:50 -0700 | [diff] [blame] | 3224 | if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK)) |
| 3225 | return 0; |
| 3226 | ctx->pos = pos = pos + 1; |
| 3227 | } |
| 3228 | iter.tgid = pos - TGID_OFFSET; |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3229 | iter.task = NULL; |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3230 | for (iter = next_tgid(ns, iter); |
| 3231 | iter.task; |
| 3232 | iter.tgid += 1, iter = next_tgid(ns, iter)) { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3233 | char name[PROC_NUMBUF]; |
| 3234 | int len; |
Eric Dumazet | 9618fba | 2017-01-24 15:18:07 -0800 | [diff] [blame] | 3235 | |
| 3236 | cond_resched(); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3237 | if (!has_pid_permissions(ns, iter.task, 2)) |
| 3238 | continue; |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 3239 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3240 | len = snprintf(name, sizeof(name), "%d", iter.tgid); |
| 3241 | ctx->pos = iter.tgid + TGID_OFFSET; |
| 3242 | if (!proc_fill_cache(file, ctx, name, len, |
| 3243 | proc_pid_instantiate, iter.task, NULL)) { |
Eric W. Biederman | 19fd4bb | 2007-11-28 16:21:26 -0800 | [diff] [blame] | 3244 | put_task_struct(iter.task); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3245 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3248 | ctx->pos = PID_MAX_LIMIT + TGID_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | return 0; |
| 3250 | } |
| 3251 | |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3252 | /* |
Janis Danisevskis | 1b3044e | 2016-05-20 17:00:08 -0700 | [diff] [blame] | 3253 | * proc_tid_comm_permission is a special permission function exclusively |
| 3254 | * used for the node /proc/<pid>/task/<tid>/comm. |
| 3255 | * It bypasses generic permission checks in the case where a task of the same |
| 3256 | * task group attempts to access the node. |
| 3257 | * The rationale behind this is that glibc and bionic access this node for |
| 3258 | * cross thread naming (pthread_set/getname_np(!self)). However, if |
| 3259 | * PR_SET_DUMPABLE gets set to 0 this node among others becomes uid=0 gid=0, |
| 3260 | * which locks out the cross thread naming implementation. |
| 3261 | * This function makes sure that the node is always accessible for members of |
| 3262 | * same thread group. |
| 3263 | */ |
| 3264 | static int proc_tid_comm_permission(struct inode *inode, int mask) |
| 3265 | { |
| 3266 | bool is_same_tgroup; |
| 3267 | struct task_struct *task; |
| 3268 | |
| 3269 | task = get_proc_task(inode); |
| 3270 | if (!task) |
| 3271 | return -ESRCH; |
| 3272 | is_same_tgroup = same_thread_group(current, task); |
| 3273 | put_task_struct(task); |
| 3274 | |
| 3275 | if (likely(is_same_tgroup && !(mask & MAY_EXEC))) { |
| 3276 | /* This file (/proc/<pid>/task/<tid>/comm) can always be |
| 3277 | * read or written by the members of the corresponding |
| 3278 | * thread group. |
| 3279 | */ |
| 3280 | return 0; |
| 3281 | } |
| 3282 | |
| 3283 | return generic_permission(inode, mask); |
| 3284 | } |
| 3285 | |
| 3286 | static const struct inode_operations proc_tid_comm_inode_operations = { |
| 3287 | .permission = proc_tid_comm_permission, |
| 3288 | }; |
| 3289 | |
| 3290 | /* |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3291 | * Tasks |
| 3292 | */ |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 3293 | static const struct pid_entry tid_base_stuff[] = { |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3294 | DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations), |
Jerome Marchand | 3835541 | 2010-04-27 13:13:06 -0700 | [diff] [blame] | 3295 | DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations), |
Eric W. Biederman | 6b4e306 | 2010-03-07 16:41:34 -0800 | [diff] [blame] | 3296 | DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations), |
Eric W. Biederman | 6ba8ed7 | 2014-07-31 16:27:08 -0700 | [diff] [blame] | 3297 | #ifdef CONFIG_NET |
| 3298 | DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations), |
| 3299 | #endif |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3300 | REG("environ", S_IRUSR, proc_environ_operations), |
Al Viro | c531716 | 2016-10-05 18:43:43 -0400 | [diff] [blame] | 3301 | REG("auxv", S_IRUSR, proc_auxv_operations), |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3302 | ONE("status", S_IRUGO, proc_pid_status), |
Djalal Harouni | 35a3504 | 2014-04-07 15:38:36 -0700 | [diff] [blame] | 3303 | ONE("personality", S_IRUSR, proc_pid_personality), |
Alexey Dobriyan | 1c963eb | 2014-08-08 14:21:37 -0700 | [diff] [blame] | 3304 | ONE("limits", S_IRUGO, proc_pid_limits), |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 3305 | #ifdef CONFIG_SCHED_DEBUG |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3306 | REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), |
Ingo Molnar | 43ae34c | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 3307 | #endif |
Janis Danisevskis | 1b3044e | 2016-05-20 17:00:08 -0700 | [diff] [blame] | 3308 | NOD("comm", S_IFREG|S_IRUGO|S_IWUSR, |
| 3309 | &proc_tid_comm_inode_operations, |
| 3310 | &proc_pid_set_comm_operations, {}), |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 3311 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK |
Alexey Dobriyan | 09d93bd | 2014-08-08 14:21:39 -0700 | [diff] [blame] | 3312 | ONE("syscall", S_IRUSR, proc_pid_syscall), |
Roland McGrath | ebcb673 | 2008-07-25 19:46:00 -0700 | [diff] [blame] | 3313 | #endif |
Alexey Dobriyan | c2c0bb4 | 2015-06-25 15:00:54 -0700 | [diff] [blame] | 3314 | REG("cmdline", S_IRUGO, proc_pid_cmdline_ops), |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3315 | ONE("stat", S_IRUGO, proc_tid_stat), |
| 3316 | ONE("statm", S_IRUGO, proc_pid_statm), |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 3317 | REG("maps", S_IRUGO, proc_tid_maps_operations), |
Iago López Galeiras | 2e13ba5 | 2015-06-25 15:00:57 -0700 | [diff] [blame] | 3318 | #ifdef CONFIG_PROC_CHILDREN |
Cyrill Gorcunov | 81841161 | 2012-05-31 16:26:43 -0700 | [diff] [blame] | 3319 | REG("children", S_IRUGO, proc_tid_children_operations), |
| 3320 | #endif |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3321 | #ifdef CONFIG_NUMA |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 3322 | REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3323 | #endif |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3324 | REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations), |
| 3325 | LNK("cwd", proc_cwd_link), |
| 3326 | LNK("root", proc_root_link), |
| 3327 | LNK("exe", proc_exe_link), |
| 3328 | REG("mounts", S_IRUGO, proc_mounts_operations), |
| 3329 | REG("mountinfo", S_IRUGO, proc_mountinfo_operations), |
Matt Mackall | 1e88328 | 2008-02-04 22:29:07 -0800 | [diff] [blame] | 3330 | #ifdef CONFIG_PROC_PAGE_MONITOR |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3331 | REG("clear_refs", S_IWUSR, proc_clear_refs_operations), |
Siddhesh Poyarekar | b764375 | 2012-03-21 16:34:04 -0700 | [diff] [blame] | 3332 | REG("smaps", S_IRUGO, proc_tid_smaps_operations), |
Daniel Colascione | 6668962 | 2017-09-06 16:25:08 -0700 | [diff] [blame] | 3333 | REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations), |
Djalal Harouni | 32ed74a | 2014-04-07 15:38:38 -0700 | [diff] [blame] | 3334 | REG("pagemap", S_IRUSR, proc_pagemap_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3335 | #endif |
| 3336 | #ifdef CONFIG_SECURITY |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3337 | DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3338 | #endif |
| 3339 | #ifdef CONFIG_KALLSYMS |
Alexey Dobriyan | edfcd60 | 2014-08-08 14:21:44 -0700 | [diff] [blame] | 3340 | ONE("wchan", S_IRUGO, proc_pid_wchan), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3341 | #endif |
Ken Chen | 2ec220e | 2008-11-10 11:26:08 +0300 | [diff] [blame] | 3342 | #ifdef CONFIG_STACKTRACE |
Djalal Harouni | 35a3504 | 2014-04-07 15:38:36 -0700 | [diff] [blame] | 3343 | ONE("stack", S_IRUSR, proc_pid_stack), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3344 | #endif |
Naveen N. Rao | 5968cec | 2015-06-30 14:36:03 +0530 | [diff] [blame] | 3345 | #ifdef CONFIG_SCHED_INFO |
Alexey Dobriyan | f6e826c | 2014-08-08 14:21:46 -0700 | [diff] [blame] | 3346 | ONE("schedstat", S_IRUGO, proc_pid_schedstat), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3347 | #endif |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 3348 | #ifdef CONFIG_LATENCYTOP |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3349 | REG("latency", S_IRUGO, proc_lstats_operations), |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 3350 | #endif |
Paul Menage | 8793d85 | 2007-10-18 23:39:39 -0700 | [diff] [blame] | 3351 | #ifdef CONFIG_PROC_PID_CPUSET |
Zefan Li | 52de477 | 2014-09-18 16:03:36 +0800 | [diff] [blame] | 3352 | ONE("cpuset", S_IRUGO, proc_cpuset_show), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3353 | #endif |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 3354 | #ifdef CONFIG_CGROUPS |
Zefan Li | 006f4ac | 2014-09-18 16:03:15 +0800 | [diff] [blame] | 3355 | ONE("cgroup", S_IRUGO, proc_cgroup_show), |
Paul Menage | a424316 | 2007-10-18 23:39:35 -0700 | [diff] [blame] | 3356 | #endif |
Alexey Dobriyan | 6ba51e3 | 2014-08-08 14:21:48 -0700 | [diff] [blame] | 3357 | ONE("oom_score", S_IRUGO, proc_oom_score), |
Greg Hackmann | 3a6594d | 2017-11-07 13:21:20 -0800 | [diff] [blame] | 3358 | REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations), |
| 3359 | REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3360 | #ifdef CONFIG_AUDITSYSCALL |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3361 | REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), |
Al Viro | 26ec3c6 | 2011-02-15 21:24:05 -0500 | [diff] [blame] | 3362 | REG("sessionid", S_IRUGO, proc_sessionid_operations), |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3363 | #endif |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 3364 | #ifdef CONFIG_FAULT_INJECTION |
Alexey Dobriyan | 631f9c1 | 2008-11-10 01:32:52 +0300 | [diff] [blame] | 3365 | REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 3366 | #endif |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 3367 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
Alexey Dobriyan | 19aadc9 | 2014-08-08 14:21:50 -0700 | [diff] [blame] | 3368 | ONE("io", S_IRUSR, proc_tid_io_accounting), |
Andrea Righi | 297c5d9 | 2008-07-25 01:48:49 -0700 | [diff] [blame] | 3369 | #endif |
Chris Metcalf | f133ecc | 2011-05-26 12:40:09 -0400 | [diff] [blame] | 3370 | #ifdef CONFIG_HARDWALL |
Alexey Dobriyan | d962c14 | 2014-08-08 14:21:52 -0700 | [diff] [blame] | 3371 | ONE("hardwall", S_IRUGO, proc_pid_hardwall), |
Chris Metcalf | f133ecc | 2011-05-26 12:40:09 -0400 | [diff] [blame] | 3372 | #endif |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 3373 | #ifdef CONFIG_USER_NS |
| 3374 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), |
| 3375 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), |
Eric W. Biederman | f76d207 | 2012-08-30 01:24:05 -0700 | [diff] [blame] | 3376 | REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations), |
Eric W. Biederman | 9cc4651 | 2014-12-02 12:27:26 -0600 | [diff] [blame] | 3377 | REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations), |
Eric W. Biederman | 22d917d | 2011-11-17 00:11:58 -0800 | [diff] [blame] | 3378 | #endif |
Connor O'Brien | 6e7b83d | 2018-01-31 18:11:57 -0800 | [diff] [blame] | 3379 | #ifdef CONFIG_CPU_FREQ_TIMES |
| 3380 | ONE("time_in_state", 0444, proc_time_in_state_show), |
| 3381 | #endif |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3382 | }; |
| 3383 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3384 | static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3385 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3386 | return proc_pident_readdir(file, ctx, |
| 3387 | tid_base_stuff, ARRAY_SIZE(tid_base_stuff)); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 3390 | static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) |
| 3391 | { |
Eric W. Biederman | 7bcd6b0 | 2006-10-02 02:18:56 -0700 | [diff] [blame] | 3392 | return proc_pident_lookup(dir, dentry, |
| 3393 | tid_base_stuff, ARRAY_SIZE(tid_base_stuff)); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 3396 | static const struct file_operations proc_tid_base_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3397 | .read = generic_read_dir, |
Al Viro | f50752e | 2016-04-20 17:13:54 -0400 | [diff] [blame] | 3398 | .iterate_shared = proc_tid_base_readdir, |
| 3399 | .llseek = generic_file_llseek, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3400 | }; |
| 3401 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 3402 | static const struct inode_operations proc_tid_base_inode_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3403 | .lookup = proc_tid_base_lookup, |
| 3404 | .getattr = pid_getattr, |
| 3405 | .setattr = proc_setattr, |
| 3406 | }; |
| 3407 | |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3408 | static int proc_task_instantiate(struct inode *dir, |
Eric Dumazet | c5141e6 | 2007-05-08 00:26:15 -0700 | [diff] [blame] | 3409 | struct dentry *dentry, struct task_struct *task, const void *ptr) |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3410 | { |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3411 | struct inode *inode; |
Eric W. Biederman | 61a2878 | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3412 | inode = proc_pid_make_inode(dir->i_sb, task); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3413 | |
| 3414 | if (!inode) |
| 3415 | goto out; |
| 3416 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; |
| 3417 | inode->i_op = &proc_tid_base_inode_operations; |
| 3418 | inode->i_fop = &proc_tid_base_operations; |
| 3419 | inode->i_flags|=S_IMMUTABLE; |
Vegard Nossum | aed5417 | 2008-06-05 22:46:53 -0700 | [diff] [blame] | 3420 | |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 3421 | set_nlink(inode, 2 + pid_entry_count_dirs(tid_base_stuff, |
| 3422 | ARRAY_SIZE(tid_base_stuff))); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3423 | |
Nick Piggin | fb045ad | 2011-01-07 17:49:55 +1100 | [diff] [blame] | 3424 | d_set_d_op(dentry, &pid_dentry_operations); |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3425 | |
| 3426 | d_add(dentry, inode); |
| 3427 | /* Close the race of the process dying before we return the dentry */ |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 3428 | if (pid_revalidate(dentry, 0)) |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3429 | return 0; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3430 | out: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3431 | return -ENOENT; |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 3434 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3435 | { |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3436 | int result = -ENOENT; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3437 | struct task_struct *task; |
| 3438 | struct task_struct *leader = get_proc_task(dir); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3439 | unsigned tid; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3440 | struct pid_namespace *ns; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3441 | |
| 3442 | if (!leader) |
| 3443 | goto out_no_task; |
| 3444 | |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 3445 | tid = name_to_int(&dentry->d_name); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3446 | if (tid == ~0U) |
| 3447 | goto out; |
| 3448 | |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3449 | ns = dentry->d_sb->s_fs_info; |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3450 | rcu_read_lock(); |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3451 | task = find_task_by_pid_ns(tid, ns); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3452 | if (task) |
| 3453 | get_task_struct(task); |
| 3454 | rcu_read_unlock(); |
| 3455 | if (!task) |
| 3456 | goto out; |
Pavel Emelyanov | bac0abd | 2007-10-18 23:40:18 -0700 | [diff] [blame] | 3457 | if (!same_thread_group(leader, task)) |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3458 | goto out_drop_task; |
| 3459 | |
Eric W. Biederman | 444ceed | 2006-10-02 02:18:49 -0700 | [diff] [blame] | 3460 | result = proc_task_instantiate(dir, dentry, task, NULL); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3461 | out_drop_task: |
| 3462 | put_task_struct(task); |
| 3463 | out: |
| 3464 | put_task_struct(leader); |
| 3465 | out_no_task: |
Al Viro | c52a47a | 2013-06-15 11:15:20 +0400 | [diff] [blame] | 3466 | return ERR_PTR(result); |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /* |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3470 | * Find the first tid of a thread group to return to user space. |
| 3471 | * |
| 3472 | * Usually this is just the thread group leader, but if the users |
| 3473 | * buffer was too small or there was a seek into the middle of the |
| 3474 | * directory we have more work todo. |
| 3475 | * |
| 3476 | * In the case of a short read we start with find_task_by_pid. |
| 3477 | * |
| 3478 | * In the case of a seek we start with the leader and walk nr |
| 3479 | * threads past it. |
| 3480 | */ |
Oleg Nesterov | 9f6e963 | 2014-01-23 15:55:40 -0800 | [diff] [blame] | 3481 | static struct task_struct *first_tid(struct pid *pid, int tid, loff_t f_pos, |
| 3482 | struct pid_namespace *ns) |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3483 | { |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3484 | struct task_struct *pos, *task; |
Oleg Nesterov | 9f6e963 | 2014-01-23 15:55:40 -0800 | [diff] [blame] | 3485 | unsigned long nr = f_pos; |
| 3486 | |
| 3487 | if (nr != f_pos) /* 32bit overflow? */ |
| 3488 | return NULL; |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3489 | |
Eric W. Biederman | cc28873 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3490 | rcu_read_lock(); |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3491 | task = pid_task(pid, PIDTYPE_PID); |
| 3492 | if (!task) |
| 3493 | goto fail; |
| 3494 | |
| 3495 | /* Attempt to start with the tid of a thread */ |
Oleg Nesterov | 9f6e963 | 2014-01-23 15:55:40 -0800 | [diff] [blame] | 3496 | if (tid && nr) { |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3497 | pos = find_task_by_pid_ns(tid, ns); |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3498 | if (pos && same_thread_group(pos, task)) |
Oleg Nesterov | a872ff0 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3499 | goto found; |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | /* If nr exceeds the number of threads there is nothing todo */ |
Oleg Nesterov | 9f6e963 | 2014-01-23 15:55:40 -0800 | [diff] [blame] | 3503 | if (nr >= get_nr_threads(task)) |
Oleg Nesterov | c986c14 | 2014-01-23 15:55:38 -0800 | [diff] [blame] | 3504 | goto fail; |
Oleg Nesterov | a872ff0 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3505 | |
| 3506 | /* If we haven't found our starting place yet start |
| 3507 | * with the leader and walk nr threads forward. |
| 3508 | */ |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3509 | pos = task = task->group_leader; |
Oleg Nesterov | c986c14 | 2014-01-23 15:55:38 -0800 | [diff] [blame] | 3510 | do { |
Oleg Nesterov | 9f6e963 | 2014-01-23 15:55:40 -0800 | [diff] [blame] | 3511 | if (!nr--) |
Oleg Nesterov | c986c14 | 2014-01-23 15:55:38 -0800 | [diff] [blame] | 3512 | goto found; |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3513 | } while_each_thread(task, pos); |
Oleg Nesterov | c986c14 | 2014-01-23 15:55:38 -0800 | [diff] [blame] | 3514 | fail: |
| 3515 | pos = NULL; |
| 3516 | goto out; |
Oleg Nesterov | a872ff0 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3517 | found: |
| 3518 | get_task_struct(pos); |
| 3519 | out: |
Eric W. Biederman | cc28873 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3520 | rcu_read_unlock(); |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3521 | return pos; |
| 3522 | } |
| 3523 | |
| 3524 | /* |
| 3525 | * Find the next thread in the thread list. |
| 3526 | * Return NULL if there is an error or no next thread. |
| 3527 | * |
| 3528 | * The reference to the input task_struct is released. |
| 3529 | */ |
| 3530 | static struct task_struct *next_tid(struct task_struct *start) |
| 3531 | { |
Oleg Nesterov | c1df7fb | 2006-06-26 00:26:02 -0700 | [diff] [blame] | 3532 | struct task_struct *pos = NULL; |
Eric W. Biederman | cc28873 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3533 | rcu_read_lock(); |
Oleg Nesterov | c1df7fb | 2006-06-26 00:26:02 -0700 | [diff] [blame] | 3534 | if (pid_alive(start)) { |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3535 | pos = next_thread(start); |
Oleg Nesterov | c1df7fb | 2006-06-26 00:26:02 -0700 | [diff] [blame] | 3536 | if (thread_group_leader(pos)) |
| 3537 | pos = NULL; |
| 3538 | else |
| 3539 | get_task_struct(pos); |
| 3540 | } |
Eric W. Biederman | cc28873 | 2006-06-26 00:26:01 -0700 | [diff] [blame] | 3541 | rcu_read_unlock(); |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3542 | put_task_struct(start); |
| 3543 | return pos; |
| 3544 | } |
| 3545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | /* for the /proc/TGID/task/ directories */ |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3547 | static int proc_task_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | { |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3549 | struct inode *inode = file_inode(file); |
| 3550 | struct task_struct *task; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3551 | struct pid_namespace *ns; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3552 | int tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3554 | if (proc_inode_is_dead(inode)) |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3555 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3557 | if (!dir_emit_dots(file, ctx)) |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3558 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3560 | /* f_version caches the tgid value that the last readdir call couldn't |
| 3561 | * return. lseek aka telldir automagically resets f_version to 0. |
| 3562 | */ |
Al Viro | 3aa3377 | 2014-10-31 00:42:35 -0400 | [diff] [blame] | 3563 | ns = inode->i_sb->s_fs_info; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3564 | tid = (int)file->f_version; |
| 3565 | file->f_version = 0; |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3566 | for (task = first_tid(proc_pid(inode), tid, ctx->pos - 2, ns); |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3567 | task; |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3568 | task = next_tid(task), ctx->pos++) { |
| 3569 | char name[PROC_NUMBUF]; |
| 3570 | int len; |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 3571 | tid = task_pid_nr_ns(task, ns); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3572 | len = snprintf(name, sizeof(name), "%d", tid); |
| 3573 | if (!proc_fill_cache(file, ctx, name, len, |
| 3574 | proc_task_instantiate, task, NULL)) { |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3575 | /* returning this tgid failed, save it as the first |
| 3576 | * pid for the next readir call */ |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3577 | file->f_version = (u64)tid; |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3578 | put_task_struct(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | break; |
Eric W. Biederman | 0bc58a9 | 2006-06-26 00:25:50 -0700 | [diff] [blame] | 3580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | } |
Oleg Nesterov | d855a4b | 2014-01-23 15:55:39 -0800 | [diff] [blame] | 3582 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 3583 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | } |
Eric W. Biederman | 6e66b52 | 2006-06-26 00:25:47 -0700 | [diff] [blame] | 3585 | |
| 3586 | static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) |
| 3587 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 3588 | struct inode *inode = d_inode(dentry); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 3589 | struct task_struct *p = get_proc_task(inode); |
Eric W. Biederman | 6e66b52 | 2006-06-26 00:25:47 -0700 | [diff] [blame] | 3590 | generic_fillattr(inode, stat); |
| 3591 | |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 3592 | if (p) { |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 3593 | stat->nlink += get_nr_threads(p); |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 3594 | put_task_struct(p); |
Eric W. Biederman | 6e66b52 | 2006-06-26 00:25:47 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | return 0; |
| 3598 | } |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3599 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 3600 | static const struct inode_operations proc_task_inode_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3601 | .lookup = proc_task_lookup, |
| 3602 | .getattr = proc_task_getattr, |
| 3603 | .setattr = proc_setattr, |
Vasiliy Kulikov | 0499680 | 2012-01-10 15:11:31 -0800 | [diff] [blame] | 3604 | .permission = proc_pid_permission, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3605 | }; |
| 3606 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 3607 | static const struct file_operations proc_task_operations = { |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3608 | .read = generic_read_dir, |
Al Viro | f50752e | 2016-04-20 17:13:54 -0400 | [diff] [blame] | 3609 | .iterate_shared = proc_task_readdir, |
| 3610 | .llseek = generic_file_llseek, |
Eric W. Biederman | 28a6d67 | 2006-10-02 02:17:05 -0700 | [diff] [blame] | 3611 | }; |