Commit 456be6cd90dbbb9b0ea01d56932d56d110d51cf7
1 parent
37509e749d
Exists in
master
and in
7 other branches
[AUDIT] LOGIN message credentials
Attached is a new patch that solves the issue of getting valid credentials into the LOGIN message. The current code was assuming that the audit context had already been copied. This is not always the case for LOGIN messages. To solve the problem, the patch passes the task struct to the function that emits the message where it can get valid credentials. Signed-off-by: Steve Grubb <sgrubb@redhat.com> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Showing 3 changed files with 7 additions and 6 deletions Inline Diff
fs/proc/base.c
1 | /* | 1 | /* |
2 | * linux/fs/proc/base.c | 2 | * linux/fs/proc/base.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
5 | * | 5 | * |
6 | * proc base directory handling functions | 6 | * proc base directory handling functions |
7 | * | 7 | * |
8 | * 1999, Al Viro. Rewritten. Now it covers the whole per-process part. | 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 | 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 | 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. | 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 | 12 | * Eventually it should become a filesystem in its own. We don't use the |
13 | * rest of procfs anymore. | 13 | * rest of procfs anymore. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
17 | 17 | ||
18 | #include <linux/config.h> | 18 | #include <linux/config.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/time.h> | 20 | #include <linux/time.h> |
21 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
22 | #include <linux/stat.h> | 22 | #include <linux/stat.h> |
23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
24 | #include <linux/file.h> | 24 | #include <linux/file.h> |
25 | #include <linux/string.h> | 25 | #include <linux/string.h> |
26 | #include <linux/seq_file.h> | 26 | #include <linux/seq_file.h> |
27 | #include <linux/namei.h> | 27 | #include <linux/namei.h> |
28 | #include <linux/namespace.h> | 28 | #include <linux/namespace.h> |
29 | #include <linux/mm.h> | 29 | #include <linux/mm.h> |
30 | #include <linux/smp_lock.h> | 30 | #include <linux/smp_lock.h> |
31 | #include <linux/kallsyms.h> | 31 | #include <linux/kallsyms.h> |
32 | #include <linux/mount.h> | 32 | #include <linux/mount.h> |
33 | #include <linux/security.h> | 33 | #include <linux/security.h> |
34 | #include <linux/ptrace.h> | 34 | #include <linux/ptrace.h> |
35 | #include <linux/seccomp.h> | 35 | #include <linux/seccomp.h> |
36 | #include <linux/cpuset.h> | 36 | #include <linux/cpuset.h> |
37 | #include <linux/audit.h> | 37 | #include <linux/audit.h> |
38 | #include "internal.h" | 38 | #include "internal.h" |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * For hysterical raisins we keep the same inumbers as in the old procfs. | 41 | * For hysterical raisins we keep the same inumbers as in the old procfs. |
42 | * Feel free to change the macro below - just keep the range distinct from | 42 | * Feel free to change the macro below - just keep the range distinct from |
43 | * inumbers of the rest of procfs (currently those are in 0x0000--0xffff). | 43 | * inumbers of the rest of procfs (currently those are in 0x0000--0xffff). |
44 | * As soon as we'll get a separate superblock we will be able to forget | 44 | * As soon as we'll get a separate superblock we will be able to forget |
45 | * about magical ranges too. | 45 | * about magical ranges too. |
46 | */ | 46 | */ |
47 | 47 | ||
48 | #define fake_ino(pid,ino) (((pid)<<16)|(ino)) | 48 | #define fake_ino(pid,ino) (((pid)<<16)|(ino)) |
49 | 49 | ||
50 | enum pid_directory_inos { | 50 | enum pid_directory_inos { |
51 | PROC_TGID_INO = 2, | 51 | PROC_TGID_INO = 2, |
52 | PROC_TGID_TASK, | 52 | PROC_TGID_TASK, |
53 | PROC_TGID_STATUS, | 53 | PROC_TGID_STATUS, |
54 | PROC_TGID_MEM, | 54 | PROC_TGID_MEM, |
55 | #ifdef CONFIG_SECCOMP | 55 | #ifdef CONFIG_SECCOMP |
56 | PROC_TGID_SECCOMP, | 56 | PROC_TGID_SECCOMP, |
57 | #endif | 57 | #endif |
58 | PROC_TGID_CWD, | 58 | PROC_TGID_CWD, |
59 | PROC_TGID_ROOT, | 59 | PROC_TGID_ROOT, |
60 | PROC_TGID_EXE, | 60 | PROC_TGID_EXE, |
61 | PROC_TGID_FD, | 61 | PROC_TGID_FD, |
62 | PROC_TGID_ENVIRON, | 62 | PROC_TGID_ENVIRON, |
63 | PROC_TGID_AUXV, | 63 | PROC_TGID_AUXV, |
64 | PROC_TGID_CMDLINE, | 64 | PROC_TGID_CMDLINE, |
65 | PROC_TGID_STAT, | 65 | PROC_TGID_STAT, |
66 | PROC_TGID_STATM, | 66 | PROC_TGID_STATM, |
67 | PROC_TGID_MAPS, | 67 | PROC_TGID_MAPS, |
68 | PROC_TGID_MOUNTS, | 68 | PROC_TGID_MOUNTS, |
69 | PROC_TGID_WCHAN, | 69 | PROC_TGID_WCHAN, |
70 | #ifdef CONFIG_SCHEDSTATS | 70 | #ifdef CONFIG_SCHEDSTATS |
71 | PROC_TGID_SCHEDSTAT, | 71 | PROC_TGID_SCHEDSTAT, |
72 | #endif | 72 | #endif |
73 | #ifdef CONFIG_CPUSETS | 73 | #ifdef CONFIG_CPUSETS |
74 | PROC_TGID_CPUSET, | 74 | PROC_TGID_CPUSET, |
75 | #endif | 75 | #endif |
76 | #ifdef CONFIG_SECURITY | 76 | #ifdef CONFIG_SECURITY |
77 | PROC_TGID_ATTR, | 77 | PROC_TGID_ATTR, |
78 | PROC_TGID_ATTR_CURRENT, | 78 | PROC_TGID_ATTR_CURRENT, |
79 | PROC_TGID_ATTR_PREV, | 79 | PROC_TGID_ATTR_PREV, |
80 | PROC_TGID_ATTR_EXEC, | 80 | PROC_TGID_ATTR_EXEC, |
81 | PROC_TGID_ATTR_FSCREATE, | 81 | PROC_TGID_ATTR_FSCREATE, |
82 | #endif | 82 | #endif |
83 | #ifdef CONFIG_AUDITSYSCALL | 83 | #ifdef CONFIG_AUDITSYSCALL |
84 | PROC_TGID_LOGINUID, | 84 | PROC_TGID_LOGINUID, |
85 | #endif | 85 | #endif |
86 | PROC_TGID_FD_DIR, | 86 | PROC_TGID_FD_DIR, |
87 | PROC_TGID_OOM_SCORE, | 87 | PROC_TGID_OOM_SCORE, |
88 | PROC_TGID_OOM_ADJUST, | 88 | PROC_TGID_OOM_ADJUST, |
89 | PROC_TID_INO, | 89 | PROC_TID_INO, |
90 | PROC_TID_STATUS, | 90 | PROC_TID_STATUS, |
91 | PROC_TID_MEM, | 91 | PROC_TID_MEM, |
92 | #ifdef CONFIG_SECCOMP | 92 | #ifdef CONFIG_SECCOMP |
93 | PROC_TID_SECCOMP, | 93 | PROC_TID_SECCOMP, |
94 | #endif | 94 | #endif |
95 | PROC_TID_CWD, | 95 | PROC_TID_CWD, |
96 | PROC_TID_ROOT, | 96 | PROC_TID_ROOT, |
97 | PROC_TID_EXE, | 97 | PROC_TID_EXE, |
98 | PROC_TID_FD, | 98 | PROC_TID_FD, |
99 | PROC_TID_ENVIRON, | 99 | PROC_TID_ENVIRON, |
100 | PROC_TID_AUXV, | 100 | PROC_TID_AUXV, |
101 | PROC_TID_CMDLINE, | 101 | PROC_TID_CMDLINE, |
102 | PROC_TID_STAT, | 102 | PROC_TID_STAT, |
103 | PROC_TID_STATM, | 103 | PROC_TID_STATM, |
104 | PROC_TID_MAPS, | 104 | PROC_TID_MAPS, |
105 | PROC_TID_MOUNTS, | 105 | PROC_TID_MOUNTS, |
106 | PROC_TID_WCHAN, | 106 | PROC_TID_WCHAN, |
107 | #ifdef CONFIG_SCHEDSTATS | 107 | #ifdef CONFIG_SCHEDSTATS |
108 | PROC_TID_SCHEDSTAT, | 108 | PROC_TID_SCHEDSTAT, |
109 | #endif | 109 | #endif |
110 | #ifdef CONFIG_CPUSETS | 110 | #ifdef CONFIG_CPUSETS |
111 | PROC_TID_CPUSET, | 111 | PROC_TID_CPUSET, |
112 | #endif | 112 | #endif |
113 | #ifdef CONFIG_SECURITY | 113 | #ifdef CONFIG_SECURITY |
114 | PROC_TID_ATTR, | 114 | PROC_TID_ATTR, |
115 | PROC_TID_ATTR_CURRENT, | 115 | PROC_TID_ATTR_CURRENT, |
116 | PROC_TID_ATTR_PREV, | 116 | PROC_TID_ATTR_PREV, |
117 | PROC_TID_ATTR_EXEC, | 117 | PROC_TID_ATTR_EXEC, |
118 | PROC_TID_ATTR_FSCREATE, | 118 | PROC_TID_ATTR_FSCREATE, |
119 | #endif | 119 | #endif |
120 | #ifdef CONFIG_AUDITSYSCALL | 120 | #ifdef CONFIG_AUDITSYSCALL |
121 | PROC_TID_LOGINUID, | 121 | PROC_TID_LOGINUID, |
122 | #endif | 122 | #endif |
123 | PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */ | 123 | PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */ |
124 | PROC_TID_OOM_SCORE, | 124 | PROC_TID_OOM_SCORE, |
125 | PROC_TID_OOM_ADJUST, | 125 | PROC_TID_OOM_ADJUST, |
126 | }; | 126 | }; |
127 | 127 | ||
128 | struct pid_entry { | 128 | struct pid_entry { |
129 | int type; | 129 | int type; |
130 | int len; | 130 | int len; |
131 | char *name; | 131 | char *name; |
132 | mode_t mode; | 132 | mode_t mode; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | #define E(type,name,mode) {(type),sizeof(name)-1,(name),(mode)} | 135 | #define E(type,name,mode) {(type),sizeof(name)-1,(name),(mode)} |
136 | 136 | ||
137 | static struct pid_entry tgid_base_stuff[] = { | 137 | static struct pid_entry tgid_base_stuff[] = { |
138 | E(PROC_TGID_TASK, "task", S_IFDIR|S_IRUGO|S_IXUGO), | 138 | E(PROC_TGID_TASK, "task", S_IFDIR|S_IRUGO|S_IXUGO), |
139 | E(PROC_TGID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR), | 139 | E(PROC_TGID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR), |
140 | E(PROC_TGID_ENVIRON, "environ", S_IFREG|S_IRUSR), | 140 | E(PROC_TGID_ENVIRON, "environ", S_IFREG|S_IRUSR), |
141 | E(PROC_TGID_AUXV, "auxv", S_IFREG|S_IRUSR), | 141 | E(PROC_TGID_AUXV, "auxv", S_IFREG|S_IRUSR), |
142 | E(PROC_TGID_STATUS, "status", S_IFREG|S_IRUGO), | 142 | E(PROC_TGID_STATUS, "status", S_IFREG|S_IRUGO), |
143 | E(PROC_TGID_CMDLINE, "cmdline", S_IFREG|S_IRUGO), | 143 | E(PROC_TGID_CMDLINE, "cmdline", S_IFREG|S_IRUGO), |
144 | E(PROC_TGID_STAT, "stat", S_IFREG|S_IRUGO), | 144 | E(PROC_TGID_STAT, "stat", S_IFREG|S_IRUGO), |
145 | E(PROC_TGID_STATM, "statm", S_IFREG|S_IRUGO), | 145 | E(PROC_TGID_STATM, "statm", S_IFREG|S_IRUGO), |
146 | E(PROC_TGID_MAPS, "maps", S_IFREG|S_IRUGO), | 146 | E(PROC_TGID_MAPS, "maps", S_IFREG|S_IRUGO), |
147 | E(PROC_TGID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR), | 147 | E(PROC_TGID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR), |
148 | #ifdef CONFIG_SECCOMP | 148 | #ifdef CONFIG_SECCOMP |
149 | E(PROC_TGID_SECCOMP, "seccomp", S_IFREG|S_IRUSR|S_IWUSR), | 149 | E(PROC_TGID_SECCOMP, "seccomp", S_IFREG|S_IRUSR|S_IWUSR), |
150 | #endif | 150 | #endif |
151 | E(PROC_TGID_CWD, "cwd", S_IFLNK|S_IRWXUGO), | 151 | E(PROC_TGID_CWD, "cwd", S_IFLNK|S_IRWXUGO), |
152 | E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO), | 152 | E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO), |
153 | E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO), | 153 | E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO), |
154 | E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO), | 154 | E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO), |
155 | #ifdef CONFIG_SECURITY | 155 | #ifdef CONFIG_SECURITY |
156 | E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), | 156 | E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), |
157 | #endif | 157 | #endif |
158 | #ifdef CONFIG_KALLSYMS | 158 | #ifdef CONFIG_KALLSYMS |
159 | E(PROC_TGID_WCHAN, "wchan", S_IFREG|S_IRUGO), | 159 | E(PROC_TGID_WCHAN, "wchan", S_IFREG|S_IRUGO), |
160 | #endif | 160 | #endif |
161 | #ifdef CONFIG_SCHEDSTATS | 161 | #ifdef CONFIG_SCHEDSTATS |
162 | E(PROC_TGID_SCHEDSTAT, "schedstat", S_IFREG|S_IRUGO), | 162 | E(PROC_TGID_SCHEDSTAT, "schedstat", S_IFREG|S_IRUGO), |
163 | #endif | 163 | #endif |
164 | #ifdef CONFIG_CPUSETS | 164 | #ifdef CONFIG_CPUSETS |
165 | E(PROC_TGID_CPUSET, "cpuset", S_IFREG|S_IRUGO), | 165 | E(PROC_TGID_CPUSET, "cpuset", S_IFREG|S_IRUGO), |
166 | #endif | 166 | #endif |
167 | E(PROC_TGID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO), | 167 | E(PROC_TGID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO), |
168 | E(PROC_TGID_OOM_ADJUST,"oom_adj", S_IFREG|S_IRUGO|S_IWUSR), | 168 | E(PROC_TGID_OOM_ADJUST,"oom_adj", S_IFREG|S_IRUGO|S_IWUSR), |
169 | #ifdef CONFIG_AUDITSYSCALL | 169 | #ifdef CONFIG_AUDITSYSCALL |
170 | E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO), | 170 | E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO), |
171 | #endif | 171 | #endif |
172 | {0,0,NULL,0} | 172 | {0,0,NULL,0} |
173 | }; | 173 | }; |
174 | static struct pid_entry tid_base_stuff[] = { | 174 | static struct pid_entry tid_base_stuff[] = { |
175 | E(PROC_TID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR), | 175 | E(PROC_TID_FD, "fd", S_IFDIR|S_IRUSR|S_IXUSR), |
176 | E(PROC_TID_ENVIRON, "environ", S_IFREG|S_IRUSR), | 176 | E(PROC_TID_ENVIRON, "environ", S_IFREG|S_IRUSR), |
177 | E(PROC_TID_AUXV, "auxv", S_IFREG|S_IRUSR), | 177 | E(PROC_TID_AUXV, "auxv", S_IFREG|S_IRUSR), |
178 | E(PROC_TID_STATUS, "status", S_IFREG|S_IRUGO), | 178 | E(PROC_TID_STATUS, "status", S_IFREG|S_IRUGO), |
179 | E(PROC_TID_CMDLINE, "cmdline", S_IFREG|S_IRUGO), | 179 | E(PROC_TID_CMDLINE, "cmdline", S_IFREG|S_IRUGO), |
180 | E(PROC_TID_STAT, "stat", S_IFREG|S_IRUGO), | 180 | E(PROC_TID_STAT, "stat", S_IFREG|S_IRUGO), |
181 | E(PROC_TID_STATM, "statm", S_IFREG|S_IRUGO), | 181 | E(PROC_TID_STATM, "statm", S_IFREG|S_IRUGO), |
182 | E(PROC_TID_MAPS, "maps", S_IFREG|S_IRUGO), | 182 | E(PROC_TID_MAPS, "maps", S_IFREG|S_IRUGO), |
183 | E(PROC_TID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR), | 183 | E(PROC_TID_MEM, "mem", S_IFREG|S_IRUSR|S_IWUSR), |
184 | #ifdef CONFIG_SECCOMP | 184 | #ifdef CONFIG_SECCOMP |
185 | E(PROC_TID_SECCOMP, "seccomp", S_IFREG|S_IRUSR|S_IWUSR), | 185 | E(PROC_TID_SECCOMP, "seccomp", S_IFREG|S_IRUSR|S_IWUSR), |
186 | #endif | 186 | #endif |
187 | E(PROC_TID_CWD, "cwd", S_IFLNK|S_IRWXUGO), | 187 | E(PROC_TID_CWD, "cwd", S_IFLNK|S_IRWXUGO), |
188 | E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO), | 188 | E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO), |
189 | E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO), | 189 | E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO), |
190 | E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO), | 190 | E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO), |
191 | #ifdef CONFIG_SECURITY | 191 | #ifdef CONFIG_SECURITY |
192 | E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), | 192 | E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), |
193 | #endif | 193 | #endif |
194 | #ifdef CONFIG_KALLSYMS | 194 | #ifdef CONFIG_KALLSYMS |
195 | E(PROC_TID_WCHAN, "wchan", S_IFREG|S_IRUGO), | 195 | E(PROC_TID_WCHAN, "wchan", S_IFREG|S_IRUGO), |
196 | #endif | 196 | #endif |
197 | #ifdef CONFIG_SCHEDSTATS | 197 | #ifdef CONFIG_SCHEDSTATS |
198 | E(PROC_TID_SCHEDSTAT, "schedstat",S_IFREG|S_IRUGO), | 198 | E(PROC_TID_SCHEDSTAT, "schedstat",S_IFREG|S_IRUGO), |
199 | #endif | 199 | #endif |
200 | #ifdef CONFIG_CPUSETS | 200 | #ifdef CONFIG_CPUSETS |
201 | E(PROC_TID_CPUSET, "cpuset", S_IFREG|S_IRUGO), | 201 | E(PROC_TID_CPUSET, "cpuset", S_IFREG|S_IRUGO), |
202 | #endif | 202 | #endif |
203 | E(PROC_TID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO), | 203 | E(PROC_TID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO), |
204 | E(PROC_TID_OOM_ADJUST, "oom_adj", S_IFREG|S_IRUGO|S_IWUSR), | 204 | E(PROC_TID_OOM_ADJUST, "oom_adj", S_IFREG|S_IRUGO|S_IWUSR), |
205 | #ifdef CONFIG_AUDITSYSCALL | 205 | #ifdef CONFIG_AUDITSYSCALL |
206 | E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO), | 206 | E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO), |
207 | #endif | 207 | #endif |
208 | {0,0,NULL,0} | 208 | {0,0,NULL,0} |
209 | }; | 209 | }; |
210 | 210 | ||
211 | #ifdef CONFIG_SECURITY | 211 | #ifdef CONFIG_SECURITY |
212 | static struct pid_entry tgid_attr_stuff[] = { | 212 | static struct pid_entry tgid_attr_stuff[] = { |
213 | E(PROC_TGID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO), | 213 | E(PROC_TGID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO), |
214 | E(PROC_TGID_ATTR_PREV, "prev", S_IFREG|S_IRUGO), | 214 | E(PROC_TGID_ATTR_PREV, "prev", S_IFREG|S_IRUGO), |
215 | E(PROC_TGID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO), | 215 | E(PROC_TGID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO), |
216 | E(PROC_TGID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO), | 216 | E(PROC_TGID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO), |
217 | {0,0,NULL,0} | 217 | {0,0,NULL,0} |
218 | }; | 218 | }; |
219 | static struct pid_entry tid_attr_stuff[] = { | 219 | static struct pid_entry tid_attr_stuff[] = { |
220 | E(PROC_TID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO), | 220 | E(PROC_TID_ATTR_CURRENT, "current", S_IFREG|S_IRUGO|S_IWUGO), |
221 | E(PROC_TID_ATTR_PREV, "prev", S_IFREG|S_IRUGO), | 221 | E(PROC_TID_ATTR_PREV, "prev", S_IFREG|S_IRUGO), |
222 | E(PROC_TID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO), | 222 | E(PROC_TID_ATTR_EXEC, "exec", S_IFREG|S_IRUGO|S_IWUGO), |
223 | E(PROC_TID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO), | 223 | E(PROC_TID_ATTR_FSCREATE, "fscreate", S_IFREG|S_IRUGO|S_IWUGO), |
224 | {0,0,NULL,0} | 224 | {0,0,NULL,0} |
225 | }; | 225 | }; |
226 | #endif | 226 | #endif |
227 | 227 | ||
228 | #undef E | 228 | #undef E |
229 | 229 | ||
230 | static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) | 230 | static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) |
231 | { | 231 | { |
232 | struct task_struct *task = proc_task(inode); | 232 | struct task_struct *task = proc_task(inode); |
233 | struct files_struct *files; | 233 | struct files_struct *files; |
234 | struct file *file; | 234 | struct file *file; |
235 | int fd = proc_type(inode) - PROC_TID_FD_DIR; | 235 | int fd = proc_type(inode) - PROC_TID_FD_DIR; |
236 | 236 | ||
237 | files = get_files_struct(task); | 237 | files = get_files_struct(task); |
238 | if (files) { | 238 | if (files) { |
239 | spin_lock(&files->file_lock); | 239 | spin_lock(&files->file_lock); |
240 | file = fcheck_files(files, fd); | 240 | file = fcheck_files(files, fd); |
241 | if (file) { | 241 | if (file) { |
242 | *mnt = mntget(file->f_vfsmnt); | 242 | *mnt = mntget(file->f_vfsmnt); |
243 | *dentry = dget(file->f_dentry); | 243 | *dentry = dget(file->f_dentry); |
244 | spin_unlock(&files->file_lock); | 244 | spin_unlock(&files->file_lock); |
245 | put_files_struct(files); | 245 | put_files_struct(files); |
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | spin_unlock(&files->file_lock); | 248 | spin_unlock(&files->file_lock); |
249 | put_files_struct(files); | 249 | put_files_struct(files); |
250 | } | 250 | } |
251 | return -ENOENT; | 251 | return -ENOENT; |
252 | } | 252 | } |
253 | 253 | ||
254 | static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) | 254 | static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) |
255 | { | 255 | { |
256 | struct fs_struct *fs; | 256 | struct fs_struct *fs; |
257 | int result = -ENOENT; | 257 | int result = -ENOENT; |
258 | task_lock(proc_task(inode)); | 258 | task_lock(proc_task(inode)); |
259 | fs = proc_task(inode)->fs; | 259 | fs = proc_task(inode)->fs; |
260 | if(fs) | 260 | if(fs) |
261 | atomic_inc(&fs->count); | 261 | atomic_inc(&fs->count); |
262 | task_unlock(proc_task(inode)); | 262 | task_unlock(proc_task(inode)); |
263 | if (fs) { | 263 | if (fs) { |
264 | read_lock(&fs->lock); | 264 | read_lock(&fs->lock); |
265 | *mnt = mntget(fs->pwdmnt); | 265 | *mnt = mntget(fs->pwdmnt); |
266 | *dentry = dget(fs->pwd); | 266 | *dentry = dget(fs->pwd); |
267 | read_unlock(&fs->lock); | 267 | read_unlock(&fs->lock); |
268 | result = 0; | 268 | result = 0; |
269 | put_fs_struct(fs); | 269 | put_fs_struct(fs); |
270 | } | 270 | } |
271 | return result; | 271 | return result; |
272 | } | 272 | } |
273 | 273 | ||
274 | static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) | 274 | static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) |
275 | { | 275 | { |
276 | struct fs_struct *fs; | 276 | struct fs_struct *fs; |
277 | int result = -ENOENT; | 277 | int result = -ENOENT; |
278 | task_lock(proc_task(inode)); | 278 | task_lock(proc_task(inode)); |
279 | fs = proc_task(inode)->fs; | 279 | fs = proc_task(inode)->fs; |
280 | if(fs) | 280 | if(fs) |
281 | atomic_inc(&fs->count); | 281 | atomic_inc(&fs->count); |
282 | task_unlock(proc_task(inode)); | 282 | task_unlock(proc_task(inode)); |
283 | if (fs) { | 283 | if (fs) { |
284 | read_lock(&fs->lock); | 284 | read_lock(&fs->lock); |
285 | *mnt = mntget(fs->rootmnt); | 285 | *mnt = mntget(fs->rootmnt); |
286 | *dentry = dget(fs->root); | 286 | *dentry = dget(fs->root); |
287 | read_unlock(&fs->lock); | 287 | read_unlock(&fs->lock); |
288 | result = 0; | 288 | result = 0; |
289 | put_fs_struct(fs); | 289 | put_fs_struct(fs); |
290 | } | 290 | } |
291 | return result; | 291 | return result; |
292 | } | 292 | } |
293 | 293 | ||
294 | #define MAY_PTRACE(task) \ | 294 | #define MAY_PTRACE(task) \ |
295 | (task == current || \ | 295 | (task == current || \ |
296 | (task->parent == current && \ | 296 | (task->parent == current && \ |
297 | (task->ptrace & PT_PTRACED) && \ | 297 | (task->ptrace & PT_PTRACED) && \ |
298 | (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \ | 298 | (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \ |
299 | security_ptrace(current,task) == 0)) | 299 | security_ptrace(current,task) == 0)) |
300 | 300 | ||
301 | static int may_ptrace_attach(struct task_struct *task) | 301 | static int may_ptrace_attach(struct task_struct *task) |
302 | { | 302 | { |
303 | int retval = 0; | 303 | int retval = 0; |
304 | 304 | ||
305 | task_lock(task); | 305 | task_lock(task); |
306 | 306 | ||
307 | if (!task->mm) | 307 | if (!task->mm) |
308 | goto out; | 308 | goto out; |
309 | if (((current->uid != task->euid) || | 309 | if (((current->uid != task->euid) || |
310 | (current->uid != task->suid) || | 310 | (current->uid != task->suid) || |
311 | (current->uid != task->uid) || | 311 | (current->uid != task->uid) || |
312 | (current->gid != task->egid) || | 312 | (current->gid != task->egid) || |
313 | (current->gid != task->sgid) || | 313 | (current->gid != task->sgid) || |
314 | (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) | 314 | (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) |
315 | goto out; | 315 | goto out; |
316 | rmb(); | 316 | rmb(); |
317 | if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE)) | 317 | if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE)) |
318 | goto out; | 318 | goto out; |
319 | if (security_ptrace(current, task)) | 319 | if (security_ptrace(current, task)) |
320 | goto out; | 320 | goto out; |
321 | 321 | ||
322 | retval = 1; | 322 | retval = 1; |
323 | out: | 323 | out: |
324 | task_unlock(task); | 324 | task_unlock(task); |
325 | return retval; | 325 | return retval; |
326 | } | 326 | } |
327 | 327 | ||
328 | static int proc_pid_environ(struct task_struct *task, char * buffer) | 328 | static int proc_pid_environ(struct task_struct *task, char * buffer) |
329 | { | 329 | { |
330 | int res = 0; | 330 | int res = 0; |
331 | struct mm_struct *mm = get_task_mm(task); | 331 | struct mm_struct *mm = get_task_mm(task); |
332 | if (mm) { | 332 | if (mm) { |
333 | unsigned int len = mm->env_end - mm->env_start; | 333 | unsigned int len = mm->env_end - mm->env_start; |
334 | if (len > PAGE_SIZE) | 334 | if (len > PAGE_SIZE) |
335 | len = PAGE_SIZE; | 335 | len = PAGE_SIZE; |
336 | res = access_process_vm(task, mm->env_start, buffer, len, 0); | 336 | res = access_process_vm(task, mm->env_start, buffer, len, 0); |
337 | if (!may_ptrace_attach(task)) | 337 | if (!may_ptrace_attach(task)) |
338 | res = -ESRCH; | 338 | res = -ESRCH; |
339 | mmput(mm); | 339 | mmput(mm); |
340 | } | 340 | } |
341 | return res; | 341 | return res; |
342 | } | 342 | } |
343 | 343 | ||
344 | static int proc_pid_cmdline(struct task_struct *task, char * buffer) | 344 | static int proc_pid_cmdline(struct task_struct *task, char * buffer) |
345 | { | 345 | { |
346 | int res = 0; | 346 | int res = 0; |
347 | unsigned int len; | 347 | unsigned int len; |
348 | struct mm_struct *mm = get_task_mm(task); | 348 | struct mm_struct *mm = get_task_mm(task); |
349 | if (!mm) | 349 | if (!mm) |
350 | goto out; | 350 | goto out; |
351 | if (!mm->arg_end) | 351 | if (!mm->arg_end) |
352 | goto out_mm; /* Shh! No looking before we're done */ | 352 | goto out_mm; /* Shh! No looking before we're done */ |
353 | 353 | ||
354 | len = mm->arg_end - mm->arg_start; | 354 | len = mm->arg_end - mm->arg_start; |
355 | 355 | ||
356 | if (len > PAGE_SIZE) | 356 | if (len > PAGE_SIZE) |
357 | len = PAGE_SIZE; | 357 | len = PAGE_SIZE; |
358 | 358 | ||
359 | res = access_process_vm(task, mm->arg_start, buffer, len, 0); | 359 | res = access_process_vm(task, mm->arg_start, buffer, len, 0); |
360 | 360 | ||
361 | // If the nul at the end of args has been overwritten, then | 361 | // If the nul at the end of args has been overwritten, then |
362 | // assume application is using setproctitle(3). | 362 | // assume application is using setproctitle(3). |
363 | if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) { | 363 | if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) { |
364 | len = strnlen(buffer, res); | 364 | len = strnlen(buffer, res); |
365 | if (len < res) { | 365 | if (len < res) { |
366 | res = len; | 366 | res = len; |
367 | } else { | 367 | } else { |
368 | len = mm->env_end - mm->env_start; | 368 | len = mm->env_end - mm->env_start; |
369 | if (len > PAGE_SIZE - res) | 369 | if (len > PAGE_SIZE - res) |
370 | len = PAGE_SIZE - res; | 370 | len = PAGE_SIZE - res; |
371 | res += access_process_vm(task, mm->env_start, buffer+res, len, 0); | 371 | res += access_process_vm(task, mm->env_start, buffer+res, len, 0); |
372 | res = strnlen(buffer, res); | 372 | res = strnlen(buffer, res); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | out_mm: | 375 | out_mm: |
376 | mmput(mm); | 376 | mmput(mm); |
377 | out: | 377 | out: |
378 | return res; | 378 | return res; |
379 | } | 379 | } |
380 | 380 | ||
381 | static int proc_pid_auxv(struct task_struct *task, char *buffer) | 381 | static int proc_pid_auxv(struct task_struct *task, char *buffer) |
382 | { | 382 | { |
383 | int res = 0; | 383 | int res = 0; |
384 | struct mm_struct *mm = get_task_mm(task); | 384 | struct mm_struct *mm = get_task_mm(task); |
385 | if (mm) { | 385 | if (mm) { |
386 | unsigned int nwords = 0; | 386 | unsigned int nwords = 0; |
387 | do | 387 | do |
388 | nwords += 2; | 388 | nwords += 2; |
389 | while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */ | 389 | while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */ |
390 | res = nwords * sizeof(mm->saved_auxv[0]); | 390 | res = nwords * sizeof(mm->saved_auxv[0]); |
391 | if (res > PAGE_SIZE) | 391 | if (res > PAGE_SIZE) |
392 | res = PAGE_SIZE; | 392 | res = PAGE_SIZE; |
393 | memcpy(buffer, mm->saved_auxv, res); | 393 | memcpy(buffer, mm->saved_auxv, res); |
394 | mmput(mm); | 394 | mmput(mm); |
395 | } | 395 | } |
396 | return res; | 396 | return res; |
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
400 | #ifdef CONFIG_KALLSYMS | 400 | #ifdef CONFIG_KALLSYMS |
401 | /* | 401 | /* |
402 | * Provides a wchan file via kallsyms in a proper one-value-per-file format. | 402 | * Provides a wchan file via kallsyms in a proper one-value-per-file format. |
403 | * Returns the resolved symbol. If that fails, simply return the address. | 403 | * Returns the resolved symbol. If that fails, simply return the address. |
404 | */ | 404 | */ |
405 | static int proc_pid_wchan(struct task_struct *task, char *buffer) | 405 | static int proc_pid_wchan(struct task_struct *task, char *buffer) |
406 | { | 406 | { |
407 | char *modname; | 407 | char *modname; |
408 | const char *sym_name; | 408 | const char *sym_name; |
409 | unsigned long wchan, size, offset; | 409 | unsigned long wchan, size, offset; |
410 | char namebuf[KSYM_NAME_LEN+1]; | 410 | char namebuf[KSYM_NAME_LEN+1]; |
411 | 411 | ||
412 | wchan = get_wchan(task); | 412 | wchan = get_wchan(task); |
413 | 413 | ||
414 | sym_name = kallsyms_lookup(wchan, &size, &offset, &modname, namebuf); | 414 | sym_name = kallsyms_lookup(wchan, &size, &offset, &modname, namebuf); |
415 | if (sym_name) | 415 | if (sym_name) |
416 | return sprintf(buffer, "%s", sym_name); | 416 | return sprintf(buffer, "%s", sym_name); |
417 | return sprintf(buffer, "%lu", wchan); | 417 | return sprintf(buffer, "%lu", wchan); |
418 | } | 418 | } |
419 | #endif /* CONFIG_KALLSYMS */ | 419 | #endif /* CONFIG_KALLSYMS */ |
420 | 420 | ||
421 | #ifdef CONFIG_SCHEDSTATS | 421 | #ifdef CONFIG_SCHEDSTATS |
422 | /* | 422 | /* |
423 | * Provides /proc/PID/schedstat | 423 | * Provides /proc/PID/schedstat |
424 | */ | 424 | */ |
425 | static int proc_pid_schedstat(struct task_struct *task, char *buffer) | 425 | static int proc_pid_schedstat(struct task_struct *task, char *buffer) |
426 | { | 426 | { |
427 | return sprintf(buffer, "%lu %lu %lu\n", | 427 | return sprintf(buffer, "%lu %lu %lu\n", |
428 | task->sched_info.cpu_time, | 428 | task->sched_info.cpu_time, |
429 | task->sched_info.run_delay, | 429 | task->sched_info.run_delay, |
430 | task->sched_info.pcnt); | 430 | task->sched_info.pcnt); |
431 | } | 431 | } |
432 | #endif | 432 | #endif |
433 | 433 | ||
434 | /* The badness from the OOM killer */ | 434 | /* The badness from the OOM killer */ |
435 | unsigned long badness(struct task_struct *p, unsigned long uptime); | 435 | unsigned long badness(struct task_struct *p, unsigned long uptime); |
436 | static int proc_oom_score(struct task_struct *task, char *buffer) | 436 | static int proc_oom_score(struct task_struct *task, char *buffer) |
437 | { | 437 | { |
438 | unsigned long points; | 438 | unsigned long points; |
439 | struct timespec uptime; | 439 | struct timespec uptime; |
440 | 440 | ||
441 | do_posix_clock_monotonic_gettime(&uptime); | 441 | do_posix_clock_monotonic_gettime(&uptime); |
442 | points = badness(task, uptime.tv_sec); | 442 | points = badness(task, uptime.tv_sec); |
443 | return sprintf(buffer, "%lu\n", points); | 443 | return sprintf(buffer, "%lu\n", points); |
444 | } | 444 | } |
445 | 445 | ||
446 | /************************************************************************/ | 446 | /************************************************************************/ |
447 | /* Here the fs part begins */ | 447 | /* Here the fs part begins */ |
448 | /************************************************************************/ | 448 | /************************************************************************/ |
449 | 449 | ||
450 | /* permission checks */ | 450 | /* permission checks */ |
451 | 451 | ||
452 | static int proc_check_root(struct inode *inode) | 452 | static int proc_check_root(struct inode *inode) |
453 | { | 453 | { |
454 | struct dentry *de, *base, *root; | 454 | struct dentry *de, *base, *root; |
455 | struct vfsmount *our_vfsmnt, *vfsmnt, *mnt; | 455 | struct vfsmount *our_vfsmnt, *vfsmnt, *mnt; |
456 | int res = 0; | 456 | int res = 0; |
457 | 457 | ||
458 | if (proc_root_link(inode, &root, &vfsmnt)) /* Ewww... */ | 458 | if (proc_root_link(inode, &root, &vfsmnt)) /* Ewww... */ |
459 | return -ENOENT; | 459 | return -ENOENT; |
460 | read_lock(¤t->fs->lock); | 460 | read_lock(¤t->fs->lock); |
461 | our_vfsmnt = mntget(current->fs->rootmnt); | 461 | our_vfsmnt = mntget(current->fs->rootmnt); |
462 | base = dget(current->fs->root); | 462 | base = dget(current->fs->root); |
463 | read_unlock(¤t->fs->lock); | 463 | read_unlock(¤t->fs->lock); |
464 | 464 | ||
465 | spin_lock(&vfsmount_lock); | 465 | spin_lock(&vfsmount_lock); |
466 | de = root; | 466 | de = root; |
467 | mnt = vfsmnt; | 467 | mnt = vfsmnt; |
468 | 468 | ||
469 | while (vfsmnt != our_vfsmnt) { | 469 | while (vfsmnt != our_vfsmnt) { |
470 | if (vfsmnt == vfsmnt->mnt_parent) | 470 | if (vfsmnt == vfsmnt->mnt_parent) |
471 | goto out; | 471 | goto out; |
472 | de = vfsmnt->mnt_mountpoint; | 472 | de = vfsmnt->mnt_mountpoint; |
473 | vfsmnt = vfsmnt->mnt_parent; | 473 | vfsmnt = vfsmnt->mnt_parent; |
474 | } | 474 | } |
475 | 475 | ||
476 | if (!is_subdir(de, base)) | 476 | if (!is_subdir(de, base)) |
477 | goto out; | 477 | goto out; |
478 | spin_unlock(&vfsmount_lock); | 478 | spin_unlock(&vfsmount_lock); |
479 | 479 | ||
480 | exit: | 480 | exit: |
481 | dput(base); | 481 | dput(base); |
482 | mntput(our_vfsmnt); | 482 | mntput(our_vfsmnt); |
483 | dput(root); | 483 | dput(root); |
484 | mntput(mnt); | 484 | mntput(mnt); |
485 | return res; | 485 | return res; |
486 | out: | 486 | out: |
487 | spin_unlock(&vfsmount_lock); | 487 | spin_unlock(&vfsmount_lock); |
488 | res = -EACCES; | 488 | res = -EACCES; |
489 | goto exit; | 489 | goto exit; |
490 | } | 490 | } |
491 | 491 | ||
492 | static int proc_permission(struct inode *inode, int mask, struct nameidata *nd) | 492 | static int proc_permission(struct inode *inode, int mask, struct nameidata *nd) |
493 | { | 493 | { |
494 | if (generic_permission(inode, mask, NULL) != 0) | 494 | if (generic_permission(inode, mask, NULL) != 0) |
495 | return -EACCES; | 495 | return -EACCES; |
496 | return proc_check_root(inode); | 496 | return proc_check_root(inode); |
497 | } | 497 | } |
498 | 498 | ||
499 | extern struct seq_operations proc_pid_maps_op; | 499 | extern struct seq_operations proc_pid_maps_op; |
500 | static int maps_open(struct inode *inode, struct file *file) | 500 | static int maps_open(struct inode *inode, struct file *file) |
501 | { | 501 | { |
502 | struct task_struct *task = proc_task(inode); | 502 | struct task_struct *task = proc_task(inode); |
503 | int ret = seq_open(file, &proc_pid_maps_op); | 503 | int ret = seq_open(file, &proc_pid_maps_op); |
504 | if (!ret) { | 504 | if (!ret) { |
505 | struct seq_file *m = file->private_data; | 505 | struct seq_file *m = file->private_data; |
506 | m->private = task; | 506 | m->private = task; |
507 | } | 507 | } |
508 | return ret; | 508 | return ret; |
509 | } | 509 | } |
510 | 510 | ||
511 | static struct file_operations proc_maps_operations = { | 511 | static struct file_operations proc_maps_operations = { |
512 | .open = maps_open, | 512 | .open = maps_open, |
513 | .read = seq_read, | 513 | .read = seq_read, |
514 | .llseek = seq_lseek, | 514 | .llseek = seq_lseek, |
515 | .release = seq_release, | 515 | .release = seq_release, |
516 | }; | 516 | }; |
517 | 517 | ||
518 | extern struct seq_operations mounts_op; | 518 | extern struct seq_operations mounts_op; |
519 | static int mounts_open(struct inode *inode, struct file *file) | 519 | static int mounts_open(struct inode *inode, struct file *file) |
520 | { | 520 | { |
521 | struct task_struct *task = proc_task(inode); | 521 | struct task_struct *task = proc_task(inode); |
522 | int ret = seq_open(file, &mounts_op); | 522 | int ret = seq_open(file, &mounts_op); |
523 | 523 | ||
524 | if (!ret) { | 524 | if (!ret) { |
525 | struct seq_file *m = file->private_data; | 525 | struct seq_file *m = file->private_data; |
526 | struct namespace *namespace; | 526 | struct namespace *namespace; |
527 | task_lock(task); | 527 | task_lock(task); |
528 | namespace = task->namespace; | 528 | namespace = task->namespace; |
529 | if (namespace) | 529 | if (namespace) |
530 | get_namespace(namespace); | 530 | get_namespace(namespace); |
531 | task_unlock(task); | 531 | task_unlock(task); |
532 | 532 | ||
533 | if (namespace) | 533 | if (namespace) |
534 | m->private = namespace; | 534 | m->private = namespace; |
535 | else { | 535 | else { |
536 | seq_release(inode, file); | 536 | seq_release(inode, file); |
537 | ret = -EINVAL; | 537 | ret = -EINVAL; |
538 | } | 538 | } |
539 | } | 539 | } |
540 | return ret; | 540 | return ret; |
541 | } | 541 | } |
542 | 542 | ||
543 | static int mounts_release(struct inode *inode, struct file *file) | 543 | static int mounts_release(struct inode *inode, struct file *file) |
544 | { | 544 | { |
545 | struct seq_file *m = file->private_data; | 545 | struct seq_file *m = file->private_data; |
546 | struct namespace *namespace = m->private; | 546 | struct namespace *namespace = m->private; |
547 | put_namespace(namespace); | 547 | put_namespace(namespace); |
548 | return seq_release(inode, file); | 548 | return seq_release(inode, file); |
549 | } | 549 | } |
550 | 550 | ||
551 | static struct file_operations proc_mounts_operations = { | 551 | static struct file_operations proc_mounts_operations = { |
552 | .open = mounts_open, | 552 | .open = mounts_open, |
553 | .read = seq_read, | 553 | .read = seq_read, |
554 | .llseek = seq_lseek, | 554 | .llseek = seq_lseek, |
555 | .release = mounts_release, | 555 | .release = mounts_release, |
556 | }; | 556 | }; |
557 | 557 | ||
558 | #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */ | 558 | #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */ |
559 | 559 | ||
560 | static ssize_t proc_info_read(struct file * file, char __user * buf, | 560 | static ssize_t proc_info_read(struct file * file, char __user * buf, |
561 | size_t count, loff_t *ppos) | 561 | size_t count, loff_t *ppos) |
562 | { | 562 | { |
563 | struct inode * inode = file->f_dentry->d_inode; | 563 | struct inode * inode = file->f_dentry->d_inode; |
564 | unsigned long page; | 564 | unsigned long page; |
565 | ssize_t length; | 565 | ssize_t length; |
566 | struct task_struct *task = proc_task(inode); | 566 | struct task_struct *task = proc_task(inode); |
567 | 567 | ||
568 | if (count > PROC_BLOCK_SIZE) | 568 | if (count > PROC_BLOCK_SIZE) |
569 | count = PROC_BLOCK_SIZE; | 569 | count = PROC_BLOCK_SIZE; |
570 | if (!(page = __get_free_page(GFP_KERNEL))) | 570 | if (!(page = __get_free_page(GFP_KERNEL))) |
571 | return -ENOMEM; | 571 | return -ENOMEM; |
572 | 572 | ||
573 | length = PROC_I(inode)->op.proc_read(task, (char*)page); | 573 | length = PROC_I(inode)->op.proc_read(task, (char*)page); |
574 | 574 | ||
575 | if (length >= 0) | 575 | if (length >= 0) |
576 | length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); | 576 | length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); |
577 | free_page(page); | 577 | free_page(page); |
578 | return length; | 578 | return length; |
579 | } | 579 | } |
580 | 580 | ||
581 | static struct file_operations proc_info_file_operations = { | 581 | static struct file_operations proc_info_file_operations = { |
582 | .read = proc_info_read, | 582 | .read = proc_info_read, |
583 | }; | 583 | }; |
584 | 584 | ||
585 | static int mem_open(struct inode* inode, struct file* file) | 585 | static int mem_open(struct inode* inode, struct file* file) |
586 | { | 586 | { |
587 | file->private_data = (void*)((long)current->self_exec_id); | 587 | file->private_data = (void*)((long)current->self_exec_id); |
588 | return 0; | 588 | return 0; |
589 | } | 589 | } |
590 | 590 | ||
591 | static ssize_t mem_read(struct file * file, char __user * buf, | 591 | static ssize_t mem_read(struct file * file, char __user * buf, |
592 | size_t count, loff_t *ppos) | 592 | size_t count, loff_t *ppos) |
593 | { | 593 | { |
594 | struct task_struct *task = proc_task(file->f_dentry->d_inode); | 594 | struct task_struct *task = proc_task(file->f_dentry->d_inode); |
595 | char *page; | 595 | char *page; |
596 | unsigned long src = *ppos; | 596 | unsigned long src = *ppos; |
597 | int ret = -ESRCH; | 597 | int ret = -ESRCH; |
598 | struct mm_struct *mm; | 598 | struct mm_struct *mm; |
599 | 599 | ||
600 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) | 600 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) |
601 | goto out; | 601 | goto out; |
602 | 602 | ||
603 | ret = -ENOMEM; | 603 | ret = -ENOMEM; |
604 | page = (char *)__get_free_page(GFP_USER); | 604 | page = (char *)__get_free_page(GFP_USER); |
605 | if (!page) | 605 | if (!page) |
606 | goto out; | 606 | goto out; |
607 | 607 | ||
608 | ret = 0; | 608 | ret = 0; |
609 | 609 | ||
610 | mm = get_task_mm(task); | 610 | mm = get_task_mm(task); |
611 | if (!mm) | 611 | if (!mm) |
612 | goto out_free; | 612 | goto out_free; |
613 | 613 | ||
614 | ret = -EIO; | 614 | ret = -EIO; |
615 | 615 | ||
616 | if (file->private_data != (void*)((long)current->self_exec_id)) | 616 | if (file->private_data != (void*)((long)current->self_exec_id)) |
617 | goto out_put; | 617 | goto out_put; |
618 | 618 | ||
619 | ret = 0; | 619 | ret = 0; |
620 | 620 | ||
621 | while (count > 0) { | 621 | while (count > 0) { |
622 | int this_len, retval; | 622 | int this_len, retval; |
623 | 623 | ||
624 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; | 624 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; |
625 | retval = access_process_vm(task, src, page, this_len, 0); | 625 | retval = access_process_vm(task, src, page, this_len, 0); |
626 | if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) { | 626 | if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) { |
627 | if (!ret) | 627 | if (!ret) |
628 | ret = -EIO; | 628 | ret = -EIO; |
629 | break; | 629 | break; |
630 | } | 630 | } |
631 | 631 | ||
632 | if (copy_to_user(buf, page, retval)) { | 632 | if (copy_to_user(buf, page, retval)) { |
633 | ret = -EFAULT; | 633 | ret = -EFAULT; |
634 | break; | 634 | break; |
635 | } | 635 | } |
636 | 636 | ||
637 | ret += retval; | 637 | ret += retval; |
638 | src += retval; | 638 | src += retval; |
639 | buf += retval; | 639 | buf += retval; |
640 | count -= retval; | 640 | count -= retval; |
641 | } | 641 | } |
642 | *ppos = src; | 642 | *ppos = src; |
643 | 643 | ||
644 | out_put: | 644 | out_put: |
645 | mmput(mm); | 645 | mmput(mm); |
646 | out_free: | 646 | out_free: |
647 | free_page((unsigned long) page); | 647 | free_page((unsigned long) page); |
648 | out: | 648 | out: |
649 | return ret; | 649 | return ret; |
650 | } | 650 | } |
651 | 651 | ||
652 | #define mem_write NULL | 652 | #define mem_write NULL |
653 | 653 | ||
654 | #ifndef mem_write | 654 | #ifndef mem_write |
655 | /* This is a security hazard */ | 655 | /* This is a security hazard */ |
656 | static ssize_t mem_write(struct file * file, const char * buf, | 656 | static ssize_t mem_write(struct file * file, const char * buf, |
657 | size_t count, loff_t *ppos) | 657 | size_t count, loff_t *ppos) |
658 | { | 658 | { |
659 | int copied = 0; | 659 | int copied = 0; |
660 | char *page; | 660 | char *page; |
661 | struct task_struct *task = proc_task(file->f_dentry->d_inode); | 661 | struct task_struct *task = proc_task(file->f_dentry->d_inode); |
662 | unsigned long dst = *ppos; | 662 | unsigned long dst = *ppos; |
663 | 663 | ||
664 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) | 664 | if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) |
665 | return -ESRCH; | 665 | return -ESRCH; |
666 | 666 | ||
667 | page = (char *)__get_free_page(GFP_USER); | 667 | page = (char *)__get_free_page(GFP_USER); |
668 | if (!page) | 668 | if (!page) |
669 | return -ENOMEM; | 669 | return -ENOMEM; |
670 | 670 | ||
671 | while (count > 0) { | 671 | while (count > 0) { |
672 | int this_len, retval; | 672 | int this_len, retval; |
673 | 673 | ||
674 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; | 674 | this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; |
675 | if (copy_from_user(page, buf, this_len)) { | 675 | if (copy_from_user(page, buf, this_len)) { |
676 | copied = -EFAULT; | 676 | copied = -EFAULT; |
677 | break; | 677 | break; |
678 | } | 678 | } |
679 | retval = access_process_vm(task, dst, page, this_len, 1); | 679 | retval = access_process_vm(task, dst, page, this_len, 1); |
680 | if (!retval) { | 680 | if (!retval) { |
681 | if (!copied) | 681 | if (!copied) |
682 | copied = -EIO; | 682 | copied = -EIO; |
683 | break; | 683 | break; |
684 | } | 684 | } |
685 | copied += retval; | 685 | copied += retval; |
686 | buf += retval; | 686 | buf += retval; |
687 | dst += retval; | 687 | dst += retval; |
688 | count -= retval; | 688 | count -= retval; |
689 | } | 689 | } |
690 | *ppos = dst; | 690 | *ppos = dst; |
691 | free_page((unsigned long) page); | 691 | free_page((unsigned long) page); |
692 | return copied; | 692 | return copied; |
693 | } | 693 | } |
694 | #endif | 694 | #endif |
695 | 695 | ||
696 | static loff_t mem_lseek(struct file * file, loff_t offset, int orig) | 696 | static loff_t mem_lseek(struct file * file, loff_t offset, int orig) |
697 | { | 697 | { |
698 | switch (orig) { | 698 | switch (orig) { |
699 | case 0: | 699 | case 0: |
700 | file->f_pos = offset; | 700 | file->f_pos = offset; |
701 | break; | 701 | break; |
702 | case 1: | 702 | case 1: |
703 | file->f_pos += offset; | 703 | file->f_pos += offset; |
704 | break; | 704 | break; |
705 | default: | 705 | default: |
706 | return -EINVAL; | 706 | return -EINVAL; |
707 | } | 707 | } |
708 | force_successful_syscall_return(); | 708 | force_successful_syscall_return(); |
709 | return file->f_pos; | 709 | return file->f_pos; |
710 | } | 710 | } |
711 | 711 | ||
712 | static struct file_operations proc_mem_operations = { | 712 | static struct file_operations proc_mem_operations = { |
713 | .llseek = mem_lseek, | 713 | .llseek = mem_lseek, |
714 | .read = mem_read, | 714 | .read = mem_read, |
715 | .write = mem_write, | 715 | .write = mem_write, |
716 | .open = mem_open, | 716 | .open = mem_open, |
717 | }; | 717 | }; |
718 | 718 | ||
719 | static ssize_t oom_adjust_read(struct file *file, char __user *buf, | 719 | static ssize_t oom_adjust_read(struct file *file, char __user *buf, |
720 | size_t count, loff_t *ppos) | 720 | size_t count, loff_t *ppos) |
721 | { | 721 | { |
722 | struct task_struct *task = proc_task(file->f_dentry->d_inode); | 722 | struct task_struct *task = proc_task(file->f_dentry->d_inode); |
723 | char buffer[8]; | 723 | char buffer[8]; |
724 | size_t len; | 724 | size_t len; |
725 | int oom_adjust = task->oomkilladj; | 725 | int oom_adjust = task->oomkilladj; |
726 | loff_t __ppos = *ppos; | 726 | loff_t __ppos = *ppos; |
727 | 727 | ||
728 | len = sprintf(buffer, "%i\n", oom_adjust); | 728 | len = sprintf(buffer, "%i\n", oom_adjust); |
729 | if (__ppos >= len) | 729 | if (__ppos >= len) |
730 | return 0; | 730 | return 0; |
731 | if (count > len-__ppos) | 731 | if (count > len-__ppos) |
732 | count = len-__ppos; | 732 | count = len-__ppos; |
733 | if (copy_to_user(buf, buffer + __ppos, count)) | 733 | if (copy_to_user(buf, buffer + __ppos, count)) |
734 | return -EFAULT; | 734 | return -EFAULT; |
735 | *ppos = __ppos + count; | 735 | *ppos = __ppos + count; |
736 | return count; | 736 | return count; |
737 | } | 737 | } |
738 | 738 | ||
739 | static ssize_t oom_adjust_write(struct file *file, const char __user *buf, | 739 | static ssize_t oom_adjust_write(struct file *file, const char __user *buf, |
740 | size_t count, loff_t *ppos) | 740 | size_t count, loff_t *ppos) |
741 | { | 741 | { |
742 | struct task_struct *task = proc_task(file->f_dentry->d_inode); | 742 | struct task_struct *task = proc_task(file->f_dentry->d_inode); |
743 | char buffer[8], *end; | 743 | char buffer[8], *end; |
744 | int oom_adjust; | 744 | int oom_adjust; |
745 | 745 | ||
746 | if (!capable(CAP_SYS_RESOURCE)) | 746 | if (!capable(CAP_SYS_RESOURCE)) |
747 | return -EPERM; | 747 | return -EPERM; |
748 | memset(buffer, 0, 8); | 748 | memset(buffer, 0, 8); |
749 | if (count > 6) | 749 | if (count > 6) |
750 | count = 6; | 750 | count = 6; |
751 | if (copy_from_user(buffer, buf, count)) | 751 | if (copy_from_user(buffer, buf, count)) |
752 | return -EFAULT; | 752 | return -EFAULT; |
753 | oom_adjust = simple_strtol(buffer, &end, 0); | 753 | oom_adjust = simple_strtol(buffer, &end, 0); |
754 | if ((oom_adjust < -16 || oom_adjust > 15) && oom_adjust != OOM_DISABLE) | 754 | if ((oom_adjust < -16 || oom_adjust > 15) && oom_adjust != OOM_DISABLE) |
755 | return -EINVAL; | 755 | return -EINVAL; |
756 | if (*end == '\n') | 756 | if (*end == '\n') |
757 | end++; | 757 | end++; |
758 | task->oomkilladj = oom_adjust; | 758 | task->oomkilladj = oom_adjust; |
759 | if (end - buffer == 0) | 759 | if (end - buffer == 0) |
760 | return -EIO; | 760 | return -EIO; |
761 | return end - buffer; | 761 | return end - buffer; |
762 | } | 762 | } |
763 | 763 | ||
764 | static struct file_operations proc_oom_adjust_operations = { | 764 | static struct file_operations proc_oom_adjust_operations = { |
765 | .read = oom_adjust_read, | 765 | .read = oom_adjust_read, |
766 | .write = oom_adjust_write, | 766 | .write = oom_adjust_write, |
767 | }; | 767 | }; |
768 | 768 | ||
769 | static struct inode_operations proc_mem_inode_operations = { | 769 | static struct inode_operations proc_mem_inode_operations = { |
770 | .permission = proc_permission, | 770 | .permission = proc_permission, |
771 | }; | 771 | }; |
772 | 772 | ||
773 | #ifdef CONFIG_AUDITSYSCALL | 773 | #ifdef CONFIG_AUDITSYSCALL |
774 | #define TMPBUFLEN 21 | 774 | #define TMPBUFLEN 21 |
775 | static ssize_t proc_loginuid_read(struct file * file, char __user * buf, | 775 | static ssize_t proc_loginuid_read(struct file * file, char __user * buf, |
776 | size_t count, loff_t *ppos) | 776 | size_t count, loff_t *ppos) |
777 | { | 777 | { |
778 | struct inode * inode = file->f_dentry->d_inode; | 778 | struct inode * inode = file->f_dentry->d_inode; |
779 | struct task_struct *task = proc_task(inode); | 779 | struct task_struct *task = proc_task(inode); |
780 | ssize_t length; | 780 | ssize_t length; |
781 | char tmpbuf[TMPBUFLEN]; | 781 | char tmpbuf[TMPBUFLEN]; |
782 | 782 | ||
783 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", | 783 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", |
784 | audit_get_loginuid(task->audit_context)); | 784 | audit_get_loginuid(task->audit_context)); |
785 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); | 785 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); |
786 | } | 786 | } |
787 | 787 | ||
788 | static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, | 788 | static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, |
789 | size_t count, loff_t *ppos) | 789 | size_t count, loff_t *ppos) |
790 | { | 790 | { |
791 | struct inode * inode = file->f_dentry->d_inode; | 791 | struct inode * inode = file->f_dentry->d_inode; |
792 | char *page, *tmp; | 792 | char *page, *tmp; |
793 | ssize_t length; | 793 | ssize_t length; |
794 | struct task_struct *task = proc_task(inode); | 794 | struct task_struct *task = proc_task(inode); |
795 | uid_t loginuid; | 795 | uid_t loginuid; |
796 | 796 | ||
797 | if (!capable(CAP_AUDIT_CONTROL)) | 797 | if (!capable(CAP_AUDIT_CONTROL)) |
798 | return -EPERM; | 798 | return -EPERM; |
799 | 799 | ||
800 | if (current != task) | 800 | if (current != task) |
801 | return -EPERM; | 801 | return -EPERM; |
802 | 802 | ||
803 | if (count > PAGE_SIZE) | 803 | if (count > PAGE_SIZE) |
804 | count = PAGE_SIZE; | 804 | count = PAGE_SIZE; |
805 | 805 | ||
806 | if (*ppos != 0) { | 806 | if (*ppos != 0) { |
807 | /* No partial writes. */ | 807 | /* No partial writes. */ |
808 | return -EINVAL; | 808 | return -EINVAL; |
809 | } | 809 | } |
810 | page = (char*)__get_free_page(GFP_USER); | 810 | page = (char*)__get_free_page(GFP_USER); |
811 | if (!page) | 811 | if (!page) |
812 | return -ENOMEM; | 812 | return -ENOMEM; |
813 | length = -EFAULT; | 813 | length = -EFAULT; |
814 | if (copy_from_user(page, buf, count)) | 814 | if (copy_from_user(page, buf, count)) |
815 | goto out_free_page; | 815 | goto out_free_page; |
816 | 816 | ||
817 | loginuid = simple_strtoul(page, &tmp, 10); | 817 | loginuid = simple_strtoul(page, &tmp, 10); |
818 | if (tmp == page) { | 818 | if (tmp == page) { |
819 | length = -EINVAL; | 819 | length = -EINVAL; |
820 | goto out_free_page; | 820 | goto out_free_page; |
821 | 821 | ||
822 | } | 822 | } |
823 | length = audit_set_loginuid(task->audit_context, loginuid); | 823 | length = audit_set_loginuid(task, loginuid); |
824 | if (likely(length == 0)) | 824 | if (likely(length == 0)) |
825 | length = count; | 825 | length = count; |
826 | 826 | ||
827 | out_free_page: | 827 | out_free_page: |
828 | free_page((unsigned long) page); | 828 | free_page((unsigned long) page); |
829 | return length; | 829 | return length; |
830 | } | 830 | } |
831 | 831 | ||
832 | static struct file_operations proc_loginuid_operations = { | 832 | static struct file_operations proc_loginuid_operations = { |
833 | .read = proc_loginuid_read, | 833 | .read = proc_loginuid_read, |
834 | .write = proc_loginuid_write, | 834 | .write = proc_loginuid_write, |
835 | }; | 835 | }; |
836 | #endif | 836 | #endif |
837 | 837 | ||
838 | #ifdef CONFIG_SECCOMP | 838 | #ifdef CONFIG_SECCOMP |
839 | static ssize_t seccomp_read(struct file *file, char __user *buf, | 839 | static ssize_t seccomp_read(struct file *file, char __user *buf, |
840 | size_t count, loff_t *ppos) | 840 | size_t count, loff_t *ppos) |
841 | { | 841 | { |
842 | struct task_struct *tsk = proc_task(file->f_dentry->d_inode); | 842 | struct task_struct *tsk = proc_task(file->f_dentry->d_inode); |
843 | char __buf[20]; | 843 | char __buf[20]; |
844 | loff_t __ppos = *ppos; | 844 | loff_t __ppos = *ppos; |
845 | size_t len; | 845 | size_t len; |
846 | 846 | ||
847 | /* no need to print the trailing zero, so use only len */ | 847 | /* no need to print the trailing zero, so use only len */ |
848 | len = sprintf(__buf, "%u\n", tsk->seccomp.mode); | 848 | len = sprintf(__buf, "%u\n", tsk->seccomp.mode); |
849 | if (__ppos >= len) | 849 | if (__ppos >= len) |
850 | return 0; | 850 | return 0; |
851 | if (count > len - __ppos) | 851 | if (count > len - __ppos) |
852 | count = len - __ppos; | 852 | count = len - __ppos; |
853 | if (copy_to_user(buf, __buf + __ppos, count)) | 853 | if (copy_to_user(buf, __buf + __ppos, count)) |
854 | return -EFAULT; | 854 | return -EFAULT; |
855 | *ppos = __ppos + count; | 855 | *ppos = __ppos + count; |
856 | return count; | 856 | return count; |
857 | } | 857 | } |
858 | 858 | ||
859 | static ssize_t seccomp_write(struct file *file, const char __user *buf, | 859 | static ssize_t seccomp_write(struct file *file, const char __user *buf, |
860 | size_t count, loff_t *ppos) | 860 | size_t count, loff_t *ppos) |
861 | { | 861 | { |
862 | struct task_struct *tsk = proc_task(file->f_dentry->d_inode); | 862 | struct task_struct *tsk = proc_task(file->f_dentry->d_inode); |
863 | char __buf[20], *end; | 863 | char __buf[20], *end; |
864 | unsigned int seccomp_mode; | 864 | unsigned int seccomp_mode; |
865 | 865 | ||
866 | /* can set it only once to be even more secure */ | 866 | /* can set it only once to be even more secure */ |
867 | if (unlikely(tsk->seccomp.mode)) | 867 | if (unlikely(tsk->seccomp.mode)) |
868 | return -EPERM; | 868 | return -EPERM; |
869 | 869 | ||
870 | memset(__buf, 0, sizeof(__buf)); | 870 | memset(__buf, 0, sizeof(__buf)); |
871 | count = min(count, sizeof(__buf) - 1); | 871 | count = min(count, sizeof(__buf) - 1); |
872 | if (copy_from_user(__buf, buf, count)) | 872 | if (copy_from_user(__buf, buf, count)) |
873 | return -EFAULT; | 873 | return -EFAULT; |
874 | seccomp_mode = simple_strtoul(__buf, &end, 0); | 874 | seccomp_mode = simple_strtoul(__buf, &end, 0); |
875 | if (*end == '\n') | 875 | if (*end == '\n') |
876 | end++; | 876 | end++; |
877 | if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) { | 877 | if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) { |
878 | tsk->seccomp.mode = seccomp_mode; | 878 | tsk->seccomp.mode = seccomp_mode; |
879 | set_tsk_thread_flag(tsk, TIF_SECCOMP); | 879 | set_tsk_thread_flag(tsk, TIF_SECCOMP); |
880 | } else | 880 | } else |
881 | return -EINVAL; | 881 | return -EINVAL; |
882 | if (unlikely(!(end - __buf))) | 882 | if (unlikely(!(end - __buf))) |
883 | return -EIO; | 883 | return -EIO; |
884 | return end - __buf; | 884 | return end - __buf; |
885 | } | 885 | } |
886 | 886 | ||
887 | static struct file_operations proc_seccomp_operations = { | 887 | static struct file_operations proc_seccomp_operations = { |
888 | .read = seccomp_read, | 888 | .read = seccomp_read, |
889 | .write = seccomp_write, | 889 | .write = seccomp_write, |
890 | }; | 890 | }; |
891 | #endif /* CONFIG_SECCOMP */ | 891 | #endif /* CONFIG_SECCOMP */ |
892 | 892 | ||
893 | static int proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) | 893 | static int proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) |
894 | { | 894 | { |
895 | struct inode *inode = dentry->d_inode; | 895 | struct inode *inode = dentry->d_inode; |
896 | int error = -EACCES; | 896 | int error = -EACCES; |
897 | 897 | ||
898 | /* We don't need a base pointer in the /proc filesystem */ | 898 | /* We don't need a base pointer in the /proc filesystem */ |
899 | path_release(nd); | 899 | path_release(nd); |
900 | 900 | ||
901 | if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE)) | 901 | if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE)) |
902 | goto out; | 902 | goto out; |
903 | error = proc_check_root(inode); | 903 | error = proc_check_root(inode); |
904 | if (error) | 904 | if (error) |
905 | goto out; | 905 | goto out; |
906 | 906 | ||
907 | error = PROC_I(inode)->op.proc_get_link(inode, &nd->dentry, &nd->mnt); | 907 | error = PROC_I(inode)->op.proc_get_link(inode, &nd->dentry, &nd->mnt); |
908 | nd->last_type = LAST_BIND; | 908 | nd->last_type = LAST_BIND; |
909 | out: | 909 | out: |
910 | return error; | 910 | return error; |
911 | } | 911 | } |
912 | 912 | ||
913 | static int do_proc_readlink(struct dentry *dentry, struct vfsmount *mnt, | 913 | static int do_proc_readlink(struct dentry *dentry, struct vfsmount *mnt, |
914 | char __user *buffer, int buflen) | 914 | char __user *buffer, int buflen) |
915 | { | 915 | { |
916 | struct inode * inode; | 916 | struct inode * inode; |
917 | char *tmp = (char*)__get_free_page(GFP_KERNEL), *path; | 917 | char *tmp = (char*)__get_free_page(GFP_KERNEL), *path; |
918 | int len; | 918 | int len; |
919 | 919 | ||
920 | if (!tmp) | 920 | if (!tmp) |
921 | return -ENOMEM; | 921 | return -ENOMEM; |
922 | 922 | ||
923 | inode = dentry->d_inode; | 923 | inode = dentry->d_inode; |
924 | path = d_path(dentry, mnt, tmp, PAGE_SIZE); | 924 | path = d_path(dentry, mnt, tmp, PAGE_SIZE); |
925 | len = PTR_ERR(path); | 925 | len = PTR_ERR(path); |
926 | if (IS_ERR(path)) | 926 | if (IS_ERR(path)) |
927 | goto out; | 927 | goto out; |
928 | len = tmp + PAGE_SIZE - 1 - path; | 928 | len = tmp + PAGE_SIZE - 1 - path; |
929 | 929 | ||
930 | if (len > buflen) | 930 | if (len > buflen) |
931 | len = buflen; | 931 | len = buflen; |
932 | if (copy_to_user(buffer, path, len)) | 932 | if (copy_to_user(buffer, path, len)) |
933 | len = -EFAULT; | 933 | len = -EFAULT; |
934 | out: | 934 | out: |
935 | free_page((unsigned long)tmp); | 935 | free_page((unsigned long)tmp); |
936 | return len; | 936 | return len; |
937 | } | 937 | } |
938 | 938 | ||
939 | static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen) | 939 | static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen) |
940 | { | 940 | { |
941 | int error = -EACCES; | 941 | int error = -EACCES; |
942 | struct inode *inode = dentry->d_inode; | 942 | struct inode *inode = dentry->d_inode; |
943 | struct dentry *de; | 943 | struct dentry *de; |
944 | struct vfsmount *mnt = NULL; | 944 | struct vfsmount *mnt = NULL; |
945 | 945 | ||
946 | lock_kernel(); | 946 | lock_kernel(); |
947 | 947 | ||
948 | if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE)) | 948 | if (current->fsuid != inode->i_uid && !capable(CAP_DAC_OVERRIDE)) |
949 | goto out; | 949 | goto out; |
950 | error = proc_check_root(inode); | 950 | error = proc_check_root(inode); |
951 | if (error) | 951 | if (error) |
952 | goto out; | 952 | goto out; |
953 | 953 | ||
954 | error = PROC_I(inode)->op.proc_get_link(inode, &de, &mnt); | 954 | error = PROC_I(inode)->op.proc_get_link(inode, &de, &mnt); |
955 | if (error) | 955 | if (error) |
956 | goto out; | 956 | goto out; |
957 | 957 | ||
958 | error = do_proc_readlink(de, mnt, buffer, buflen); | 958 | error = do_proc_readlink(de, mnt, buffer, buflen); |
959 | dput(de); | 959 | dput(de); |
960 | mntput(mnt); | 960 | mntput(mnt); |
961 | out: | 961 | out: |
962 | unlock_kernel(); | 962 | unlock_kernel(); |
963 | return error; | 963 | return error; |
964 | } | 964 | } |
965 | 965 | ||
966 | static struct inode_operations proc_pid_link_inode_operations = { | 966 | static struct inode_operations proc_pid_link_inode_operations = { |
967 | .readlink = proc_pid_readlink, | 967 | .readlink = proc_pid_readlink, |
968 | .follow_link = proc_pid_follow_link | 968 | .follow_link = proc_pid_follow_link |
969 | }; | 969 | }; |
970 | 970 | ||
971 | #define NUMBUF 10 | 971 | #define NUMBUF 10 |
972 | 972 | ||
973 | static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir) | 973 | static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir) |
974 | { | 974 | { |
975 | struct inode *inode = filp->f_dentry->d_inode; | 975 | struct inode *inode = filp->f_dentry->d_inode; |
976 | struct task_struct *p = proc_task(inode); | 976 | struct task_struct *p = proc_task(inode); |
977 | unsigned int fd, tid, ino; | 977 | unsigned int fd, tid, ino; |
978 | int retval; | 978 | int retval; |
979 | char buf[NUMBUF]; | 979 | char buf[NUMBUF]; |
980 | struct files_struct * files; | 980 | struct files_struct * files; |
981 | 981 | ||
982 | retval = -ENOENT; | 982 | retval = -ENOENT; |
983 | if (!pid_alive(p)) | 983 | if (!pid_alive(p)) |
984 | goto out; | 984 | goto out; |
985 | retval = 0; | 985 | retval = 0; |
986 | tid = p->pid; | 986 | tid = p->pid; |
987 | 987 | ||
988 | fd = filp->f_pos; | 988 | fd = filp->f_pos; |
989 | switch (fd) { | 989 | switch (fd) { |
990 | case 0: | 990 | case 0: |
991 | if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0) | 991 | if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0) |
992 | goto out; | 992 | goto out; |
993 | filp->f_pos++; | 993 | filp->f_pos++; |
994 | case 1: | 994 | case 1: |
995 | ino = fake_ino(tid, PROC_TID_INO); | 995 | ino = fake_ino(tid, PROC_TID_INO); |
996 | if (filldir(dirent, "..", 2, 1, ino, DT_DIR) < 0) | 996 | if (filldir(dirent, "..", 2, 1, ino, DT_DIR) < 0) |
997 | goto out; | 997 | goto out; |
998 | filp->f_pos++; | 998 | filp->f_pos++; |
999 | default: | 999 | default: |
1000 | files = get_files_struct(p); | 1000 | files = get_files_struct(p); |
1001 | if (!files) | 1001 | if (!files) |
1002 | goto out; | 1002 | goto out; |
1003 | spin_lock(&files->file_lock); | 1003 | spin_lock(&files->file_lock); |
1004 | for (fd = filp->f_pos-2; | 1004 | for (fd = filp->f_pos-2; |
1005 | fd < files->max_fds; | 1005 | fd < files->max_fds; |
1006 | fd++, filp->f_pos++) { | 1006 | fd++, filp->f_pos++) { |
1007 | unsigned int i,j; | 1007 | unsigned int i,j; |
1008 | 1008 | ||
1009 | if (!fcheck_files(files, fd)) | 1009 | if (!fcheck_files(files, fd)) |
1010 | continue; | 1010 | continue; |
1011 | spin_unlock(&files->file_lock); | 1011 | spin_unlock(&files->file_lock); |
1012 | 1012 | ||
1013 | j = NUMBUF; | 1013 | j = NUMBUF; |
1014 | i = fd; | 1014 | i = fd; |
1015 | do { | 1015 | do { |
1016 | j--; | 1016 | j--; |
1017 | buf[j] = '0' + (i % 10); | 1017 | buf[j] = '0' + (i % 10); |
1018 | i /= 10; | 1018 | i /= 10; |
1019 | } while (i); | 1019 | } while (i); |
1020 | 1020 | ||
1021 | ino = fake_ino(tid, PROC_TID_FD_DIR + fd); | 1021 | ino = fake_ino(tid, PROC_TID_FD_DIR + fd); |
1022 | if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) { | 1022 | if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino, DT_LNK) < 0) { |
1023 | spin_lock(&files->file_lock); | 1023 | spin_lock(&files->file_lock); |
1024 | break; | 1024 | break; |
1025 | } | 1025 | } |
1026 | spin_lock(&files->file_lock); | 1026 | spin_lock(&files->file_lock); |
1027 | } | 1027 | } |
1028 | spin_unlock(&files->file_lock); | 1028 | spin_unlock(&files->file_lock); |
1029 | put_files_struct(files); | 1029 | put_files_struct(files); |
1030 | } | 1030 | } |
1031 | out: | 1031 | out: |
1032 | return retval; | 1032 | return retval; |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | static int proc_pident_readdir(struct file *filp, | 1035 | static int proc_pident_readdir(struct file *filp, |
1036 | void *dirent, filldir_t filldir, | 1036 | void *dirent, filldir_t filldir, |
1037 | struct pid_entry *ents, unsigned int nents) | 1037 | struct pid_entry *ents, unsigned int nents) |
1038 | { | 1038 | { |
1039 | int i; | 1039 | int i; |
1040 | int pid; | 1040 | int pid; |
1041 | struct dentry *dentry = filp->f_dentry; | 1041 | struct dentry *dentry = filp->f_dentry; |
1042 | struct inode *inode = dentry->d_inode; | 1042 | struct inode *inode = dentry->d_inode; |
1043 | struct pid_entry *p; | 1043 | struct pid_entry *p; |
1044 | ino_t ino; | 1044 | ino_t ino; |
1045 | int ret; | 1045 | int ret; |
1046 | 1046 | ||
1047 | ret = -ENOENT; | 1047 | ret = -ENOENT; |
1048 | if (!pid_alive(proc_task(inode))) | 1048 | if (!pid_alive(proc_task(inode))) |
1049 | goto out; | 1049 | goto out; |
1050 | 1050 | ||
1051 | ret = 0; | 1051 | ret = 0; |
1052 | pid = proc_task(inode)->pid; | 1052 | pid = proc_task(inode)->pid; |
1053 | i = filp->f_pos; | 1053 | i = filp->f_pos; |
1054 | switch (i) { | 1054 | switch (i) { |
1055 | case 0: | 1055 | case 0: |
1056 | ino = inode->i_ino; | 1056 | ino = inode->i_ino; |
1057 | if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0) | 1057 | if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0) |
1058 | goto out; | 1058 | goto out; |
1059 | i++; | 1059 | i++; |
1060 | filp->f_pos++; | 1060 | filp->f_pos++; |
1061 | /* fall through */ | 1061 | /* fall through */ |
1062 | case 1: | 1062 | case 1: |
1063 | ino = parent_ino(dentry); | 1063 | ino = parent_ino(dentry); |
1064 | if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0) | 1064 | if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0) |
1065 | goto out; | 1065 | goto out; |
1066 | i++; | 1066 | i++; |
1067 | filp->f_pos++; | 1067 | filp->f_pos++; |
1068 | /* fall through */ | 1068 | /* fall through */ |
1069 | default: | 1069 | default: |
1070 | i -= 2; | 1070 | i -= 2; |
1071 | if (i >= nents) { | 1071 | if (i >= nents) { |
1072 | ret = 1; | 1072 | ret = 1; |
1073 | goto out; | 1073 | goto out; |
1074 | } | 1074 | } |
1075 | p = ents + i; | 1075 | p = ents + i; |
1076 | while (p->name) { | 1076 | while (p->name) { |
1077 | if (filldir(dirent, p->name, p->len, filp->f_pos, | 1077 | if (filldir(dirent, p->name, p->len, filp->f_pos, |
1078 | fake_ino(pid, p->type), p->mode >> 12) < 0) | 1078 | fake_ino(pid, p->type), p->mode >> 12) < 0) |
1079 | goto out; | 1079 | goto out; |
1080 | filp->f_pos++; | 1080 | filp->f_pos++; |
1081 | p++; | 1081 | p++; |
1082 | } | 1082 | } |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | ret = 1; | 1085 | ret = 1; |
1086 | out: | 1086 | out: |
1087 | return ret; | 1087 | return ret; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | static int proc_tgid_base_readdir(struct file * filp, | 1090 | static int proc_tgid_base_readdir(struct file * filp, |
1091 | void * dirent, filldir_t filldir) | 1091 | void * dirent, filldir_t filldir) |
1092 | { | 1092 | { |
1093 | return proc_pident_readdir(filp,dirent,filldir, | 1093 | return proc_pident_readdir(filp,dirent,filldir, |
1094 | tgid_base_stuff,ARRAY_SIZE(tgid_base_stuff)); | 1094 | tgid_base_stuff,ARRAY_SIZE(tgid_base_stuff)); |
1095 | } | 1095 | } |
1096 | 1096 | ||
1097 | static int proc_tid_base_readdir(struct file * filp, | 1097 | static int proc_tid_base_readdir(struct file * filp, |
1098 | void * dirent, filldir_t filldir) | 1098 | void * dirent, filldir_t filldir) |
1099 | { | 1099 | { |
1100 | return proc_pident_readdir(filp,dirent,filldir, | 1100 | return proc_pident_readdir(filp,dirent,filldir, |
1101 | tid_base_stuff,ARRAY_SIZE(tid_base_stuff)); | 1101 | tid_base_stuff,ARRAY_SIZE(tid_base_stuff)); |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | /* building an inode */ | 1104 | /* building an inode */ |
1105 | 1105 | ||
1106 | static int task_dumpable(struct task_struct *task) | 1106 | static int task_dumpable(struct task_struct *task) |
1107 | { | 1107 | { |
1108 | int dumpable = 0; | 1108 | int dumpable = 0; |
1109 | struct mm_struct *mm; | 1109 | struct mm_struct *mm; |
1110 | 1110 | ||
1111 | task_lock(task); | 1111 | task_lock(task); |
1112 | mm = task->mm; | 1112 | mm = task->mm; |
1113 | if (mm) | 1113 | if (mm) |
1114 | dumpable = mm->dumpable; | 1114 | dumpable = mm->dumpable; |
1115 | task_unlock(task); | 1115 | task_unlock(task); |
1116 | return dumpable; | 1116 | return dumpable; |
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | 1119 | ||
1120 | static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task, int ino) | 1120 | static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task, int ino) |
1121 | { | 1121 | { |
1122 | struct inode * inode; | 1122 | struct inode * inode; |
1123 | struct proc_inode *ei; | 1123 | struct proc_inode *ei; |
1124 | 1124 | ||
1125 | /* We need a new inode */ | 1125 | /* We need a new inode */ |
1126 | 1126 | ||
1127 | inode = new_inode(sb); | 1127 | inode = new_inode(sb); |
1128 | if (!inode) | 1128 | if (!inode) |
1129 | goto out; | 1129 | goto out; |
1130 | 1130 | ||
1131 | /* Common stuff */ | 1131 | /* Common stuff */ |
1132 | ei = PROC_I(inode); | 1132 | ei = PROC_I(inode); |
1133 | ei->task = NULL; | 1133 | ei->task = NULL; |
1134 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 1134 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
1135 | inode->i_ino = fake_ino(task->pid, ino); | 1135 | inode->i_ino = fake_ino(task->pid, ino); |
1136 | 1136 | ||
1137 | if (!pid_alive(task)) | 1137 | if (!pid_alive(task)) |
1138 | goto out_unlock; | 1138 | goto out_unlock; |
1139 | 1139 | ||
1140 | /* | 1140 | /* |
1141 | * grab the reference to task. | 1141 | * grab the reference to task. |
1142 | */ | 1142 | */ |
1143 | get_task_struct(task); | 1143 | get_task_struct(task); |
1144 | ei->task = task; | 1144 | ei->task = task; |
1145 | ei->type = ino; | 1145 | ei->type = ino; |
1146 | inode->i_uid = 0; | 1146 | inode->i_uid = 0; |
1147 | inode->i_gid = 0; | 1147 | inode->i_gid = 0; |
1148 | if (ino == PROC_TGID_INO || ino == PROC_TID_INO || task_dumpable(task)) { | 1148 | if (ino == PROC_TGID_INO || ino == PROC_TID_INO || task_dumpable(task)) { |
1149 | inode->i_uid = task->euid; | 1149 | inode->i_uid = task->euid; |
1150 | inode->i_gid = task->egid; | 1150 | inode->i_gid = task->egid; |
1151 | } | 1151 | } |
1152 | security_task_to_inode(task, inode); | 1152 | security_task_to_inode(task, inode); |
1153 | 1153 | ||
1154 | out: | 1154 | out: |
1155 | return inode; | 1155 | return inode; |
1156 | 1156 | ||
1157 | out_unlock: | 1157 | out_unlock: |
1158 | ei->pde = NULL; | 1158 | ei->pde = NULL; |
1159 | iput(inode); | 1159 | iput(inode); |
1160 | return NULL; | 1160 | return NULL; |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | /* dentry stuff */ | 1163 | /* dentry stuff */ |
1164 | 1164 | ||
1165 | /* | 1165 | /* |
1166 | * Exceptional case: normally we are not allowed to unhash a busy | 1166 | * Exceptional case: normally we are not allowed to unhash a busy |
1167 | * directory. In this case, however, we can do it - no aliasing problems | 1167 | * directory. In this case, however, we can do it - no aliasing problems |
1168 | * due to the way we treat inodes. | 1168 | * due to the way we treat inodes. |
1169 | * | 1169 | * |
1170 | * Rewrite the inode's ownerships here because the owning task may have | 1170 | * Rewrite the inode's ownerships here because the owning task may have |
1171 | * performed a setuid(), etc. | 1171 | * performed a setuid(), etc. |
1172 | */ | 1172 | */ |
1173 | static int pid_revalidate(struct dentry *dentry, struct nameidata *nd) | 1173 | static int pid_revalidate(struct dentry *dentry, struct nameidata *nd) |
1174 | { | 1174 | { |
1175 | struct inode *inode = dentry->d_inode; | 1175 | struct inode *inode = dentry->d_inode; |
1176 | struct task_struct *task = proc_task(inode); | 1176 | struct task_struct *task = proc_task(inode); |
1177 | if (pid_alive(task)) { | 1177 | if (pid_alive(task)) { |
1178 | if (proc_type(inode) == PROC_TGID_INO || proc_type(inode) == PROC_TID_INO || task_dumpable(task)) { | 1178 | if (proc_type(inode) == PROC_TGID_INO || proc_type(inode) == PROC_TID_INO || task_dumpable(task)) { |
1179 | inode->i_uid = task->euid; | 1179 | inode->i_uid = task->euid; |
1180 | inode->i_gid = task->egid; | 1180 | inode->i_gid = task->egid; |
1181 | } else { | 1181 | } else { |
1182 | inode->i_uid = 0; | 1182 | inode->i_uid = 0; |
1183 | inode->i_gid = 0; | 1183 | inode->i_gid = 0; |
1184 | } | 1184 | } |
1185 | security_task_to_inode(task, inode); | 1185 | security_task_to_inode(task, inode); |
1186 | return 1; | 1186 | return 1; |
1187 | } | 1187 | } |
1188 | d_drop(dentry); | 1188 | d_drop(dentry); |
1189 | return 0; | 1189 | return 0; |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd) | 1192 | static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd) |
1193 | { | 1193 | { |
1194 | struct inode *inode = dentry->d_inode; | 1194 | struct inode *inode = dentry->d_inode; |
1195 | struct task_struct *task = proc_task(inode); | 1195 | struct task_struct *task = proc_task(inode); |
1196 | int fd = proc_type(inode) - PROC_TID_FD_DIR; | 1196 | int fd = proc_type(inode) - PROC_TID_FD_DIR; |
1197 | struct files_struct *files; | 1197 | struct files_struct *files; |
1198 | 1198 | ||
1199 | files = get_files_struct(task); | 1199 | files = get_files_struct(task); |
1200 | if (files) { | 1200 | if (files) { |
1201 | spin_lock(&files->file_lock); | 1201 | spin_lock(&files->file_lock); |
1202 | if (fcheck_files(files, fd)) { | 1202 | if (fcheck_files(files, fd)) { |
1203 | spin_unlock(&files->file_lock); | 1203 | spin_unlock(&files->file_lock); |
1204 | put_files_struct(files); | 1204 | put_files_struct(files); |
1205 | if (task_dumpable(task)) { | 1205 | if (task_dumpable(task)) { |
1206 | inode->i_uid = task->euid; | 1206 | inode->i_uid = task->euid; |
1207 | inode->i_gid = task->egid; | 1207 | inode->i_gid = task->egid; |
1208 | } else { | 1208 | } else { |
1209 | inode->i_uid = 0; | 1209 | inode->i_uid = 0; |
1210 | inode->i_gid = 0; | 1210 | inode->i_gid = 0; |
1211 | } | 1211 | } |
1212 | security_task_to_inode(task, inode); | 1212 | security_task_to_inode(task, inode); |
1213 | return 1; | 1213 | return 1; |
1214 | } | 1214 | } |
1215 | spin_unlock(&files->file_lock); | 1215 | spin_unlock(&files->file_lock); |
1216 | put_files_struct(files); | 1216 | put_files_struct(files); |
1217 | } | 1217 | } |
1218 | d_drop(dentry); | 1218 | d_drop(dentry); |
1219 | return 0; | 1219 | return 0; |
1220 | } | 1220 | } |
1221 | 1221 | ||
1222 | static void pid_base_iput(struct dentry *dentry, struct inode *inode) | 1222 | static void pid_base_iput(struct dentry *dentry, struct inode *inode) |
1223 | { | 1223 | { |
1224 | struct task_struct *task = proc_task(inode); | 1224 | struct task_struct *task = proc_task(inode); |
1225 | spin_lock(&task->proc_lock); | 1225 | spin_lock(&task->proc_lock); |
1226 | if (task->proc_dentry == dentry) | 1226 | if (task->proc_dentry == dentry) |
1227 | task->proc_dentry = NULL; | 1227 | task->proc_dentry = NULL; |
1228 | spin_unlock(&task->proc_lock); | 1228 | spin_unlock(&task->proc_lock); |
1229 | iput(inode); | 1229 | iput(inode); |
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | static int pid_delete_dentry(struct dentry * dentry) | 1232 | static int pid_delete_dentry(struct dentry * dentry) |
1233 | { | 1233 | { |
1234 | /* Is the task we represent dead? | 1234 | /* Is the task we represent dead? |
1235 | * If so, then don't put the dentry on the lru list, | 1235 | * If so, then don't put the dentry on the lru list, |
1236 | * kill it immediately. | 1236 | * kill it immediately. |
1237 | */ | 1237 | */ |
1238 | return !pid_alive(proc_task(dentry->d_inode)); | 1238 | return !pid_alive(proc_task(dentry->d_inode)); |
1239 | } | 1239 | } |
1240 | 1240 | ||
1241 | static struct dentry_operations tid_fd_dentry_operations = | 1241 | static struct dentry_operations tid_fd_dentry_operations = |
1242 | { | 1242 | { |
1243 | .d_revalidate = tid_fd_revalidate, | 1243 | .d_revalidate = tid_fd_revalidate, |
1244 | .d_delete = pid_delete_dentry, | 1244 | .d_delete = pid_delete_dentry, |
1245 | }; | 1245 | }; |
1246 | 1246 | ||
1247 | static struct dentry_operations pid_dentry_operations = | 1247 | static struct dentry_operations pid_dentry_operations = |
1248 | { | 1248 | { |
1249 | .d_revalidate = pid_revalidate, | 1249 | .d_revalidate = pid_revalidate, |
1250 | .d_delete = pid_delete_dentry, | 1250 | .d_delete = pid_delete_dentry, |
1251 | }; | 1251 | }; |
1252 | 1252 | ||
1253 | static struct dentry_operations pid_base_dentry_operations = | 1253 | static struct dentry_operations pid_base_dentry_operations = |
1254 | { | 1254 | { |
1255 | .d_revalidate = pid_revalidate, | 1255 | .d_revalidate = pid_revalidate, |
1256 | .d_iput = pid_base_iput, | 1256 | .d_iput = pid_base_iput, |
1257 | .d_delete = pid_delete_dentry, | 1257 | .d_delete = pid_delete_dentry, |
1258 | }; | 1258 | }; |
1259 | 1259 | ||
1260 | /* Lookups */ | 1260 | /* Lookups */ |
1261 | 1261 | ||
1262 | static unsigned name_to_int(struct dentry *dentry) | 1262 | static unsigned name_to_int(struct dentry *dentry) |
1263 | { | 1263 | { |
1264 | const char *name = dentry->d_name.name; | 1264 | const char *name = dentry->d_name.name; |
1265 | int len = dentry->d_name.len; | 1265 | int len = dentry->d_name.len; |
1266 | unsigned n = 0; | 1266 | unsigned n = 0; |
1267 | 1267 | ||
1268 | if (len > 1 && *name == '0') | 1268 | if (len > 1 && *name == '0') |
1269 | goto out; | 1269 | goto out; |
1270 | while (len-- > 0) { | 1270 | while (len-- > 0) { |
1271 | unsigned c = *name++ - '0'; | 1271 | unsigned c = *name++ - '0'; |
1272 | if (c > 9) | 1272 | if (c > 9) |
1273 | goto out; | 1273 | goto out; |
1274 | if (n >= (~0U-9)/10) | 1274 | if (n >= (~0U-9)/10) |
1275 | goto out; | 1275 | goto out; |
1276 | n *= 10; | 1276 | n *= 10; |
1277 | n += c; | 1277 | n += c; |
1278 | } | 1278 | } |
1279 | return n; | 1279 | return n; |
1280 | out: | 1280 | out: |
1281 | return ~0U; | 1281 | return ~0U; |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | /* SMP-safe */ | 1284 | /* SMP-safe */ |
1285 | static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry, struct nameidata *nd) | 1285 | static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry, struct nameidata *nd) |
1286 | { | 1286 | { |
1287 | struct task_struct *task = proc_task(dir); | 1287 | struct task_struct *task = proc_task(dir); |
1288 | unsigned fd = name_to_int(dentry); | 1288 | unsigned fd = name_to_int(dentry); |
1289 | struct file * file; | 1289 | struct file * file; |
1290 | struct files_struct * files; | 1290 | struct files_struct * files; |
1291 | struct inode *inode; | 1291 | struct inode *inode; |
1292 | struct proc_inode *ei; | 1292 | struct proc_inode *ei; |
1293 | 1293 | ||
1294 | if (fd == ~0U) | 1294 | if (fd == ~0U) |
1295 | goto out; | 1295 | goto out; |
1296 | if (!pid_alive(task)) | 1296 | if (!pid_alive(task)) |
1297 | goto out; | 1297 | goto out; |
1298 | 1298 | ||
1299 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_FD_DIR+fd); | 1299 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_FD_DIR+fd); |
1300 | if (!inode) | 1300 | if (!inode) |
1301 | goto out; | 1301 | goto out; |
1302 | ei = PROC_I(inode); | 1302 | ei = PROC_I(inode); |
1303 | files = get_files_struct(task); | 1303 | files = get_files_struct(task); |
1304 | if (!files) | 1304 | if (!files) |
1305 | goto out_unlock; | 1305 | goto out_unlock; |
1306 | inode->i_mode = S_IFLNK; | 1306 | inode->i_mode = S_IFLNK; |
1307 | spin_lock(&files->file_lock); | 1307 | spin_lock(&files->file_lock); |
1308 | file = fcheck_files(files, fd); | 1308 | file = fcheck_files(files, fd); |
1309 | if (!file) | 1309 | if (!file) |
1310 | goto out_unlock2; | 1310 | goto out_unlock2; |
1311 | if (file->f_mode & 1) | 1311 | if (file->f_mode & 1) |
1312 | inode->i_mode |= S_IRUSR | S_IXUSR; | 1312 | inode->i_mode |= S_IRUSR | S_IXUSR; |
1313 | if (file->f_mode & 2) | 1313 | if (file->f_mode & 2) |
1314 | inode->i_mode |= S_IWUSR | S_IXUSR; | 1314 | inode->i_mode |= S_IWUSR | S_IXUSR; |
1315 | spin_unlock(&files->file_lock); | 1315 | spin_unlock(&files->file_lock); |
1316 | put_files_struct(files); | 1316 | put_files_struct(files); |
1317 | inode->i_op = &proc_pid_link_inode_operations; | 1317 | inode->i_op = &proc_pid_link_inode_operations; |
1318 | inode->i_size = 64; | 1318 | inode->i_size = 64; |
1319 | ei->op.proc_get_link = proc_fd_link; | 1319 | ei->op.proc_get_link = proc_fd_link; |
1320 | dentry->d_op = &tid_fd_dentry_operations; | 1320 | dentry->d_op = &tid_fd_dentry_operations; |
1321 | d_add(dentry, inode); | 1321 | d_add(dentry, inode); |
1322 | return NULL; | 1322 | return NULL; |
1323 | 1323 | ||
1324 | out_unlock2: | 1324 | out_unlock2: |
1325 | spin_unlock(&files->file_lock); | 1325 | spin_unlock(&files->file_lock); |
1326 | put_files_struct(files); | 1326 | put_files_struct(files); |
1327 | out_unlock: | 1327 | out_unlock: |
1328 | iput(inode); | 1328 | iput(inode); |
1329 | out: | 1329 | out: |
1330 | return ERR_PTR(-ENOENT); | 1330 | return ERR_PTR(-ENOENT); |
1331 | } | 1331 | } |
1332 | 1332 | ||
1333 | static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir); | 1333 | static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir); |
1334 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd); | 1334 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd); |
1335 | 1335 | ||
1336 | static struct file_operations proc_fd_operations = { | 1336 | static struct file_operations proc_fd_operations = { |
1337 | .read = generic_read_dir, | 1337 | .read = generic_read_dir, |
1338 | .readdir = proc_readfd, | 1338 | .readdir = proc_readfd, |
1339 | }; | 1339 | }; |
1340 | 1340 | ||
1341 | static struct file_operations proc_task_operations = { | 1341 | static struct file_operations proc_task_operations = { |
1342 | .read = generic_read_dir, | 1342 | .read = generic_read_dir, |
1343 | .readdir = proc_task_readdir, | 1343 | .readdir = proc_task_readdir, |
1344 | }; | 1344 | }; |
1345 | 1345 | ||
1346 | /* | 1346 | /* |
1347 | * proc directories can do almost nothing.. | 1347 | * proc directories can do almost nothing.. |
1348 | */ | 1348 | */ |
1349 | static struct inode_operations proc_fd_inode_operations = { | 1349 | static struct inode_operations proc_fd_inode_operations = { |
1350 | .lookup = proc_lookupfd, | 1350 | .lookup = proc_lookupfd, |
1351 | .permission = proc_permission, | 1351 | .permission = proc_permission, |
1352 | }; | 1352 | }; |
1353 | 1353 | ||
1354 | static struct inode_operations proc_task_inode_operations = { | 1354 | static struct inode_operations proc_task_inode_operations = { |
1355 | .lookup = proc_task_lookup, | 1355 | .lookup = proc_task_lookup, |
1356 | .permission = proc_permission, | 1356 | .permission = proc_permission, |
1357 | }; | 1357 | }; |
1358 | 1358 | ||
1359 | #ifdef CONFIG_SECURITY | 1359 | #ifdef CONFIG_SECURITY |
1360 | static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, | 1360 | static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, |
1361 | size_t count, loff_t *ppos) | 1361 | size_t count, loff_t *ppos) |
1362 | { | 1362 | { |
1363 | struct inode * inode = file->f_dentry->d_inode; | 1363 | struct inode * inode = file->f_dentry->d_inode; |
1364 | unsigned long page; | 1364 | unsigned long page; |
1365 | ssize_t length; | 1365 | ssize_t length; |
1366 | struct task_struct *task = proc_task(inode); | 1366 | struct task_struct *task = proc_task(inode); |
1367 | 1367 | ||
1368 | if (count > PAGE_SIZE) | 1368 | if (count > PAGE_SIZE) |
1369 | count = PAGE_SIZE; | 1369 | count = PAGE_SIZE; |
1370 | if (!(page = __get_free_page(GFP_KERNEL))) | 1370 | if (!(page = __get_free_page(GFP_KERNEL))) |
1371 | return -ENOMEM; | 1371 | return -ENOMEM; |
1372 | 1372 | ||
1373 | length = security_getprocattr(task, | 1373 | length = security_getprocattr(task, |
1374 | (char*)file->f_dentry->d_name.name, | 1374 | (char*)file->f_dentry->d_name.name, |
1375 | (void*)page, count); | 1375 | (void*)page, count); |
1376 | if (length >= 0) | 1376 | if (length >= 0) |
1377 | length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); | 1377 | length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); |
1378 | free_page(page); | 1378 | free_page(page); |
1379 | return length; | 1379 | return length; |
1380 | } | 1380 | } |
1381 | 1381 | ||
1382 | static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, | 1382 | static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, |
1383 | size_t count, loff_t *ppos) | 1383 | size_t count, loff_t *ppos) |
1384 | { | 1384 | { |
1385 | struct inode * inode = file->f_dentry->d_inode; | 1385 | struct inode * inode = file->f_dentry->d_inode; |
1386 | char *page; | 1386 | char *page; |
1387 | ssize_t length; | 1387 | ssize_t length; |
1388 | struct task_struct *task = proc_task(inode); | 1388 | struct task_struct *task = proc_task(inode); |
1389 | 1389 | ||
1390 | if (count > PAGE_SIZE) | 1390 | if (count > PAGE_SIZE) |
1391 | count = PAGE_SIZE; | 1391 | count = PAGE_SIZE; |
1392 | if (*ppos != 0) { | 1392 | if (*ppos != 0) { |
1393 | /* No partial writes. */ | 1393 | /* No partial writes. */ |
1394 | return -EINVAL; | 1394 | return -EINVAL; |
1395 | } | 1395 | } |
1396 | page = (char*)__get_free_page(GFP_USER); | 1396 | page = (char*)__get_free_page(GFP_USER); |
1397 | if (!page) | 1397 | if (!page) |
1398 | return -ENOMEM; | 1398 | return -ENOMEM; |
1399 | length = -EFAULT; | 1399 | length = -EFAULT; |
1400 | if (copy_from_user(page, buf, count)) | 1400 | if (copy_from_user(page, buf, count)) |
1401 | goto out; | 1401 | goto out; |
1402 | 1402 | ||
1403 | length = security_setprocattr(task, | 1403 | length = security_setprocattr(task, |
1404 | (char*)file->f_dentry->d_name.name, | 1404 | (char*)file->f_dentry->d_name.name, |
1405 | (void*)page, count); | 1405 | (void*)page, count); |
1406 | out: | 1406 | out: |
1407 | free_page((unsigned long) page); | 1407 | free_page((unsigned long) page); |
1408 | return length; | 1408 | return length; |
1409 | } | 1409 | } |
1410 | 1410 | ||
1411 | static struct file_operations proc_pid_attr_operations = { | 1411 | static struct file_operations proc_pid_attr_operations = { |
1412 | .read = proc_pid_attr_read, | 1412 | .read = proc_pid_attr_read, |
1413 | .write = proc_pid_attr_write, | 1413 | .write = proc_pid_attr_write, |
1414 | }; | 1414 | }; |
1415 | 1415 | ||
1416 | static struct file_operations proc_tid_attr_operations; | 1416 | static struct file_operations proc_tid_attr_operations; |
1417 | static struct inode_operations proc_tid_attr_inode_operations; | 1417 | static struct inode_operations proc_tid_attr_inode_operations; |
1418 | static struct file_operations proc_tgid_attr_operations; | 1418 | static struct file_operations proc_tgid_attr_operations; |
1419 | static struct inode_operations proc_tgid_attr_inode_operations; | 1419 | static struct inode_operations proc_tgid_attr_inode_operations; |
1420 | #endif | 1420 | #endif |
1421 | 1421 | ||
1422 | /* SMP-safe */ | 1422 | /* SMP-safe */ |
1423 | static struct dentry *proc_pident_lookup(struct inode *dir, | 1423 | static struct dentry *proc_pident_lookup(struct inode *dir, |
1424 | struct dentry *dentry, | 1424 | struct dentry *dentry, |
1425 | struct pid_entry *ents) | 1425 | struct pid_entry *ents) |
1426 | { | 1426 | { |
1427 | struct inode *inode; | 1427 | struct inode *inode; |
1428 | int error; | 1428 | int error; |
1429 | struct task_struct *task = proc_task(dir); | 1429 | struct task_struct *task = proc_task(dir); |
1430 | struct pid_entry *p; | 1430 | struct pid_entry *p; |
1431 | struct proc_inode *ei; | 1431 | struct proc_inode *ei; |
1432 | 1432 | ||
1433 | error = -ENOENT; | 1433 | error = -ENOENT; |
1434 | inode = NULL; | 1434 | inode = NULL; |
1435 | 1435 | ||
1436 | if (!pid_alive(task)) | 1436 | if (!pid_alive(task)) |
1437 | goto out; | 1437 | goto out; |
1438 | 1438 | ||
1439 | for (p = ents; p->name; p++) { | 1439 | for (p = ents; p->name; p++) { |
1440 | if (p->len != dentry->d_name.len) | 1440 | if (p->len != dentry->d_name.len) |
1441 | continue; | 1441 | continue; |
1442 | if (!memcmp(dentry->d_name.name, p->name, p->len)) | 1442 | if (!memcmp(dentry->d_name.name, p->name, p->len)) |
1443 | break; | 1443 | break; |
1444 | } | 1444 | } |
1445 | if (!p->name) | 1445 | if (!p->name) |
1446 | goto out; | 1446 | goto out; |
1447 | 1447 | ||
1448 | error = -EINVAL; | 1448 | error = -EINVAL; |
1449 | inode = proc_pid_make_inode(dir->i_sb, task, p->type); | 1449 | inode = proc_pid_make_inode(dir->i_sb, task, p->type); |
1450 | if (!inode) | 1450 | if (!inode) |
1451 | goto out; | 1451 | goto out; |
1452 | 1452 | ||
1453 | ei = PROC_I(inode); | 1453 | ei = PROC_I(inode); |
1454 | inode->i_mode = p->mode; | 1454 | inode->i_mode = p->mode; |
1455 | /* | 1455 | /* |
1456 | * Yes, it does not scale. And it should not. Don't add | 1456 | * Yes, it does not scale. And it should not. Don't add |
1457 | * new entries into /proc/<tgid>/ without very good reasons. | 1457 | * new entries into /proc/<tgid>/ without very good reasons. |
1458 | */ | 1458 | */ |
1459 | switch(p->type) { | 1459 | switch(p->type) { |
1460 | case PROC_TGID_TASK: | 1460 | case PROC_TGID_TASK: |
1461 | inode->i_nlink = 3; | 1461 | inode->i_nlink = 3; |
1462 | inode->i_op = &proc_task_inode_operations; | 1462 | inode->i_op = &proc_task_inode_operations; |
1463 | inode->i_fop = &proc_task_operations; | 1463 | inode->i_fop = &proc_task_operations; |
1464 | break; | 1464 | break; |
1465 | case PROC_TID_FD: | 1465 | case PROC_TID_FD: |
1466 | case PROC_TGID_FD: | 1466 | case PROC_TGID_FD: |
1467 | inode->i_nlink = 2; | 1467 | inode->i_nlink = 2; |
1468 | inode->i_op = &proc_fd_inode_operations; | 1468 | inode->i_op = &proc_fd_inode_operations; |
1469 | inode->i_fop = &proc_fd_operations; | 1469 | inode->i_fop = &proc_fd_operations; |
1470 | break; | 1470 | break; |
1471 | case PROC_TID_EXE: | 1471 | case PROC_TID_EXE: |
1472 | case PROC_TGID_EXE: | 1472 | case PROC_TGID_EXE: |
1473 | inode->i_op = &proc_pid_link_inode_operations; | 1473 | inode->i_op = &proc_pid_link_inode_operations; |
1474 | ei->op.proc_get_link = proc_exe_link; | 1474 | ei->op.proc_get_link = proc_exe_link; |
1475 | break; | 1475 | break; |
1476 | case PROC_TID_CWD: | 1476 | case PROC_TID_CWD: |
1477 | case PROC_TGID_CWD: | 1477 | case PROC_TGID_CWD: |
1478 | inode->i_op = &proc_pid_link_inode_operations; | 1478 | inode->i_op = &proc_pid_link_inode_operations; |
1479 | ei->op.proc_get_link = proc_cwd_link; | 1479 | ei->op.proc_get_link = proc_cwd_link; |
1480 | break; | 1480 | break; |
1481 | case PROC_TID_ROOT: | 1481 | case PROC_TID_ROOT: |
1482 | case PROC_TGID_ROOT: | 1482 | case PROC_TGID_ROOT: |
1483 | inode->i_op = &proc_pid_link_inode_operations; | 1483 | inode->i_op = &proc_pid_link_inode_operations; |
1484 | ei->op.proc_get_link = proc_root_link; | 1484 | ei->op.proc_get_link = proc_root_link; |
1485 | break; | 1485 | break; |
1486 | case PROC_TID_ENVIRON: | 1486 | case PROC_TID_ENVIRON: |
1487 | case PROC_TGID_ENVIRON: | 1487 | case PROC_TGID_ENVIRON: |
1488 | inode->i_fop = &proc_info_file_operations; | 1488 | inode->i_fop = &proc_info_file_operations; |
1489 | ei->op.proc_read = proc_pid_environ; | 1489 | ei->op.proc_read = proc_pid_environ; |
1490 | break; | 1490 | break; |
1491 | case PROC_TID_AUXV: | 1491 | case PROC_TID_AUXV: |
1492 | case PROC_TGID_AUXV: | 1492 | case PROC_TGID_AUXV: |
1493 | inode->i_fop = &proc_info_file_operations; | 1493 | inode->i_fop = &proc_info_file_operations; |
1494 | ei->op.proc_read = proc_pid_auxv; | 1494 | ei->op.proc_read = proc_pid_auxv; |
1495 | break; | 1495 | break; |
1496 | case PROC_TID_STATUS: | 1496 | case PROC_TID_STATUS: |
1497 | case PROC_TGID_STATUS: | 1497 | case PROC_TGID_STATUS: |
1498 | inode->i_fop = &proc_info_file_operations; | 1498 | inode->i_fop = &proc_info_file_operations; |
1499 | ei->op.proc_read = proc_pid_status; | 1499 | ei->op.proc_read = proc_pid_status; |
1500 | break; | 1500 | break; |
1501 | case PROC_TID_STAT: | 1501 | case PROC_TID_STAT: |
1502 | inode->i_fop = &proc_info_file_operations; | 1502 | inode->i_fop = &proc_info_file_operations; |
1503 | ei->op.proc_read = proc_tid_stat; | 1503 | ei->op.proc_read = proc_tid_stat; |
1504 | break; | 1504 | break; |
1505 | case PROC_TGID_STAT: | 1505 | case PROC_TGID_STAT: |
1506 | inode->i_fop = &proc_info_file_operations; | 1506 | inode->i_fop = &proc_info_file_operations; |
1507 | ei->op.proc_read = proc_tgid_stat; | 1507 | ei->op.proc_read = proc_tgid_stat; |
1508 | break; | 1508 | break; |
1509 | case PROC_TID_CMDLINE: | 1509 | case PROC_TID_CMDLINE: |
1510 | case PROC_TGID_CMDLINE: | 1510 | case PROC_TGID_CMDLINE: |
1511 | inode->i_fop = &proc_info_file_operations; | 1511 | inode->i_fop = &proc_info_file_operations; |
1512 | ei->op.proc_read = proc_pid_cmdline; | 1512 | ei->op.proc_read = proc_pid_cmdline; |
1513 | break; | 1513 | break; |
1514 | case PROC_TID_STATM: | 1514 | case PROC_TID_STATM: |
1515 | case PROC_TGID_STATM: | 1515 | case PROC_TGID_STATM: |
1516 | inode->i_fop = &proc_info_file_operations; | 1516 | inode->i_fop = &proc_info_file_operations; |
1517 | ei->op.proc_read = proc_pid_statm; | 1517 | ei->op.proc_read = proc_pid_statm; |
1518 | break; | 1518 | break; |
1519 | case PROC_TID_MAPS: | 1519 | case PROC_TID_MAPS: |
1520 | case PROC_TGID_MAPS: | 1520 | case PROC_TGID_MAPS: |
1521 | inode->i_fop = &proc_maps_operations; | 1521 | inode->i_fop = &proc_maps_operations; |
1522 | break; | 1522 | break; |
1523 | case PROC_TID_MEM: | 1523 | case PROC_TID_MEM: |
1524 | case PROC_TGID_MEM: | 1524 | case PROC_TGID_MEM: |
1525 | inode->i_op = &proc_mem_inode_operations; | 1525 | inode->i_op = &proc_mem_inode_operations; |
1526 | inode->i_fop = &proc_mem_operations; | 1526 | inode->i_fop = &proc_mem_operations; |
1527 | break; | 1527 | break; |
1528 | #ifdef CONFIG_SECCOMP | 1528 | #ifdef CONFIG_SECCOMP |
1529 | case PROC_TID_SECCOMP: | 1529 | case PROC_TID_SECCOMP: |
1530 | case PROC_TGID_SECCOMP: | 1530 | case PROC_TGID_SECCOMP: |
1531 | inode->i_fop = &proc_seccomp_operations; | 1531 | inode->i_fop = &proc_seccomp_operations; |
1532 | break; | 1532 | break; |
1533 | #endif /* CONFIG_SECCOMP */ | 1533 | #endif /* CONFIG_SECCOMP */ |
1534 | case PROC_TID_MOUNTS: | 1534 | case PROC_TID_MOUNTS: |
1535 | case PROC_TGID_MOUNTS: | 1535 | case PROC_TGID_MOUNTS: |
1536 | inode->i_fop = &proc_mounts_operations; | 1536 | inode->i_fop = &proc_mounts_operations; |
1537 | break; | 1537 | break; |
1538 | #ifdef CONFIG_SECURITY | 1538 | #ifdef CONFIG_SECURITY |
1539 | case PROC_TID_ATTR: | 1539 | case PROC_TID_ATTR: |
1540 | inode->i_nlink = 2; | 1540 | inode->i_nlink = 2; |
1541 | inode->i_op = &proc_tid_attr_inode_operations; | 1541 | inode->i_op = &proc_tid_attr_inode_operations; |
1542 | inode->i_fop = &proc_tid_attr_operations; | 1542 | inode->i_fop = &proc_tid_attr_operations; |
1543 | break; | 1543 | break; |
1544 | case PROC_TGID_ATTR: | 1544 | case PROC_TGID_ATTR: |
1545 | inode->i_nlink = 2; | 1545 | inode->i_nlink = 2; |
1546 | inode->i_op = &proc_tgid_attr_inode_operations; | 1546 | inode->i_op = &proc_tgid_attr_inode_operations; |
1547 | inode->i_fop = &proc_tgid_attr_operations; | 1547 | inode->i_fop = &proc_tgid_attr_operations; |
1548 | break; | 1548 | break; |
1549 | case PROC_TID_ATTR_CURRENT: | 1549 | case PROC_TID_ATTR_CURRENT: |
1550 | case PROC_TGID_ATTR_CURRENT: | 1550 | case PROC_TGID_ATTR_CURRENT: |
1551 | case PROC_TID_ATTR_PREV: | 1551 | case PROC_TID_ATTR_PREV: |
1552 | case PROC_TGID_ATTR_PREV: | 1552 | case PROC_TGID_ATTR_PREV: |
1553 | case PROC_TID_ATTR_EXEC: | 1553 | case PROC_TID_ATTR_EXEC: |
1554 | case PROC_TGID_ATTR_EXEC: | 1554 | case PROC_TGID_ATTR_EXEC: |
1555 | case PROC_TID_ATTR_FSCREATE: | 1555 | case PROC_TID_ATTR_FSCREATE: |
1556 | case PROC_TGID_ATTR_FSCREATE: | 1556 | case PROC_TGID_ATTR_FSCREATE: |
1557 | inode->i_fop = &proc_pid_attr_operations; | 1557 | inode->i_fop = &proc_pid_attr_operations; |
1558 | break; | 1558 | break; |
1559 | #endif | 1559 | #endif |
1560 | #ifdef CONFIG_KALLSYMS | 1560 | #ifdef CONFIG_KALLSYMS |
1561 | case PROC_TID_WCHAN: | 1561 | case PROC_TID_WCHAN: |
1562 | case PROC_TGID_WCHAN: | 1562 | case PROC_TGID_WCHAN: |
1563 | inode->i_fop = &proc_info_file_operations; | 1563 | inode->i_fop = &proc_info_file_operations; |
1564 | ei->op.proc_read = proc_pid_wchan; | 1564 | ei->op.proc_read = proc_pid_wchan; |
1565 | break; | 1565 | break; |
1566 | #endif | 1566 | #endif |
1567 | #ifdef CONFIG_SCHEDSTATS | 1567 | #ifdef CONFIG_SCHEDSTATS |
1568 | case PROC_TID_SCHEDSTAT: | 1568 | case PROC_TID_SCHEDSTAT: |
1569 | case PROC_TGID_SCHEDSTAT: | 1569 | case PROC_TGID_SCHEDSTAT: |
1570 | inode->i_fop = &proc_info_file_operations; | 1570 | inode->i_fop = &proc_info_file_operations; |
1571 | ei->op.proc_read = proc_pid_schedstat; | 1571 | ei->op.proc_read = proc_pid_schedstat; |
1572 | break; | 1572 | break; |
1573 | #endif | 1573 | #endif |
1574 | #ifdef CONFIG_CPUSETS | 1574 | #ifdef CONFIG_CPUSETS |
1575 | case PROC_TID_CPUSET: | 1575 | case PROC_TID_CPUSET: |
1576 | case PROC_TGID_CPUSET: | 1576 | case PROC_TGID_CPUSET: |
1577 | inode->i_fop = &proc_cpuset_operations; | 1577 | inode->i_fop = &proc_cpuset_operations; |
1578 | break; | 1578 | break; |
1579 | #endif | 1579 | #endif |
1580 | case PROC_TID_OOM_SCORE: | 1580 | case PROC_TID_OOM_SCORE: |
1581 | case PROC_TGID_OOM_SCORE: | 1581 | case PROC_TGID_OOM_SCORE: |
1582 | inode->i_fop = &proc_info_file_operations; | 1582 | inode->i_fop = &proc_info_file_operations; |
1583 | ei->op.proc_read = proc_oom_score; | 1583 | ei->op.proc_read = proc_oom_score; |
1584 | break; | 1584 | break; |
1585 | case PROC_TID_OOM_ADJUST: | 1585 | case PROC_TID_OOM_ADJUST: |
1586 | case PROC_TGID_OOM_ADJUST: | 1586 | case PROC_TGID_OOM_ADJUST: |
1587 | inode->i_fop = &proc_oom_adjust_operations; | 1587 | inode->i_fop = &proc_oom_adjust_operations; |
1588 | break; | 1588 | break; |
1589 | #ifdef CONFIG_AUDITSYSCALL | 1589 | #ifdef CONFIG_AUDITSYSCALL |
1590 | case PROC_TID_LOGINUID: | 1590 | case PROC_TID_LOGINUID: |
1591 | case PROC_TGID_LOGINUID: | 1591 | case PROC_TGID_LOGINUID: |
1592 | inode->i_fop = &proc_loginuid_operations; | 1592 | inode->i_fop = &proc_loginuid_operations; |
1593 | break; | 1593 | break; |
1594 | #endif | 1594 | #endif |
1595 | default: | 1595 | default: |
1596 | printk("procfs: impossible type (%d)",p->type); | 1596 | printk("procfs: impossible type (%d)",p->type); |
1597 | iput(inode); | 1597 | iput(inode); |
1598 | return ERR_PTR(-EINVAL); | 1598 | return ERR_PTR(-EINVAL); |
1599 | } | 1599 | } |
1600 | dentry->d_op = &pid_dentry_operations; | 1600 | dentry->d_op = &pid_dentry_operations; |
1601 | d_add(dentry, inode); | 1601 | d_add(dentry, inode); |
1602 | return NULL; | 1602 | return NULL; |
1603 | 1603 | ||
1604 | out: | 1604 | out: |
1605 | return ERR_PTR(error); | 1605 | return ERR_PTR(error); |
1606 | } | 1606 | } |
1607 | 1607 | ||
1608 | static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){ | 1608 | static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){ |
1609 | return proc_pident_lookup(dir, dentry, tgid_base_stuff); | 1609 | return proc_pident_lookup(dir, dentry, tgid_base_stuff); |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){ | 1612 | static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd){ |
1613 | return proc_pident_lookup(dir, dentry, tid_base_stuff); | 1613 | return proc_pident_lookup(dir, dentry, tid_base_stuff); |
1614 | } | 1614 | } |
1615 | 1615 | ||
1616 | static struct file_operations proc_tgid_base_operations = { | 1616 | static struct file_operations proc_tgid_base_operations = { |
1617 | .read = generic_read_dir, | 1617 | .read = generic_read_dir, |
1618 | .readdir = proc_tgid_base_readdir, | 1618 | .readdir = proc_tgid_base_readdir, |
1619 | }; | 1619 | }; |
1620 | 1620 | ||
1621 | static struct file_operations proc_tid_base_operations = { | 1621 | static struct file_operations proc_tid_base_operations = { |
1622 | .read = generic_read_dir, | 1622 | .read = generic_read_dir, |
1623 | .readdir = proc_tid_base_readdir, | 1623 | .readdir = proc_tid_base_readdir, |
1624 | }; | 1624 | }; |
1625 | 1625 | ||
1626 | static struct inode_operations proc_tgid_base_inode_operations = { | 1626 | static struct inode_operations proc_tgid_base_inode_operations = { |
1627 | .lookup = proc_tgid_base_lookup, | 1627 | .lookup = proc_tgid_base_lookup, |
1628 | }; | 1628 | }; |
1629 | 1629 | ||
1630 | static struct inode_operations proc_tid_base_inode_operations = { | 1630 | static struct inode_operations proc_tid_base_inode_operations = { |
1631 | .lookup = proc_tid_base_lookup, | 1631 | .lookup = proc_tid_base_lookup, |
1632 | }; | 1632 | }; |
1633 | 1633 | ||
1634 | #ifdef CONFIG_SECURITY | 1634 | #ifdef CONFIG_SECURITY |
1635 | static int proc_tgid_attr_readdir(struct file * filp, | 1635 | static int proc_tgid_attr_readdir(struct file * filp, |
1636 | void * dirent, filldir_t filldir) | 1636 | void * dirent, filldir_t filldir) |
1637 | { | 1637 | { |
1638 | return proc_pident_readdir(filp,dirent,filldir, | 1638 | return proc_pident_readdir(filp,dirent,filldir, |
1639 | tgid_attr_stuff,ARRAY_SIZE(tgid_attr_stuff)); | 1639 | tgid_attr_stuff,ARRAY_SIZE(tgid_attr_stuff)); |
1640 | } | 1640 | } |
1641 | 1641 | ||
1642 | static int proc_tid_attr_readdir(struct file * filp, | 1642 | static int proc_tid_attr_readdir(struct file * filp, |
1643 | void * dirent, filldir_t filldir) | 1643 | void * dirent, filldir_t filldir) |
1644 | { | 1644 | { |
1645 | return proc_pident_readdir(filp,dirent,filldir, | 1645 | return proc_pident_readdir(filp,dirent,filldir, |
1646 | tid_attr_stuff,ARRAY_SIZE(tid_attr_stuff)); | 1646 | tid_attr_stuff,ARRAY_SIZE(tid_attr_stuff)); |
1647 | } | 1647 | } |
1648 | 1648 | ||
1649 | static struct file_operations proc_tgid_attr_operations = { | 1649 | static struct file_operations proc_tgid_attr_operations = { |
1650 | .read = generic_read_dir, | 1650 | .read = generic_read_dir, |
1651 | .readdir = proc_tgid_attr_readdir, | 1651 | .readdir = proc_tgid_attr_readdir, |
1652 | }; | 1652 | }; |
1653 | 1653 | ||
1654 | static struct file_operations proc_tid_attr_operations = { | 1654 | static struct file_operations proc_tid_attr_operations = { |
1655 | .read = generic_read_dir, | 1655 | .read = generic_read_dir, |
1656 | .readdir = proc_tid_attr_readdir, | 1656 | .readdir = proc_tid_attr_readdir, |
1657 | }; | 1657 | }; |
1658 | 1658 | ||
1659 | static struct dentry *proc_tgid_attr_lookup(struct inode *dir, | 1659 | static struct dentry *proc_tgid_attr_lookup(struct inode *dir, |
1660 | struct dentry *dentry, struct nameidata *nd) | 1660 | struct dentry *dentry, struct nameidata *nd) |
1661 | { | 1661 | { |
1662 | return proc_pident_lookup(dir, dentry, tgid_attr_stuff); | 1662 | return proc_pident_lookup(dir, dentry, tgid_attr_stuff); |
1663 | } | 1663 | } |
1664 | 1664 | ||
1665 | static struct dentry *proc_tid_attr_lookup(struct inode *dir, | 1665 | static struct dentry *proc_tid_attr_lookup(struct inode *dir, |
1666 | struct dentry *dentry, struct nameidata *nd) | 1666 | struct dentry *dentry, struct nameidata *nd) |
1667 | { | 1667 | { |
1668 | return proc_pident_lookup(dir, dentry, tid_attr_stuff); | 1668 | return proc_pident_lookup(dir, dentry, tid_attr_stuff); |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | static struct inode_operations proc_tgid_attr_inode_operations = { | 1671 | static struct inode_operations proc_tgid_attr_inode_operations = { |
1672 | .lookup = proc_tgid_attr_lookup, | 1672 | .lookup = proc_tgid_attr_lookup, |
1673 | }; | 1673 | }; |
1674 | 1674 | ||
1675 | static struct inode_operations proc_tid_attr_inode_operations = { | 1675 | static struct inode_operations proc_tid_attr_inode_operations = { |
1676 | .lookup = proc_tid_attr_lookup, | 1676 | .lookup = proc_tid_attr_lookup, |
1677 | }; | 1677 | }; |
1678 | #endif | 1678 | #endif |
1679 | 1679 | ||
1680 | /* | 1680 | /* |
1681 | * /proc/self: | 1681 | * /proc/self: |
1682 | */ | 1682 | */ |
1683 | static int proc_self_readlink(struct dentry *dentry, char __user *buffer, | 1683 | static int proc_self_readlink(struct dentry *dentry, char __user *buffer, |
1684 | int buflen) | 1684 | int buflen) |
1685 | { | 1685 | { |
1686 | char tmp[30]; | 1686 | char tmp[30]; |
1687 | sprintf(tmp, "%d", current->tgid); | 1687 | sprintf(tmp, "%d", current->tgid); |
1688 | return vfs_readlink(dentry,buffer,buflen,tmp); | 1688 | return vfs_readlink(dentry,buffer,buflen,tmp); |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | static int proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) | 1691 | static int proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) |
1692 | { | 1692 | { |
1693 | char tmp[30]; | 1693 | char tmp[30]; |
1694 | sprintf(tmp, "%d", current->tgid); | 1694 | sprintf(tmp, "%d", current->tgid); |
1695 | return vfs_follow_link(nd,tmp); | 1695 | return vfs_follow_link(nd,tmp); |
1696 | } | 1696 | } |
1697 | 1697 | ||
1698 | static struct inode_operations proc_self_inode_operations = { | 1698 | static struct inode_operations proc_self_inode_operations = { |
1699 | .readlink = proc_self_readlink, | 1699 | .readlink = proc_self_readlink, |
1700 | .follow_link = proc_self_follow_link, | 1700 | .follow_link = proc_self_follow_link, |
1701 | }; | 1701 | }; |
1702 | 1702 | ||
1703 | /** | 1703 | /** |
1704 | * proc_pid_unhash - Unhash /proc/<pid> entry from the dcache. | 1704 | * proc_pid_unhash - Unhash /proc/<pid> entry from the dcache. |
1705 | * @p: task that should be flushed. | 1705 | * @p: task that should be flushed. |
1706 | * | 1706 | * |
1707 | * Drops the /proc/<pid> dcache entry from the hash chains. | 1707 | * Drops the /proc/<pid> dcache entry from the hash chains. |
1708 | * | 1708 | * |
1709 | * Dropping /proc/<pid> entries and detach_pid must be synchroneous, | 1709 | * Dropping /proc/<pid> entries and detach_pid must be synchroneous, |
1710 | * otherwise e.g. /proc/<pid>/exe might point to the wrong executable, | 1710 | * otherwise e.g. /proc/<pid>/exe might point to the wrong executable, |
1711 | * if the pid value is immediately reused. This is enforced by | 1711 | * if the pid value is immediately reused. This is enforced by |
1712 | * - caller must acquire spin_lock(p->proc_lock) | 1712 | * - caller must acquire spin_lock(p->proc_lock) |
1713 | * - must be called before detach_pid() | 1713 | * - must be called before detach_pid() |
1714 | * - proc_pid_lookup acquires proc_lock, and checks that | 1714 | * - proc_pid_lookup acquires proc_lock, and checks that |
1715 | * the target is not dead by looking at the attach count | 1715 | * the target is not dead by looking at the attach count |
1716 | * of PIDTYPE_PID. | 1716 | * of PIDTYPE_PID. |
1717 | */ | 1717 | */ |
1718 | 1718 | ||
1719 | struct dentry *proc_pid_unhash(struct task_struct *p) | 1719 | struct dentry *proc_pid_unhash(struct task_struct *p) |
1720 | { | 1720 | { |
1721 | struct dentry *proc_dentry; | 1721 | struct dentry *proc_dentry; |
1722 | 1722 | ||
1723 | proc_dentry = p->proc_dentry; | 1723 | proc_dentry = p->proc_dentry; |
1724 | if (proc_dentry != NULL) { | 1724 | if (proc_dentry != NULL) { |
1725 | 1725 | ||
1726 | spin_lock(&dcache_lock); | 1726 | spin_lock(&dcache_lock); |
1727 | spin_lock(&proc_dentry->d_lock); | 1727 | spin_lock(&proc_dentry->d_lock); |
1728 | if (!d_unhashed(proc_dentry)) { | 1728 | if (!d_unhashed(proc_dentry)) { |
1729 | dget_locked(proc_dentry); | 1729 | dget_locked(proc_dentry); |
1730 | __d_drop(proc_dentry); | 1730 | __d_drop(proc_dentry); |
1731 | spin_unlock(&proc_dentry->d_lock); | 1731 | spin_unlock(&proc_dentry->d_lock); |
1732 | } else { | 1732 | } else { |
1733 | spin_unlock(&proc_dentry->d_lock); | 1733 | spin_unlock(&proc_dentry->d_lock); |
1734 | proc_dentry = NULL; | 1734 | proc_dentry = NULL; |
1735 | } | 1735 | } |
1736 | spin_unlock(&dcache_lock); | 1736 | spin_unlock(&dcache_lock); |
1737 | } | 1737 | } |
1738 | return proc_dentry; | 1738 | return proc_dentry; |
1739 | } | 1739 | } |
1740 | 1740 | ||
1741 | /** | 1741 | /** |
1742 | * proc_pid_flush - recover memory used by stale /proc/<pid>/x entries | 1742 | * proc_pid_flush - recover memory used by stale /proc/<pid>/x entries |
1743 | * @proc_entry: directoy to prune. | 1743 | * @proc_entry: directoy to prune. |
1744 | * | 1744 | * |
1745 | * Shrink the /proc directory that was used by the just killed thread. | 1745 | * Shrink the /proc directory that was used by the just killed thread. |
1746 | */ | 1746 | */ |
1747 | 1747 | ||
1748 | void proc_pid_flush(struct dentry *proc_dentry) | 1748 | void proc_pid_flush(struct dentry *proc_dentry) |
1749 | { | 1749 | { |
1750 | might_sleep(); | 1750 | might_sleep(); |
1751 | if(proc_dentry != NULL) { | 1751 | if(proc_dentry != NULL) { |
1752 | shrink_dcache_parent(proc_dentry); | 1752 | shrink_dcache_parent(proc_dentry); |
1753 | dput(proc_dentry); | 1753 | dput(proc_dentry); |
1754 | } | 1754 | } |
1755 | } | 1755 | } |
1756 | 1756 | ||
1757 | /* SMP-safe */ | 1757 | /* SMP-safe */ |
1758 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) | 1758 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) |
1759 | { | 1759 | { |
1760 | struct task_struct *task; | 1760 | struct task_struct *task; |
1761 | struct inode *inode; | 1761 | struct inode *inode; |
1762 | struct proc_inode *ei; | 1762 | struct proc_inode *ei; |
1763 | unsigned tgid; | 1763 | unsigned tgid; |
1764 | int died; | 1764 | int died; |
1765 | 1765 | ||
1766 | if (dentry->d_name.len == 4 && !memcmp(dentry->d_name.name,"self",4)) { | 1766 | if (dentry->d_name.len == 4 && !memcmp(dentry->d_name.name,"self",4)) { |
1767 | inode = new_inode(dir->i_sb); | 1767 | inode = new_inode(dir->i_sb); |
1768 | if (!inode) | 1768 | if (!inode) |
1769 | return ERR_PTR(-ENOMEM); | 1769 | return ERR_PTR(-ENOMEM); |
1770 | ei = PROC_I(inode); | 1770 | ei = PROC_I(inode); |
1771 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 1771 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
1772 | inode->i_ino = fake_ino(0, PROC_TGID_INO); | 1772 | inode->i_ino = fake_ino(0, PROC_TGID_INO); |
1773 | ei->pde = NULL; | 1773 | ei->pde = NULL; |
1774 | inode->i_mode = S_IFLNK|S_IRWXUGO; | 1774 | inode->i_mode = S_IFLNK|S_IRWXUGO; |
1775 | inode->i_uid = inode->i_gid = 0; | 1775 | inode->i_uid = inode->i_gid = 0; |
1776 | inode->i_size = 64; | 1776 | inode->i_size = 64; |
1777 | inode->i_op = &proc_self_inode_operations; | 1777 | inode->i_op = &proc_self_inode_operations; |
1778 | d_add(dentry, inode); | 1778 | d_add(dentry, inode); |
1779 | return NULL; | 1779 | return NULL; |
1780 | } | 1780 | } |
1781 | tgid = name_to_int(dentry); | 1781 | tgid = name_to_int(dentry); |
1782 | if (tgid == ~0U) | 1782 | if (tgid == ~0U) |
1783 | goto out; | 1783 | goto out; |
1784 | 1784 | ||
1785 | read_lock(&tasklist_lock); | 1785 | read_lock(&tasklist_lock); |
1786 | task = find_task_by_pid(tgid); | 1786 | task = find_task_by_pid(tgid); |
1787 | if (task) | 1787 | if (task) |
1788 | get_task_struct(task); | 1788 | get_task_struct(task); |
1789 | read_unlock(&tasklist_lock); | 1789 | read_unlock(&tasklist_lock); |
1790 | if (!task) | 1790 | if (!task) |
1791 | goto out; | 1791 | goto out; |
1792 | 1792 | ||
1793 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TGID_INO); | 1793 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TGID_INO); |
1794 | 1794 | ||
1795 | 1795 | ||
1796 | if (!inode) { | 1796 | if (!inode) { |
1797 | put_task_struct(task); | 1797 | put_task_struct(task); |
1798 | goto out; | 1798 | goto out; |
1799 | } | 1799 | } |
1800 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; | 1800 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; |
1801 | inode->i_op = &proc_tgid_base_inode_operations; | 1801 | inode->i_op = &proc_tgid_base_inode_operations; |
1802 | inode->i_fop = &proc_tgid_base_operations; | 1802 | inode->i_fop = &proc_tgid_base_operations; |
1803 | inode->i_nlink = 3; | 1803 | inode->i_nlink = 3; |
1804 | inode->i_flags|=S_IMMUTABLE; | 1804 | inode->i_flags|=S_IMMUTABLE; |
1805 | 1805 | ||
1806 | dentry->d_op = &pid_base_dentry_operations; | 1806 | dentry->d_op = &pid_base_dentry_operations; |
1807 | 1807 | ||
1808 | died = 0; | 1808 | died = 0; |
1809 | d_add(dentry, inode); | 1809 | d_add(dentry, inode); |
1810 | spin_lock(&task->proc_lock); | 1810 | spin_lock(&task->proc_lock); |
1811 | task->proc_dentry = dentry; | 1811 | task->proc_dentry = dentry; |
1812 | if (!pid_alive(task)) { | 1812 | if (!pid_alive(task)) { |
1813 | dentry = proc_pid_unhash(task); | 1813 | dentry = proc_pid_unhash(task); |
1814 | died = 1; | 1814 | died = 1; |
1815 | } | 1815 | } |
1816 | spin_unlock(&task->proc_lock); | 1816 | spin_unlock(&task->proc_lock); |
1817 | 1817 | ||
1818 | put_task_struct(task); | 1818 | put_task_struct(task); |
1819 | if (died) { | 1819 | if (died) { |
1820 | proc_pid_flush(dentry); | 1820 | proc_pid_flush(dentry); |
1821 | goto out; | 1821 | goto out; |
1822 | } | 1822 | } |
1823 | return NULL; | 1823 | return NULL; |
1824 | out: | 1824 | out: |
1825 | return ERR_PTR(-ENOENT); | 1825 | return ERR_PTR(-ENOENT); |
1826 | } | 1826 | } |
1827 | 1827 | ||
1828 | /* SMP-safe */ | 1828 | /* SMP-safe */ |
1829 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) | 1829 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) |
1830 | { | 1830 | { |
1831 | struct task_struct *task; | 1831 | struct task_struct *task; |
1832 | struct task_struct *leader = proc_task(dir); | 1832 | struct task_struct *leader = proc_task(dir); |
1833 | struct inode *inode; | 1833 | struct inode *inode; |
1834 | unsigned tid; | 1834 | unsigned tid; |
1835 | 1835 | ||
1836 | tid = name_to_int(dentry); | 1836 | tid = name_to_int(dentry); |
1837 | if (tid == ~0U) | 1837 | if (tid == ~0U) |
1838 | goto out; | 1838 | goto out; |
1839 | 1839 | ||
1840 | read_lock(&tasklist_lock); | 1840 | read_lock(&tasklist_lock); |
1841 | task = find_task_by_pid(tid); | 1841 | task = find_task_by_pid(tid); |
1842 | if (task) | 1842 | if (task) |
1843 | get_task_struct(task); | 1843 | get_task_struct(task); |
1844 | read_unlock(&tasklist_lock); | 1844 | read_unlock(&tasklist_lock); |
1845 | if (!task) | 1845 | if (!task) |
1846 | goto out; | 1846 | goto out; |
1847 | if (leader->tgid != task->tgid) | 1847 | if (leader->tgid != task->tgid) |
1848 | goto out_drop_task; | 1848 | goto out_drop_task; |
1849 | 1849 | ||
1850 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_INO); | 1850 | inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_INO); |
1851 | 1851 | ||
1852 | 1852 | ||
1853 | if (!inode) | 1853 | if (!inode) |
1854 | goto out_drop_task; | 1854 | goto out_drop_task; |
1855 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; | 1855 | inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO; |
1856 | inode->i_op = &proc_tid_base_inode_operations; | 1856 | inode->i_op = &proc_tid_base_inode_operations; |
1857 | inode->i_fop = &proc_tid_base_operations; | 1857 | inode->i_fop = &proc_tid_base_operations; |
1858 | inode->i_nlink = 3; | 1858 | inode->i_nlink = 3; |
1859 | inode->i_flags|=S_IMMUTABLE; | 1859 | inode->i_flags|=S_IMMUTABLE; |
1860 | 1860 | ||
1861 | dentry->d_op = &pid_base_dentry_operations; | 1861 | dentry->d_op = &pid_base_dentry_operations; |
1862 | 1862 | ||
1863 | d_add(dentry, inode); | 1863 | d_add(dentry, inode); |
1864 | 1864 | ||
1865 | put_task_struct(task); | 1865 | put_task_struct(task); |
1866 | return NULL; | 1866 | return NULL; |
1867 | out_drop_task: | 1867 | out_drop_task: |
1868 | put_task_struct(task); | 1868 | put_task_struct(task); |
1869 | out: | 1869 | out: |
1870 | return ERR_PTR(-ENOENT); | 1870 | return ERR_PTR(-ENOENT); |
1871 | } | 1871 | } |
1872 | 1872 | ||
1873 | #define PROC_NUMBUF 10 | 1873 | #define PROC_NUMBUF 10 |
1874 | #define PROC_MAXPIDS 20 | 1874 | #define PROC_MAXPIDS 20 |
1875 | 1875 | ||
1876 | /* | 1876 | /* |
1877 | * Get a few tgid's to return for filldir - we need to hold the | 1877 | * Get a few tgid's to return for filldir - we need to hold the |
1878 | * tasklist lock while doing this, and we must release it before | 1878 | * tasklist lock while doing this, and we must release it before |
1879 | * we actually do the filldir itself, so we use a temp buffer.. | 1879 | * we actually do the filldir itself, so we use a temp buffer.. |
1880 | */ | 1880 | */ |
1881 | static int get_tgid_list(int index, unsigned long version, unsigned int *tgids) | 1881 | static int get_tgid_list(int index, unsigned long version, unsigned int *tgids) |
1882 | { | 1882 | { |
1883 | struct task_struct *p; | 1883 | struct task_struct *p; |
1884 | int nr_tgids = 0; | 1884 | int nr_tgids = 0; |
1885 | 1885 | ||
1886 | index--; | 1886 | index--; |
1887 | read_lock(&tasklist_lock); | 1887 | read_lock(&tasklist_lock); |
1888 | p = NULL; | 1888 | p = NULL; |
1889 | if (version) { | 1889 | if (version) { |
1890 | p = find_task_by_pid(version); | 1890 | p = find_task_by_pid(version); |
1891 | if (p && !thread_group_leader(p)) | 1891 | if (p && !thread_group_leader(p)) |
1892 | p = NULL; | 1892 | p = NULL; |
1893 | } | 1893 | } |
1894 | 1894 | ||
1895 | if (p) | 1895 | if (p) |
1896 | index = 0; | 1896 | index = 0; |
1897 | else | 1897 | else |
1898 | p = next_task(&init_task); | 1898 | p = next_task(&init_task); |
1899 | 1899 | ||
1900 | for ( ; p != &init_task; p = next_task(p)) { | 1900 | for ( ; p != &init_task; p = next_task(p)) { |
1901 | int tgid = p->pid; | 1901 | int tgid = p->pid; |
1902 | if (!pid_alive(p)) | 1902 | if (!pid_alive(p)) |
1903 | continue; | 1903 | continue; |
1904 | if (--index >= 0) | 1904 | if (--index >= 0) |
1905 | continue; | 1905 | continue; |
1906 | tgids[nr_tgids] = tgid; | 1906 | tgids[nr_tgids] = tgid; |
1907 | nr_tgids++; | 1907 | nr_tgids++; |
1908 | if (nr_tgids >= PROC_MAXPIDS) | 1908 | if (nr_tgids >= PROC_MAXPIDS) |
1909 | break; | 1909 | break; |
1910 | } | 1910 | } |
1911 | read_unlock(&tasklist_lock); | 1911 | read_unlock(&tasklist_lock); |
1912 | return nr_tgids; | 1912 | return nr_tgids; |
1913 | } | 1913 | } |
1914 | 1914 | ||
1915 | /* | 1915 | /* |
1916 | * Get a few tid's to return for filldir - we need to hold the | 1916 | * Get a few tid's to return for filldir - we need to hold the |
1917 | * tasklist lock while doing this, and we must release it before | 1917 | * tasklist lock while doing this, and we must release it before |
1918 | * we actually do the filldir itself, so we use a temp buffer.. | 1918 | * we actually do the filldir itself, so we use a temp buffer.. |
1919 | */ | 1919 | */ |
1920 | static int get_tid_list(int index, unsigned int *tids, struct inode *dir) | 1920 | static int get_tid_list(int index, unsigned int *tids, struct inode *dir) |
1921 | { | 1921 | { |
1922 | struct task_struct *leader_task = proc_task(dir); | 1922 | struct task_struct *leader_task = proc_task(dir); |
1923 | struct task_struct *task = leader_task; | 1923 | struct task_struct *task = leader_task; |
1924 | int nr_tids = 0; | 1924 | int nr_tids = 0; |
1925 | 1925 | ||
1926 | index -= 2; | 1926 | index -= 2; |
1927 | read_lock(&tasklist_lock); | 1927 | read_lock(&tasklist_lock); |
1928 | /* | 1928 | /* |
1929 | * The starting point task (leader_task) might be an already | 1929 | * The starting point task (leader_task) might be an already |
1930 | * unlinked task, which cannot be used to access the task-list | 1930 | * unlinked task, which cannot be used to access the task-list |
1931 | * via next_thread(). | 1931 | * via next_thread(). |
1932 | */ | 1932 | */ |
1933 | if (pid_alive(task)) do { | 1933 | if (pid_alive(task)) do { |
1934 | int tid = task->pid; | 1934 | int tid = task->pid; |
1935 | 1935 | ||
1936 | if (--index >= 0) | 1936 | if (--index >= 0) |
1937 | continue; | 1937 | continue; |
1938 | tids[nr_tids] = tid; | 1938 | tids[nr_tids] = tid; |
1939 | nr_tids++; | 1939 | nr_tids++; |
1940 | if (nr_tids >= PROC_MAXPIDS) | 1940 | if (nr_tids >= PROC_MAXPIDS) |
1941 | break; | 1941 | break; |
1942 | } while ((task = next_thread(task)) != leader_task); | 1942 | } while ((task = next_thread(task)) != leader_task); |
1943 | read_unlock(&tasklist_lock); | 1943 | read_unlock(&tasklist_lock); |
1944 | return nr_tids; | 1944 | return nr_tids; |
1945 | } | 1945 | } |
1946 | 1946 | ||
1947 | /* for the /proc/ directory itself, after non-process stuff has been done */ | 1947 | /* for the /proc/ directory itself, after non-process stuff has been done */ |
1948 | int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) | 1948 | int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) |
1949 | { | 1949 | { |
1950 | unsigned int tgid_array[PROC_MAXPIDS]; | 1950 | unsigned int tgid_array[PROC_MAXPIDS]; |
1951 | char buf[PROC_NUMBUF]; | 1951 | char buf[PROC_NUMBUF]; |
1952 | unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; | 1952 | unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; |
1953 | unsigned int nr_tgids, i; | 1953 | unsigned int nr_tgids, i; |
1954 | int next_tgid; | 1954 | int next_tgid; |
1955 | 1955 | ||
1956 | if (!nr) { | 1956 | if (!nr) { |
1957 | ino_t ino = fake_ino(0,PROC_TGID_INO); | 1957 | ino_t ino = fake_ino(0,PROC_TGID_INO); |
1958 | if (filldir(dirent, "self", 4, filp->f_pos, ino, DT_LNK) < 0) | 1958 | if (filldir(dirent, "self", 4, filp->f_pos, ino, DT_LNK) < 0) |
1959 | return 0; | 1959 | return 0; |
1960 | filp->f_pos++; | 1960 | filp->f_pos++; |
1961 | nr++; | 1961 | nr++; |
1962 | } | 1962 | } |
1963 | 1963 | ||
1964 | /* f_version caches the tgid value that the last readdir call couldn't | 1964 | /* f_version caches the tgid value that the last readdir call couldn't |
1965 | * return. lseek aka telldir automagically resets f_version to 0. | 1965 | * return. lseek aka telldir automagically resets f_version to 0. |
1966 | */ | 1966 | */ |
1967 | next_tgid = filp->f_version; | 1967 | next_tgid = filp->f_version; |
1968 | filp->f_version = 0; | 1968 | filp->f_version = 0; |
1969 | for (;;) { | 1969 | for (;;) { |
1970 | nr_tgids = get_tgid_list(nr, next_tgid, tgid_array); | 1970 | nr_tgids = get_tgid_list(nr, next_tgid, tgid_array); |
1971 | if (!nr_tgids) { | 1971 | if (!nr_tgids) { |
1972 | /* no more entries ! */ | 1972 | /* no more entries ! */ |
1973 | break; | 1973 | break; |
1974 | } | 1974 | } |
1975 | next_tgid = 0; | 1975 | next_tgid = 0; |
1976 | 1976 | ||
1977 | /* do not use the last found pid, reserve it for next_tgid */ | 1977 | /* do not use the last found pid, reserve it for next_tgid */ |
1978 | if (nr_tgids == PROC_MAXPIDS) { | 1978 | if (nr_tgids == PROC_MAXPIDS) { |
1979 | nr_tgids--; | 1979 | nr_tgids--; |
1980 | next_tgid = tgid_array[nr_tgids]; | 1980 | next_tgid = tgid_array[nr_tgids]; |
1981 | } | 1981 | } |
1982 | 1982 | ||
1983 | for (i=0;i<nr_tgids;i++) { | 1983 | for (i=0;i<nr_tgids;i++) { |
1984 | int tgid = tgid_array[i]; | 1984 | int tgid = tgid_array[i]; |
1985 | ino_t ino = fake_ino(tgid,PROC_TGID_INO); | 1985 | ino_t ino = fake_ino(tgid,PROC_TGID_INO); |
1986 | unsigned long j = PROC_NUMBUF; | 1986 | unsigned long j = PROC_NUMBUF; |
1987 | 1987 | ||
1988 | do | 1988 | do |
1989 | buf[--j] = '0' + (tgid % 10); | 1989 | buf[--j] = '0' + (tgid % 10); |
1990 | while ((tgid /= 10) != 0); | 1990 | while ((tgid /= 10) != 0); |
1991 | 1991 | ||
1992 | if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino, DT_DIR) < 0) { | 1992 | if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino, DT_DIR) < 0) { |
1993 | /* returning this tgid failed, save it as the first | 1993 | /* returning this tgid failed, save it as the first |
1994 | * pid for the next readir call */ | 1994 | * pid for the next readir call */ |
1995 | filp->f_version = tgid_array[i]; | 1995 | filp->f_version = tgid_array[i]; |
1996 | goto out; | 1996 | goto out; |
1997 | } | 1997 | } |
1998 | filp->f_pos++; | 1998 | filp->f_pos++; |
1999 | nr++; | 1999 | nr++; |
2000 | } | 2000 | } |
2001 | } | 2001 | } |
2002 | out: | 2002 | out: |
2003 | return 0; | 2003 | return 0; |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | /* for the /proc/TGID/task/ directories */ | 2006 | /* for the /proc/TGID/task/ directories */ |
2007 | static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir) | 2007 | static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir) |
2008 | { | 2008 | { |
2009 | unsigned int tid_array[PROC_MAXPIDS]; | 2009 | unsigned int tid_array[PROC_MAXPIDS]; |
2010 | char buf[PROC_NUMBUF]; | 2010 | char buf[PROC_NUMBUF]; |
2011 | unsigned int nr_tids, i; | 2011 | unsigned int nr_tids, i; |
2012 | struct dentry *dentry = filp->f_dentry; | 2012 | struct dentry *dentry = filp->f_dentry; |
2013 | struct inode *inode = dentry->d_inode; | 2013 | struct inode *inode = dentry->d_inode; |
2014 | int retval = -ENOENT; | 2014 | int retval = -ENOENT; |
2015 | ino_t ino; | 2015 | ino_t ino; |
2016 | unsigned long pos = filp->f_pos; /* avoiding "long long" filp->f_pos */ | 2016 | unsigned long pos = filp->f_pos; /* avoiding "long long" filp->f_pos */ |
2017 | 2017 | ||
2018 | if (!pid_alive(proc_task(inode))) | 2018 | if (!pid_alive(proc_task(inode))) |
2019 | goto out; | 2019 | goto out; |
2020 | retval = 0; | 2020 | retval = 0; |
2021 | 2021 | ||
2022 | switch (pos) { | 2022 | switch (pos) { |
2023 | case 0: | 2023 | case 0: |
2024 | ino = inode->i_ino; | 2024 | ino = inode->i_ino; |
2025 | if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0) | 2025 | if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0) |
2026 | goto out; | 2026 | goto out; |
2027 | pos++; | 2027 | pos++; |
2028 | /* fall through */ | 2028 | /* fall through */ |
2029 | case 1: | 2029 | case 1: |
2030 | ino = parent_ino(dentry); | 2030 | ino = parent_ino(dentry); |
2031 | if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0) | 2031 | if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0) |
2032 | goto out; | 2032 | goto out; |
2033 | pos++; | 2033 | pos++; |
2034 | /* fall through */ | 2034 | /* fall through */ |
2035 | } | 2035 | } |
2036 | 2036 | ||
2037 | nr_tids = get_tid_list(pos, tid_array, inode); | 2037 | nr_tids = get_tid_list(pos, tid_array, inode); |
2038 | 2038 | ||
2039 | for (i = 0; i < nr_tids; i++) { | 2039 | for (i = 0; i < nr_tids; i++) { |
2040 | unsigned long j = PROC_NUMBUF; | 2040 | unsigned long j = PROC_NUMBUF; |
2041 | int tid = tid_array[i]; | 2041 | int tid = tid_array[i]; |
2042 | 2042 | ||
2043 | ino = fake_ino(tid,PROC_TID_INO); | 2043 | ino = fake_ino(tid,PROC_TID_INO); |
2044 | 2044 | ||
2045 | do | 2045 | do |
2046 | buf[--j] = '0' + (tid % 10); | 2046 | buf[--j] = '0' + (tid % 10); |
2047 | while ((tid /= 10) != 0); | 2047 | while ((tid /= 10) != 0); |
2048 | 2048 | ||
2049 | if (filldir(dirent, buf+j, PROC_NUMBUF-j, pos, ino, DT_DIR) < 0) | 2049 | if (filldir(dirent, buf+j, PROC_NUMBUF-j, pos, ino, DT_DIR) < 0) |
2050 | break; | 2050 | break; |
2051 | pos++; | 2051 | pos++; |
2052 | } | 2052 | } |
2053 | out: | 2053 | out: |
2054 | filp->f_pos = pos; | 2054 | filp->f_pos = pos; |
2055 | return retval; | 2055 | return retval; |
2056 | } | 2056 | } |
2057 | 2057 |
include/linux/audit.h
1 | /* audit.h -- Auditing support | 1 | /* audit.h -- Auditing support |
2 | * | 2 | * |
3 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. | 3 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. |
4 | * All Rights Reserved. | 4 | * All Rights Reserved. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or | 8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | * | 19 | * |
20 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> | 20 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> |
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef _LINUX_AUDIT_H_ | 24 | #ifndef _LINUX_AUDIT_H_ |
25 | #define _LINUX_AUDIT_H_ | 25 | #define _LINUX_AUDIT_H_ |
26 | 26 | ||
27 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
28 | #include <linux/elf.h> | 28 | #include <linux/elf.h> |
29 | 29 | ||
30 | /* Request and reply types */ | 30 | /* Request and reply types */ |
31 | #define AUDIT_GET 1000 /* Get status */ | 31 | #define AUDIT_GET 1000 /* Get status */ |
32 | #define AUDIT_SET 1001 /* Set status (enable/disable/auditd) */ | 32 | #define AUDIT_SET 1001 /* Set status (enable/disable/auditd) */ |
33 | #define AUDIT_LIST 1002 /* List filtering rules */ | 33 | #define AUDIT_LIST 1002 /* List filtering rules */ |
34 | #define AUDIT_ADD 1003 /* Add filtering rule */ | 34 | #define AUDIT_ADD 1003 /* Add filtering rule */ |
35 | #define AUDIT_DEL 1004 /* Delete filtering rule */ | 35 | #define AUDIT_DEL 1004 /* Delete filtering rule */ |
36 | #define AUDIT_USER 1005 /* Send a message from user-space */ | 36 | #define AUDIT_USER 1005 /* Send a message from user-space */ |
37 | #define AUDIT_LOGIN 1006 /* Define the login id and informaiton */ | 37 | #define AUDIT_LOGIN 1006 /* Define the login id and informaiton */ |
38 | #define AUDIT_KERNEL 2000 /* Asynchronous audit record. NOT A REQUEST. */ | 38 | #define AUDIT_KERNEL 2000 /* Asynchronous audit record. NOT A REQUEST. */ |
39 | 39 | ||
40 | /* Rule flags */ | 40 | /* Rule flags */ |
41 | #define AUDIT_PER_TASK 0x01 /* Apply rule at task creation (not syscall) */ | 41 | #define AUDIT_PER_TASK 0x01 /* Apply rule at task creation (not syscall) */ |
42 | #define AUDIT_AT_ENTRY 0x02 /* Apply rule at syscall entry */ | 42 | #define AUDIT_AT_ENTRY 0x02 /* Apply rule at syscall entry */ |
43 | #define AUDIT_AT_EXIT 0x04 /* Apply rule at syscall exit */ | 43 | #define AUDIT_AT_EXIT 0x04 /* Apply rule at syscall exit */ |
44 | #define AUDIT_PREPEND 0x10 /* Prepend to front of list */ | 44 | #define AUDIT_PREPEND 0x10 /* Prepend to front of list */ |
45 | 45 | ||
46 | /* Rule actions */ | 46 | /* Rule actions */ |
47 | #define AUDIT_NEVER 0 /* Do not build context if rule matches */ | 47 | #define AUDIT_NEVER 0 /* Do not build context if rule matches */ |
48 | #define AUDIT_POSSIBLE 1 /* Build context if rule matches */ | 48 | #define AUDIT_POSSIBLE 1 /* Build context if rule matches */ |
49 | #define AUDIT_ALWAYS 2 /* Generate audit record if rule matches */ | 49 | #define AUDIT_ALWAYS 2 /* Generate audit record if rule matches */ |
50 | 50 | ||
51 | /* Rule structure sizes -- if these change, different AUDIT_ADD and | 51 | /* Rule structure sizes -- if these change, different AUDIT_ADD and |
52 | * AUDIT_LIST commands must be implemented. */ | 52 | * AUDIT_LIST commands must be implemented. */ |
53 | #define AUDIT_MAX_FIELDS 64 | 53 | #define AUDIT_MAX_FIELDS 64 |
54 | #define AUDIT_BITMASK_SIZE 64 | 54 | #define AUDIT_BITMASK_SIZE 64 |
55 | #define AUDIT_WORD(nr) ((__u32)((nr)/32)) | 55 | #define AUDIT_WORD(nr) ((__u32)((nr)/32)) |
56 | #define AUDIT_BIT(nr) (1 << ((nr) - AUDIT_WORD(nr)*32)) | 56 | #define AUDIT_BIT(nr) (1 << ((nr) - AUDIT_WORD(nr)*32)) |
57 | 57 | ||
58 | /* Rule fields */ | 58 | /* Rule fields */ |
59 | /* These are useful when checking the | 59 | /* These are useful when checking the |
60 | * task structure at task creation time | 60 | * task structure at task creation time |
61 | * (AUDIT_PER_TASK). */ | 61 | * (AUDIT_PER_TASK). */ |
62 | #define AUDIT_PID 0 | 62 | #define AUDIT_PID 0 |
63 | #define AUDIT_UID 1 | 63 | #define AUDIT_UID 1 |
64 | #define AUDIT_EUID 2 | 64 | #define AUDIT_EUID 2 |
65 | #define AUDIT_SUID 3 | 65 | #define AUDIT_SUID 3 |
66 | #define AUDIT_FSUID 4 | 66 | #define AUDIT_FSUID 4 |
67 | #define AUDIT_GID 5 | 67 | #define AUDIT_GID 5 |
68 | #define AUDIT_EGID 6 | 68 | #define AUDIT_EGID 6 |
69 | #define AUDIT_SGID 7 | 69 | #define AUDIT_SGID 7 |
70 | #define AUDIT_FSGID 8 | 70 | #define AUDIT_FSGID 8 |
71 | #define AUDIT_LOGINUID 9 | 71 | #define AUDIT_LOGINUID 9 |
72 | #define AUDIT_PERS 10 | 72 | #define AUDIT_PERS 10 |
73 | #define AUDIT_ARCH 11 | 73 | #define AUDIT_ARCH 11 |
74 | 74 | ||
75 | /* These are ONLY useful when checking | 75 | /* These are ONLY useful when checking |
76 | * at syscall exit time (AUDIT_AT_EXIT). */ | 76 | * at syscall exit time (AUDIT_AT_EXIT). */ |
77 | #define AUDIT_DEVMAJOR 100 | 77 | #define AUDIT_DEVMAJOR 100 |
78 | #define AUDIT_DEVMINOR 101 | 78 | #define AUDIT_DEVMINOR 101 |
79 | #define AUDIT_INODE 102 | 79 | #define AUDIT_INODE 102 |
80 | #define AUDIT_EXIT 103 | 80 | #define AUDIT_EXIT 103 |
81 | #define AUDIT_SUCCESS 104 /* exit >= 0; value ignored */ | 81 | #define AUDIT_SUCCESS 104 /* exit >= 0; value ignored */ |
82 | 82 | ||
83 | #define AUDIT_ARG0 200 | 83 | #define AUDIT_ARG0 200 |
84 | #define AUDIT_ARG1 (AUDIT_ARG0+1) | 84 | #define AUDIT_ARG1 (AUDIT_ARG0+1) |
85 | #define AUDIT_ARG2 (AUDIT_ARG0+2) | 85 | #define AUDIT_ARG2 (AUDIT_ARG0+2) |
86 | #define AUDIT_ARG3 (AUDIT_ARG0+3) | 86 | #define AUDIT_ARG3 (AUDIT_ARG0+3) |
87 | 87 | ||
88 | #define AUDIT_NEGATE 0x80000000 | 88 | #define AUDIT_NEGATE 0x80000000 |
89 | 89 | ||
90 | 90 | ||
91 | /* Status symbols */ | 91 | /* Status symbols */ |
92 | /* Mask values */ | 92 | /* Mask values */ |
93 | #define AUDIT_STATUS_ENABLED 0x0001 | 93 | #define AUDIT_STATUS_ENABLED 0x0001 |
94 | #define AUDIT_STATUS_FAILURE 0x0002 | 94 | #define AUDIT_STATUS_FAILURE 0x0002 |
95 | #define AUDIT_STATUS_PID 0x0004 | 95 | #define AUDIT_STATUS_PID 0x0004 |
96 | #define AUDIT_STATUS_RATE_LIMIT 0x0008 | 96 | #define AUDIT_STATUS_RATE_LIMIT 0x0008 |
97 | #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010 | 97 | #define AUDIT_STATUS_BACKLOG_LIMIT 0x0010 |
98 | /* Failure-to-log actions */ | 98 | /* Failure-to-log actions */ |
99 | #define AUDIT_FAIL_SILENT 0 | 99 | #define AUDIT_FAIL_SILENT 0 |
100 | #define AUDIT_FAIL_PRINTK 1 | 100 | #define AUDIT_FAIL_PRINTK 1 |
101 | #define AUDIT_FAIL_PANIC 2 | 101 | #define AUDIT_FAIL_PANIC 2 |
102 | 102 | ||
103 | /* distinguish syscall tables */ | 103 | /* distinguish syscall tables */ |
104 | #define __AUDIT_ARCH_64BIT 0x80000000 | 104 | #define __AUDIT_ARCH_64BIT 0x80000000 |
105 | #define __AUDIT_ARCH_LE 0x40000000 | 105 | #define __AUDIT_ARCH_LE 0x40000000 |
106 | #define AUDIT_ARCH_ALPHA (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) | 106 | #define AUDIT_ARCH_ALPHA (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
107 | #define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE) | 107 | #define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE) |
108 | #define AUDIT_ARCH_ARMEB (EM_ARM) | 108 | #define AUDIT_ARCH_ARMEB (EM_ARM) |
109 | #define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) | 109 | #define AUDIT_ARCH_CRIS (EM_CRIS|__AUDIT_ARCH_LE) |
110 | #define AUDIT_ARCH_FRV (EM_FRV) | 110 | #define AUDIT_ARCH_FRV (EM_FRV) |
111 | #define AUDIT_ARCH_H8300 (EM_H8_300) | 111 | #define AUDIT_ARCH_H8300 (EM_H8_300) |
112 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) | 112 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) |
113 | #define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) | 113 | #define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
114 | #define AUDIT_ARCH_M32R (EM_M32R) | 114 | #define AUDIT_ARCH_M32R (EM_M32R) |
115 | #define AUDIT_ARCH_M68K (EM_68K) | 115 | #define AUDIT_ARCH_M68K (EM_68K) |
116 | #define AUDIT_ARCH_MIPS (EM_MIPS) | 116 | #define AUDIT_ARCH_MIPS (EM_MIPS) |
117 | #define AUDIT_ARCH_MIPSEL (EM_MIPS|__AUDIT_ARCH_LE) | 117 | #define AUDIT_ARCH_MIPSEL (EM_MIPS|__AUDIT_ARCH_LE) |
118 | #define AUDIT_ARCH_MIPS64 (EM_MIPS|__AUDIT_ARCH_64BIT) | 118 | #define AUDIT_ARCH_MIPS64 (EM_MIPS|__AUDIT_ARCH_64BIT) |
119 | #define AUDIT_ARCH_MIPSEL64 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) | 119 | #define AUDIT_ARCH_MIPSEL64 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
120 | #define AUDIT_ARCH_PARISC (EM_PARISC) | 120 | #define AUDIT_ARCH_PARISC (EM_PARISC) |
121 | #define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT) | 121 | #define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT) |
122 | #define AUDIT_ARCH_PPC (EM_PPC) | 122 | #define AUDIT_ARCH_PPC (EM_PPC) |
123 | #define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT) | 123 | #define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT) |
124 | #define AUDIT_ARCH_S390 (EM_S390) | 124 | #define AUDIT_ARCH_S390 (EM_S390) |
125 | #define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT) | 125 | #define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT) |
126 | #define AUDIT_ARCH_SH (EM_SH) | 126 | #define AUDIT_ARCH_SH (EM_SH) |
127 | #define AUDIT_ARCH_SHEL (EM_SH|__AUDIT_ARCH_LE) | 127 | #define AUDIT_ARCH_SHEL (EM_SH|__AUDIT_ARCH_LE) |
128 | #define AUDIT_ARCH_SH64 (EM_SH|__AUDIT_ARCH_64BIT) | 128 | #define AUDIT_ARCH_SH64 (EM_SH|__AUDIT_ARCH_64BIT) |
129 | #define AUDIT_ARCH_SHEL64 (EM_SH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) | 129 | #define AUDIT_ARCH_SHEL64 (EM_SH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
130 | #define AUDIT_ARCH_SPARC (EM_SPARC) | 130 | #define AUDIT_ARCH_SPARC (EM_SPARC) |
131 | #define AUDIT_ARCH_SPARC64 (EM_SPARC64|__AUDIT_ARCH_64BIT) | 131 | #define AUDIT_ARCH_SPARC64 (EM_SPARC64|__AUDIT_ARCH_64BIT) |
132 | #define AUDIT_ARCH_V850 (EM_V850|__AUDIT_ARCH_LE) | 132 | #define AUDIT_ARCH_V850 (EM_V850|__AUDIT_ARCH_LE) |
133 | #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) | 133 | #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
134 | 134 | ||
135 | #ifndef __KERNEL__ | 135 | #ifndef __KERNEL__ |
136 | struct audit_message { | 136 | struct audit_message { |
137 | struct nlmsghdr nlh; | 137 | struct nlmsghdr nlh; |
138 | char data[1200]; | 138 | char data[1200]; |
139 | }; | 139 | }; |
140 | #endif | 140 | #endif |
141 | 141 | ||
142 | struct audit_status { | 142 | struct audit_status { |
143 | __u32 mask; /* Bit mask for valid entries */ | 143 | __u32 mask; /* Bit mask for valid entries */ |
144 | __u32 enabled; /* 1 = enabled, 0 = disbaled */ | 144 | __u32 enabled; /* 1 = enabled, 0 = disbaled */ |
145 | __u32 failure; /* Failure-to-log action */ | 145 | __u32 failure; /* Failure-to-log action */ |
146 | __u32 pid; /* pid of auditd process */ | 146 | __u32 pid; /* pid of auditd process */ |
147 | __u32 rate_limit; /* messages rate limit (per second) */ | 147 | __u32 rate_limit; /* messages rate limit (per second) */ |
148 | __u32 backlog_limit; /* waiting messages limit */ | 148 | __u32 backlog_limit; /* waiting messages limit */ |
149 | __u32 lost; /* messages lost */ | 149 | __u32 lost; /* messages lost */ |
150 | __u32 backlog; /* messages waiting in queue */ | 150 | __u32 backlog; /* messages waiting in queue */ |
151 | }; | 151 | }; |
152 | 152 | ||
153 | struct audit_rule { /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */ | 153 | struct audit_rule { /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */ |
154 | __u32 flags; /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */ | 154 | __u32 flags; /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */ |
155 | __u32 action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */ | 155 | __u32 action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */ |
156 | __u32 field_count; | 156 | __u32 field_count; |
157 | __u32 mask[AUDIT_BITMASK_SIZE]; | 157 | __u32 mask[AUDIT_BITMASK_SIZE]; |
158 | __u32 fields[AUDIT_MAX_FIELDS]; | 158 | __u32 fields[AUDIT_MAX_FIELDS]; |
159 | __u32 values[AUDIT_MAX_FIELDS]; | 159 | __u32 values[AUDIT_MAX_FIELDS]; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | #ifdef __KERNEL__ | 162 | #ifdef __KERNEL__ |
163 | 163 | ||
164 | struct audit_buffer; | 164 | struct audit_buffer; |
165 | struct audit_context; | 165 | struct audit_context; |
166 | struct inode; | 166 | struct inode; |
167 | 167 | ||
168 | #define AUDITSC_INVALID 0 | 168 | #define AUDITSC_INVALID 0 |
169 | #define AUDITSC_SUCCESS 1 | 169 | #define AUDITSC_SUCCESS 1 |
170 | #define AUDITSC_FAILURE 2 | 170 | #define AUDITSC_FAILURE 2 |
171 | #define AUDITSC_RESULT(x) ( ((long)(x))<0?AUDITSC_FAILURE:AUDITSC_SUCCESS ) | 171 | #define AUDITSC_RESULT(x) ( ((long)(x))<0?AUDITSC_FAILURE:AUDITSC_SUCCESS ) |
172 | #ifdef CONFIG_AUDITSYSCALL | 172 | #ifdef CONFIG_AUDITSYSCALL |
173 | /* These are defined in auditsc.c */ | 173 | /* These are defined in auditsc.c */ |
174 | /* Public API */ | 174 | /* Public API */ |
175 | extern int audit_alloc(struct task_struct *task); | 175 | extern int audit_alloc(struct task_struct *task); |
176 | extern void audit_free(struct task_struct *task); | 176 | extern void audit_free(struct task_struct *task); |
177 | extern void audit_syscall_entry(struct task_struct *task, int arch, | 177 | extern void audit_syscall_entry(struct task_struct *task, int arch, |
178 | int major, unsigned long a0, unsigned long a1, | 178 | int major, unsigned long a0, unsigned long a1, |
179 | unsigned long a2, unsigned long a3); | 179 | unsigned long a2, unsigned long a3); |
180 | extern void audit_syscall_exit(struct task_struct *task, int failed, long return_code); | 180 | extern void audit_syscall_exit(struct task_struct *task, int failed, long return_code); |
181 | extern void audit_getname(const char *name); | 181 | extern void audit_getname(const char *name); |
182 | extern void audit_putname(const char *name); | 182 | extern void audit_putname(const char *name); |
183 | extern void audit_inode(const char *name, const struct inode *inode); | 183 | extern void audit_inode(const char *name, const struct inode *inode); |
184 | 184 | ||
185 | /* Private API (for audit.c only) */ | 185 | /* Private API (for audit.c only) */ |
186 | extern int audit_receive_filter(int type, int pid, int uid, int seq, | 186 | extern int audit_receive_filter(int type, int pid, int uid, int seq, |
187 | void *data, uid_t loginuid); | 187 | void *data, uid_t loginuid); |
188 | extern void audit_get_stamp(struct audit_context *ctx, | 188 | extern void audit_get_stamp(struct audit_context *ctx, |
189 | struct timespec *t, unsigned int *serial); | 189 | struct timespec *t, unsigned int *serial); |
190 | extern int audit_set_loginuid(struct audit_context *ctx, uid_t loginuid); | 190 | extern int audit_set_loginuid(struct task_struct *task, uid_t loginuid); |
191 | extern uid_t audit_get_loginuid(struct audit_context *ctx); | 191 | extern uid_t audit_get_loginuid(struct audit_context *ctx); |
192 | extern int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode); | 192 | extern int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode); |
193 | #else | 193 | #else |
194 | #define audit_alloc(t) ({ 0; }) | 194 | #define audit_alloc(t) ({ 0; }) |
195 | #define audit_free(t) do { ; } while (0) | 195 | #define audit_free(t) do { ; } while (0) |
196 | #define audit_syscall_entry(t,ta,a,b,c,d,e) do { ; } while (0) | 196 | #define audit_syscall_entry(t,ta,a,b,c,d,e) do { ; } while (0) |
197 | #define audit_syscall_exit(t,f,r) do { ; } while (0) | 197 | #define audit_syscall_exit(t,f,r) do { ; } while (0) |
198 | #define audit_getname(n) do { ; } while (0) | 198 | #define audit_getname(n) do { ; } while (0) |
199 | #define audit_putname(n) do { ; } while (0) | 199 | #define audit_putname(n) do { ; } while (0) |
200 | #define audit_inode(n,i) do { ; } while (0) | 200 | #define audit_inode(n,i) do { ; } while (0) |
201 | #define audit_get_loginuid(c) ({ -1; }) | 201 | #define audit_get_loginuid(c) ({ -1; }) |
202 | #define audit_ipc_perms(q,u,g,m) ({ 0; }) | 202 | #define audit_ipc_perms(q,u,g,m) ({ 0; }) |
203 | #endif | 203 | #endif |
204 | 204 | ||
205 | #ifdef CONFIG_AUDIT | 205 | #ifdef CONFIG_AUDIT |
206 | /* These are defined in audit.c */ | 206 | /* These are defined in audit.c */ |
207 | /* Public API */ | 207 | /* Public API */ |
208 | extern void audit_log(struct audit_context *ctx, | 208 | extern void audit_log(struct audit_context *ctx, |
209 | const char *fmt, ...) | 209 | const char *fmt, ...) |
210 | __attribute__((format(printf,2,3))); | 210 | __attribute__((format(printf,2,3))); |
211 | 211 | ||
212 | extern struct audit_buffer *audit_log_start(struct audit_context *ctx); | 212 | extern struct audit_buffer *audit_log_start(struct audit_context *ctx); |
213 | extern void audit_log_format(struct audit_buffer *ab, | 213 | extern void audit_log_format(struct audit_buffer *ab, |
214 | const char *fmt, ...) | 214 | const char *fmt, ...) |
215 | __attribute__((format(printf,2,3))); | 215 | __attribute__((format(printf,2,3))); |
216 | extern void audit_log_end(struct audit_buffer *ab); | 216 | extern void audit_log_end(struct audit_buffer *ab); |
217 | extern void audit_log_hex(struct audit_buffer *ab, | 217 | extern void audit_log_hex(struct audit_buffer *ab, |
218 | const unsigned char *buf, | 218 | const unsigned char *buf, |
219 | size_t len); | 219 | size_t len); |
220 | extern void audit_log_untrustedstring(struct audit_buffer *ab, | 220 | extern void audit_log_untrustedstring(struct audit_buffer *ab, |
221 | const char *string); | 221 | const char *string); |
222 | extern void audit_log_d_path(struct audit_buffer *ab, | 222 | extern void audit_log_d_path(struct audit_buffer *ab, |
223 | const char *prefix, | 223 | const char *prefix, |
224 | struct dentry *dentry, | 224 | struct dentry *dentry, |
225 | struct vfsmount *vfsmnt); | 225 | struct vfsmount *vfsmnt); |
226 | /* Private API (for auditsc.c only) */ | 226 | /* Private API (for auditsc.c only) */ |
227 | extern void audit_send_reply(int pid, int seq, int type, | 227 | extern void audit_send_reply(int pid, int seq, int type, |
228 | int done, int multi, | 228 | int done, int multi, |
229 | void *payload, int size); | 229 | void *payload, int size); |
230 | extern void audit_log_lost(const char *message); | 230 | extern void audit_log_lost(const char *message); |
231 | #else | 231 | #else |
232 | #define audit_log(t,f,...) do { ; } while (0) | 232 | #define audit_log(t,f,...) do { ; } while (0) |
233 | #define audit_log_start(t) ({ NULL; }) | 233 | #define audit_log_start(t) ({ NULL; }) |
234 | #define audit_log_vformat(b,f,a) do { ; } while (0) | 234 | #define audit_log_vformat(b,f,a) do { ; } while (0) |
235 | #define audit_log_format(b,f,...) do { ; } while (0) | 235 | #define audit_log_format(b,f,...) do { ; } while (0) |
236 | #define audit_log_end(b) do { ; } while (0) | 236 | #define audit_log_end(b) do { ; } while (0) |
237 | #define audit_log_hex(a,b,l) do { ; } while (0) | 237 | #define audit_log_hex(a,b,l) do { ; } while (0) |
238 | #define audit_log_untrustedstring(a,s) do { ; } while (0) | 238 | #define audit_log_untrustedstring(a,s) do { ; } while (0) |
239 | #define audit_log_d_path(b,p,d,v) do { ; } while (0) | 239 | #define audit_log_d_path(b,p,d,v) do { ; } while (0) |
240 | #endif | 240 | #endif |
241 | #endif | 241 | #endif |
242 | #endif | 242 | #endif |
243 | 243 |
kernel/auditsc.c
1 | /* auditsc.c -- System-call auditing support | 1 | /* auditsc.c -- System-call auditing support |
2 | * Handles all system-call specific auditing features. | 2 | * Handles all system-call specific auditing features. |
3 | * | 3 | * |
4 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. | 4 | * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. |
5 | * All Rights Reserved. | 5 | * All Rights Reserved. |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. | 10 | * (at your option) any later version. |
11 | * | 11 | * |
12 | * This program is distributed in the hope that it will be useful, | 12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 | * | 20 | * |
21 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> | 21 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> |
22 | * | 22 | * |
23 | * Many of the ideas implemented here are from Stephen C. Tweedie, | 23 | * Many of the ideas implemented here are from Stephen C. Tweedie, |
24 | * especially the idea of avoiding a copy by using getname. | 24 | * especially the idea of avoiding a copy by using getname. |
25 | * | 25 | * |
26 | * The method for actual interception of syscall entry and exit (not in | 26 | * The method for actual interception of syscall entry and exit (not in |
27 | * this file -- see entry.S) is based on a GPL'd patch written by | 27 | * this file -- see entry.S) is based on a GPL'd patch written by |
28 | * okir@suse.de and Copyright 2003 SuSE Linux AG. | 28 | * okir@suse.de and Copyright 2003 SuSE Linux AG. |
29 | * | 29 | * |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/init.h> | 32 | #include <linux/init.h> |
33 | #include <asm/atomic.h> | 33 | #include <asm/atomic.h> |
34 | #include <asm/types.h> | 34 | #include <asm/types.h> |
35 | #include <linux/mm.h> | 35 | #include <linux/mm.h> |
36 | #include <linux/module.h> | 36 | #include <linux/module.h> |
37 | 37 | ||
38 | #include <linux/audit.h> | 38 | #include <linux/audit.h> |
39 | #include <linux/personality.h> | 39 | #include <linux/personality.h> |
40 | #include <linux/time.h> | 40 | #include <linux/time.h> |
41 | #include <asm/unistd.h> | 41 | #include <asm/unistd.h> |
42 | 42 | ||
43 | /* 0 = no checking | 43 | /* 0 = no checking |
44 | 1 = put_count checking | 44 | 1 = put_count checking |
45 | 2 = verbose put_count checking | 45 | 2 = verbose put_count checking |
46 | */ | 46 | */ |
47 | #define AUDIT_DEBUG 0 | 47 | #define AUDIT_DEBUG 0 |
48 | 48 | ||
49 | /* No syscall auditing will take place unless audit_enabled != 0. */ | 49 | /* No syscall auditing will take place unless audit_enabled != 0. */ |
50 | extern int audit_enabled; | 50 | extern int audit_enabled; |
51 | 51 | ||
52 | /* AUDIT_NAMES is the number of slots we reserve in the audit_context | 52 | /* AUDIT_NAMES is the number of slots we reserve in the audit_context |
53 | * for saving names from getname(). */ | 53 | * for saving names from getname(). */ |
54 | #define AUDIT_NAMES 20 | 54 | #define AUDIT_NAMES 20 |
55 | 55 | ||
56 | /* AUDIT_NAMES_RESERVED is the number of slots we reserve in the | 56 | /* AUDIT_NAMES_RESERVED is the number of slots we reserve in the |
57 | * audit_context from being used for nameless inodes from | 57 | * audit_context from being used for nameless inodes from |
58 | * path_lookup. */ | 58 | * path_lookup. */ |
59 | #define AUDIT_NAMES_RESERVED 7 | 59 | #define AUDIT_NAMES_RESERVED 7 |
60 | 60 | ||
61 | /* At task start time, the audit_state is set in the audit_context using | 61 | /* At task start time, the audit_state is set in the audit_context using |
62 | a per-task filter. At syscall entry, the audit_state is augmented by | 62 | a per-task filter. At syscall entry, the audit_state is augmented by |
63 | the syscall filter. */ | 63 | the syscall filter. */ |
64 | enum audit_state { | 64 | enum audit_state { |
65 | AUDIT_DISABLED, /* Do not create per-task audit_context. | 65 | AUDIT_DISABLED, /* Do not create per-task audit_context. |
66 | * No syscall-specific audit records can | 66 | * No syscall-specific audit records can |
67 | * be generated. */ | 67 | * be generated. */ |
68 | AUDIT_SETUP_CONTEXT, /* Create the per-task audit_context, | 68 | AUDIT_SETUP_CONTEXT, /* Create the per-task audit_context, |
69 | * but don't necessarily fill it in at | 69 | * but don't necessarily fill it in at |
70 | * syscall entry time (i.e., filter | 70 | * syscall entry time (i.e., filter |
71 | * instead). */ | 71 | * instead). */ |
72 | AUDIT_BUILD_CONTEXT, /* Create the per-task audit_context, | 72 | AUDIT_BUILD_CONTEXT, /* Create the per-task audit_context, |
73 | * and always fill it in at syscall | 73 | * and always fill it in at syscall |
74 | * entry time. This makes a full | 74 | * entry time. This makes a full |
75 | * syscall record available if some | 75 | * syscall record available if some |
76 | * other part of the kernel decides it | 76 | * other part of the kernel decides it |
77 | * should be recorded. */ | 77 | * should be recorded. */ |
78 | AUDIT_RECORD_CONTEXT /* Create the per-task audit_context, | 78 | AUDIT_RECORD_CONTEXT /* Create the per-task audit_context, |
79 | * always fill it in at syscall entry | 79 | * always fill it in at syscall entry |
80 | * time, and always write out the audit | 80 | * time, and always write out the audit |
81 | * record at syscall exit time. */ | 81 | * record at syscall exit time. */ |
82 | }; | 82 | }; |
83 | 83 | ||
84 | /* When fs/namei.c:getname() is called, we store the pointer in name and | 84 | /* When fs/namei.c:getname() is called, we store the pointer in name and |
85 | * we don't let putname() free it (instead we free all of the saved | 85 | * we don't let putname() free it (instead we free all of the saved |
86 | * pointers at syscall exit time). | 86 | * pointers at syscall exit time). |
87 | * | 87 | * |
88 | * Further, in fs/namei.c:path_lookup() we store the inode and device. */ | 88 | * Further, in fs/namei.c:path_lookup() we store the inode and device. */ |
89 | struct audit_names { | 89 | struct audit_names { |
90 | const char *name; | 90 | const char *name; |
91 | unsigned long ino; | 91 | unsigned long ino; |
92 | dev_t dev; | 92 | dev_t dev; |
93 | umode_t mode; | 93 | umode_t mode; |
94 | uid_t uid; | 94 | uid_t uid; |
95 | gid_t gid; | 95 | gid_t gid; |
96 | dev_t rdev; | 96 | dev_t rdev; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | struct audit_aux_data { | 99 | struct audit_aux_data { |
100 | struct audit_aux_data *next; | 100 | struct audit_aux_data *next; |
101 | int type; | 101 | int type; |
102 | }; | 102 | }; |
103 | 103 | ||
104 | #define AUDIT_AUX_IPCPERM 0 | 104 | #define AUDIT_AUX_IPCPERM 0 |
105 | 105 | ||
106 | struct audit_aux_data_ipcctl { | 106 | struct audit_aux_data_ipcctl { |
107 | struct audit_aux_data d; | 107 | struct audit_aux_data d; |
108 | struct ipc_perm p; | 108 | struct ipc_perm p; |
109 | unsigned long qbytes; | 109 | unsigned long qbytes; |
110 | uid_t uid; | 110 | uid_t uid; |
111 | gid_t gid; | 111 | gid_t gid; |
112 | mode_t mode; | 112 | mode_t mode; |
113 | }; | 113 | }; |
114 | 114 | ||
115 | 115 | ||
116 | /* The per-task audit context. */ | 116 | /* The per-task audit context. */ |
117 | struct audit_context { | 117 | struct audit_context { |
118 | int in_syscall; /* 1 if task is in a syscall */ | 118 | int in_syscall; /* 1 if task is in a syscall */ |
119 | enum audit_state state; | 119 | enum audit_state state; |
120 | unsigned int serial; /* serial number for record */ | 120 | unsigned int serial; /* serial number for record */ |
121 | struct timespec ctime; /* time of syscall entry */ | 121 | struct timespec ctime; /* time of syscall entry */ |
122 | uid_t loginuid; /* login uid (identity) */ | 122 | uid_t loginuid; /* login uid (identity) */ |
123 | int major; /* syscall number */ | 123 | int major; /* syscall number */ |
124 | unsigned long argv[4]; /* syscall arguments */ | 124 | unsigned long argv[4]; /* syscall arguments */ |
125 | int return_valid; /* return code is valid */ | 125 | int return_valid; /* return code is valid */ |
126 | long return_code;/* syscall return code */ | 126 | long return_code;/* syscall return code */ |
127 | int auditable; /* 1 if record should be written */ | 127 | int auditable; /* 1 if record should be written */ |
128 | int name_count; | 128 | int name_count; |
129 | struct audit_names names[AUDIT_NAMES]; | 129 | struct audit_names names[AUDIT_NAMES]; |
130 | struct audit_context *previous; /* For nested syscalls */ | 130 | struct audit_context *previous; /* For nested syscalls */ |
131 | struct audit_aux_data *aux; | 131 | struct audit_aux_data *aux; |
132 | 132 | ||
133 | /* Save things to print about task_struct */ | 133 | /* Save things to print about task_struct */ |
134 | pid_t pid; | 134 | pid_t pid; |
135 | uid_t uid, euid, suid, fsuid; | 135 | uid_t uid, euid, suid, fsuid; |
136 | gid_t gid, egid, sgid, fsgid; | 136 | gid_t gid, egid, sgid, fsgid; |
137 | unsigned long personality; | 137 | unsigned long personality; |
138 | int arch; | 138 | int arch; |
139 | 139 | ||
140 | #if AUDIT_DEBUG | 140 | #if AUDIT_DEBUG |
141 | int put_count; | 141 | int put_count; |
142 | int ino_count; | 142 | int ino_count; |
143 | #endif | 143 | #endif |
144 | }; | 144 | }; |
145 | 145 | ||
146 | /* Public API */ | 146 | /* Public API */ |
147 | /* There are three lists of rules -- one to search at task creation | 147 | /* There are three lists of rules -- one to search at task creation |
148 | * time, one to search at syscall entry time, and another to search at | 148 | * time, one to search at syscall entry time, and another to search at |
149 | * syscall exit time. */ | 149 | * syscall exit time. */ |
150 | static LIST_HEAD(audit_tsklist); | 150 | static LIST_HEAD(audit_tsklist); |
151 | static LIST_HEAD(audit_entlist); | 151 | static LIST_HEAD(audit_entlist); |
152 | static LIST_HEAD(audit_extlist); | 152 | static LIST_HEAD(audit_extlist); |
153 | 153 | ||
154 | struct audit_entry { | 154 | struct audit_entry { |
155 | struct list_head list; | 155 | struct list_head list; |
156 | struct rcu_head rcu; | 156 | struct rcu_head rcu; |
157 | struct audit_rule rule; | 157 | struct audit_rule rule; |
158 | }; | 158 | }; |
159 | 159 | ||
160 | /* Check to see if two rules are identical. It is called from | 160 | /* Check to see if two rules are identical. It is called from |
161 | * audit_del_rule during AUDIT_DEL. */ | 161 | * audit_del_rule during AUDIT_DEL. */ |
162 | static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b) | 162 | static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b) |
163 | { | 163 | { |
164 | int i; | 164 | int i; |
165 | 165 | ||
166 | if (a->flags != b->flags) | 166 | if (a->flags != b->flags) |
167 | return 1; | 167 | return 1; |
168 | 168 | ||
169 | if (a->action != b->action) | 169 | if (a->action != b->action) |
170 | return 1; | 170 | return 1; |
171 | 171 | ||
172 | if (a->field_count != b->field_count) | 172 | if (a->field_count != b->field_count) |
173 | return 1; | 173 | return 1; |
174 | 174 | ||
175 | for (i = 0; i < a->field_count; i++) { | 175 | for (i = 0; i < a->field_count; i++) { |
176 | if (a->fields[i] != b->fields[i] | 176 | if (a->fields[i] != b->fields[i] |
177 | || a->values[i] != b->values[i]) | 177 | || a->values[i] != b->values[i]) |
178 | return 1; | 178 | return 1; |
179 | } | 179 | } |
180 | 180 | ||
181 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) | 181 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) |
182 | if (a->mask[i] != b->mask[i]) | 182 | if (a->mask[i] != b->mask[i]) |
183 | return 1; | 183 | return 1; |
184 | 184 | ||
185 | return 0; | 185 | return 0; |
186 | } | 186 | } |
187 | 187 | ||
188 | /* Note that audit_add_rule and audit_del_rule are called via | 188 | /* Note that audit_add_rule and audit_del_rule are called via |
189 | * audit_receive() in audit.c, and are protected by | 189 | * audit_receive() in audit.c, and are protected by |
190 | * audit_netlink_sem. */ | 190 | * audit_netlink_sem. */ |
191 | static inline int audit_add_rule(struct audit_entry *entry, | 191 | static inline int audit_add_rule(struct audit_entry *entry, |
192 | struct list_head *list) | 192 | struct list_head *list) |
193 | { | 193 | { |
194 | if (entry->rule.flags & AUDIT_PREPEND) { | 194 | if (entry->rule.flags & AUDIT_PREPEND) { |
195 | entry->rule.flags &= ~AUDIT_PREPEND; | 195 | entry->rule.flags &= ~AUDIT_PREPEND; |
196 | list_add_rcu(&entry->list, list); | 196 | list_add_rcu(&entry->list, list); |
197 | } else { | 197 | } else { |
198 | list_add_tail_rcu(&entry->list, list); | 198 | list_add_tail_rcu(&entry->list, list); |
199 | } | 199 | } |
200 | return 0; | 200 | return 0; |
201 | } | 201 | } |
202 | 202 | ||
203 | static void audit_free_rule(struct rcu_head *head) | 203 | static void audit_free_rule(struct rcu_head *head) |
204 | { | 204 | { |
205 | struct audit_entry *e = container_of(head, struct audit_entry, rcu); | 205 | struct audit_entry *e = container_of(head, struct audit_entry, rcu); |
206 | kfree(e); | 206 | kfree(e); |
207 | } | 207 | } |
208 | 208 | ||
209 | /* Note that audit_add_rule and audit_del_rule are called via | 209 | /* Note that audit_add_rule and audit_del_rule are called via |
210 | * audit_receive() in audit.c, and are protected by | 210 | * audit_receive() in audit.c, and are protected by |
211 | * audit_netlink_sem. */ | 211 | * audit_netlink_sem. */ |
212 | static inline int audit_del_rule(struct audit_rule *rule, | 212 | static inline int audit_del_rule(struct audit_rule *rule, |
213 | struct list_head *list) | 213 | struct list_head *list) |
214 | { | 214 | { |
215 | struct audit_entry *e; | 215 | struct audit_entry *e; |
216 | 216 | ||
217 | /* Do not use the _rcu iterator here, since this is the only | 217 | /* Do not use the _rcu iterator here, since this is the only |
218 | * deletion routine. */ | 218 | * deletion routine. */ |
219 | list_for_each_entry(e, list, list) { | 219 | list_for_each_entry(e, list, list) { |
220 | if (!audit_compare_rule(rule, &e->rule)) { | 220 | if (!audit_compare_rule(rule, &e->rule)) { |
221 | list_del_rcu(&e->list); | 221 | list_del_rcu(&e->list); |
222 | call_rcu(&e->rcu, audit_free_rule); | 222 | call_rcu(&e->rcu, audit_free_rule); |
223 | return 0; | 223 | return 0; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | return -EFAULT; /* No matching rule */ | 226 | return -EFAULT; /* No matching rule */ |
227 | } | 227 | } |
228 | 228 | ||
229 | #ifdef CONFIG_NET | 229 | #ifdef CONFIG_NET |
230 | /* Copy rule from user-space to kernel-space. Called during | 230 | /* Copy rule from user-space to kernel-space. Called during |
231 | * AUDIT_ADD. */ | 231 | * AUDIT_ADD. */ |
232 | static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s) | 232 | static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s) |
233 | { | 233 | { |
234 | int i; | 234 | int i; |
235 | 235 | ||
236 | if (s->action != AUDIT_NEVER | 236 | if (s->action != AUDIT_NEVER |
237 | && s->action != AUDIT_POSSIBLE | 237 | && s->action != AUDIT_POSSIBLE |
238 | && s->action != AUDIT_ALWAYS) | 238 | && s->action != AUDIT_ALWAYS) |
239 | return -1; | 239 | return -1; |
240 | if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS) | 240 | if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS) |
241 | return -1; | 241 | return -1; |
242 | 242 | ||
243 | d->flags = s->flags; | 243 | d->flags = s->flags; |
244 | d->action = s->action; | 244 | d->action = s->action; |
245 | d->field_count = s->field_count; | 245 | d->field_count = s->field_count; |
246 | for (i = 0; i < d->field_count; i++) { | 246 | for (i = 0; i < d->field_count; i++) { |
247 | d->fields[i] = s->fields[i]; | 247 | d->fields[i] = s->fields[i]; |
248 | d->values[i] = s->values[i]; | 248 | d->values[i] = s->values[i]; |
249 | } | 249 | } |
250 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i]; | 250 | for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i]; |
251 | return 0; | 251 | return 0; |
252 | } | 252 | } |
253 | 253 | ||
254 | int audit_receive_filter(int type, int pid, int uid, int seq, void *data, | 254 | int audit_receive_filter(int type, int pid, int uid, int seq, void *data, |
255 | uid_t loginuid) | 255 | uid_t loginuid) |
256 | { | 256 | { |
257 | u32 flags; | 257 | u32 flags; |
258 | struct audit_entry *entry; | 258 | struct audit_entry *entry; |
259 | int err = 0; | 259 | int err = 0; |
260 | 260 | ||
261 | switch (type) { | 261 | switch (type) { |
262 | case AUDIT_LIST: | 262 | case AUDIT_LIST: |
263 | /* The *_rcu iterators not needed here because we are | 263 | /* The *_rcu iterators not needed here because we are |
264 | always called with audit_netlink_sem held. */ | 264 | always called with audit_netlink_sem held. */ |
265 | list_for_each_entry(entry, &audit_tsklist, list) | 265 | list_for_each_entry(entry, &audit_tsklist, list) |
266 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 266 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, |
267 | &entry->rule, sizeof(entry->rule)); | 267 | &entry->rule, sizeof(entry->rule)); |
268 | list_for_each_entry(entry, &audit_entlist, list) | 268 | list_for_each_entry(entry, &audit_entlist, list) |
269 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 269 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, |
270 | &entry->rule, sizeof(entry->rule)); | 270 | &entry->rule, sizeof(entry->rule)); |
271 | list_for_each_entry(entry, &audit_extlist, list) | 271 | list_for_each_entry(entry, &audit_extlist, list) |
272 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, | 272 | audit_send_reply(pid, seq, AUDIT_LIST, 0, 1, |
273 | &entry->rule, sizeof(entry->rule)); | 273 | &entry->rule, sizeof(entry->rule)); |
274 | audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0); | 274 | audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0); |
275 | break; | 275 | break; |
276 | case AUDIT_ADD: | 276 | case AUDIT_ADD: |
277 | if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL))) | 277 | if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL))) |
278 | return -ENOMEM; | 278 | return -ENOMEM; |
279 | if (audit_copy_rule(&entry->rule, data)) { | 279 | if (audit_copy_rule(&entry->rule, data)) { |
280 | kfree(entry); | 280 | kfree(entry); |
281 | return -EINVAL; | 281 | return -EINVAL; |
282 | } | 282 | } |
283 | flags = entry->rule.flags; | 283 | flags = entry->rule.flags; |
284 | if (!err && (flags & AUDIT_PER_TASK)) | 284 | if (!err && (flags & AUDIT_PER_TASK)) |
285 | err = audit_add_rule(entry, &audit_tsklist); | 285 | err = audit_add_rule(entry, &audit_tsklist); |
286 | if (!err && (flags & AUDIT_AT_ENTRY)) | 286 | if (!err && (flags & AUDIT_AT_ENTRY)) |
287 | err = audit_add_rule(entry, &audit_entlist); | 287 | err = audit_add_rule(entry, &audit_entlist); |
288 | if (!err && (flags & AUDIT_AT_EXIT)) | 288 | if (!err && (flags & AUDIT_AT_EXIT)) |
289 | err = audit_add_rule(entry, &audit_extlist); | 289 | err = audit_add_rule(entry, &audit_extlist); |
290 | audit_log(NULL, "auid %u added an audit rule\n", loginuid); | 290 | audit_log(NULL, "auid %u added an audit rule\n", loginuid); |
291 | break; | 291 | break; |
292 | case AUDIT_DEL: | 292 | case AUDIT_DEL: |
293 | flags =((struct audit_rule *)data)->flags; | 293 | flags =((struct audit_rule *)data)->flags; |
294 | if (!err && (flags & AUDIT_PER_TASK)) | 294 | if (!err && (flags & AUDIT_PER_TASK)) |
295 | err = audit_del_rule(data, &audit_tsklist); | 295 | err = audit_del_rule(data, &audit_tsklist); |
296 | if (!err && (flags & AUDIT_AT_ENTRY)) | 296 | if (!err && (flags & AUDIT_AT_ENTRY)) |
297 | err = audit_del_rule(data, &audit_entlist); | 297 | err = audit_del_rule(data, &audit_entlist); |
298 | if (!err && (flags & AUDIT_AT_EXIT)) | 298 | if (!err && (flags & AUDIT_AT_EXIT)) |
299 | err = audit_del_rule(data, &audit_extlist); | 299 | err = audit_del_rule(data, &audit_extlist); |
300 | audit_log(NULL, "auid %u removed an audit rule\n", loginuid); | 300 | audit_log(NULL, "auid %u removed an audit rule\n", loginuid); |
301 | break; | 301 | break; |
302 | default: | 302 | default: |
303 | return -EINVAL; | 303 | return -EINVAL; |
304 | } | 304 | } |
305 | 305 | ||
306 | return err; | 306 | return err; |
307 | } | 307 | } |
308 | #endif | 308 | #endif |
309 | 309 | ||
310 | /* Compare a task_struct with an audit_rule. Return 1 on match, 0 | 310 | /* Compare a task_struct with an audit_rule. Return 1 on match, 0 |
311 | * otherwise. */ | 311 | * otherwise. */ |
312 | static int audit_filter_rules(struct task_struct *tsk, | 312 | static int audit_filter_rules(struct task_struct *tsk, |
313 | struct audit_rule *rule, | 313 | struct audit_rule *rule, |
314 | struct audit_context *ctx, | 314 | struct audit_context *ctx, |
315 | enum audit_state *state) | 315 | enum audit_state *state) |
316 | { | 316 | { |
317 | int i, j; | 317 | int i, j; |
318 | 318 | ||
319 | for (i = 0; i < rule->field_count; i++) { | 319 | for (i = 0; i < rule->field_count; i++) { |
320 | u32 field = rule->fields[i] & ~AUDIT_NEGATE; | 320 | u32 field = rule->fields[i] & ~AUDIT_NEGATE; |
321 | u32 value = rule->values[i]; | 321 | u32 value = rule->values[i]; |
322 | int result = 0; | 322 | int result = 0; |
323 | 323 | ||
324 | switch (field) { | 324 | switch (field) { |
325 | case AUDIT_PID: | 325 | case AUDIT_PID: |
326 | result = (tsk->pid == value); | 326 | result = (tsk->pid == value); |
327 | break; | 327 | break; |
328 | case AUDIT_UID: | 328 | case AUDIT_UID: |
329 | result = (tsk->uid == value); | 329 | result = (tsk->uid == value); |
330 | break; | 330 | break; |
331 | case AUDIT_EUID: | 331 | case AUDIT_EUID: |
332 | result = (tsk->euid == value); | 332 | result = (tsk->euid == value); |
333 | break; | 333 | break; |
334 | case AUDIT_SUID: | 334 | case AUDIT_SUID: |
335 | result = (tsk->suid == value); | 335 | result = (tsk->suid == value); |
336 | break; | 336 | break; |
337 | case AUDIT_FSUID: | 337 | case AUDIT_FSUID: |
338 | result = (tsk->fsuid == value); | 338 | result = (tsk->fsuid == value); |
339 | break; | 339 | break; |
340 | case AUDIT_GID: | 340 | case AUDIT_GID: |
341 | result = (tsk->gid == value); | 341 | result = (tsk->gid == value); |
342 | break; | 342 | break; |
343 | case AUDIT_EGID: | 343 | case AUDIT_EGID: |
344 | result = (tsk->egid == value); | 344 | result = (tsk->egid == value); |
345 | break; | 345 | break; |
346 | case AUDIT_SGID: | 346 | case AUDIT_SGID: |
347 | result = (tsk->sgid == value); | 347 | result = (tsk->sgid == value); |
348 | break; | 348 | break; |
349 | case AUDIT_FSGID: | 349 | case AUDIT_FSGID: |
350 | result = (tsk->fsgid == value); | 350 | result = (tsk->fsgid == value); |
351 | break; | 351 | break; |
352 | case AUDIT_PERS: | 352 | case AUDIT_PERS: |
353 | result = (tsk->personality == value); | 353 | result = (tsk->personality == value); |
354 | break; | 354 | break; |
355 | case AUDIT_ARCH: | 355 | case AUDIT_ARCH: |
356 | if (ctx) | 356 | if (ctx) |
357 | result = (ctx->arch == value); | 357 | result = (ctx->arch == value); |
358 | break; | 358 | break; |
359 | 359 | ||
360 | case AUDIT_EXIT: | 360 | case AUDIT_EXIT: |
361 | if (ctx && ctx->return_valid) | 361 | if (ctx && ctx->return_valid) |
362 | result = (ctx->return_code == value); | 362 | result = (ctx->return_code == value); |
363 | break; | 363 | break; |
364 | case AUDIT_SUCCESS: | 364 | case AUDIT_SUCCESS: |
365 | if (ctx && ctx->return_valid) | 365 | if (ctx && ctx->return_valid) |
366 | result = (ctx->return_valid == AUDITSC_SUCCESS); | 366 | result = (ctx->return_valid == AUDITSC_SUCCESS); |
367 | break; | 367 | break; |
368 | case AUDIT_DEVMAJOR: | 368 | case AUDIT_DEVMAJOR: |
369 | if (ctx) { | 369 | if (ctx) { |
370 | for (j = 0; j < ctx->name_count; j++) { | 370 | for (j = 0; j < ctx->name_count; j++) { |
371 | if (MAJOR(ctx->names[j].dev)==value) { | 371 | if (MAJOR(ctx->names[j].dev)==value) { |
372 | ++result; | 372 | ++result; |
373 | break; | 373 | break; |
374 | } | 374 | } |
375 | } | 375 | } |
376 | } | 376 | } |
377 | break; | 377 | break; |
378 | case AUDIT_DEVMINOR: | 378 | case AUDIT_DEVMINOR: |
379 | if (ctx) { | 379 | if (ctx) { |
380 | for (j = 0; j < ctx->name_count; j++) { | 380 | for (j = 0; j < ctx->name_count; j++) { |
381 | if (MINOR(ctx->names[j].dev)==value) { | 381 | if (MINOR(ctx->names[j].dev)==value) { |
382 | ++result; | 382 | ++result; |
383 | break; | 383 | break; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | } | 386 | } |
387 | break; | 387 | break; |
388 | case AUDIT_INODE: | 388 | case AUDIT_INODE: |
389 | if (ctx) { | 389 | if (ctx) { |
390 | for (j = 0; j < ctx->name_count; j++) { | 390 | for (j = 0; j < ctx->name_count; j++) { |
391 | if (ctx->names[j].ino == value) { | 391 | if (ctx->names[j].ino == value) { |
392 | ++result; | 392 | ++result; |
393 | break; | 393 | break; |
394 | } | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | break; | 397 | break; |
398 | case AUDIT_LOGINUID: | 398 | case AUDIT_LOGINUID: |
399 | result = 0; | 399 | result = 0; |
400 | if (ctx) | 400 | if (ctx) |
401 | result = (ctx->loginuid == value); | 401 | result = (ctx->loginuid == value); |
402 | break; | 402 | break; |
403 | case AUDIT_ARG0: | 403 | case AUDIT_ARG0: |
404 | case AUDIT_ARG1: | 404 | case AUDIT_ARG1: |
405 | case AUDIT_ARG2: | 405 | case AUDIT_ARG2: |
406 | case AUDIT_ARG3: | 406 | case AUDIT_ARG3: |
407 | if (ctx) | 407 | if (ctx) |
408 | result = (ctx->argv[field-AUDIT_ARG0]==value); | 408 | result = (ctx->argv[field-AUDIT_ARG0]==value); |
409 | break; | 409 | break; |
410 | } | 410 | } |
411 | 411 | ||
412 | if (rule->fields[i] & AUDIT_NEGATE) | 412 | if (rule->fields[i] & AUDIT_NEGATE) |
413 | result = !result; | 413 | result = !result; |
414 | if (!result) | 414 | if (!result) |
415 | return 0; | 415 | return 0; |
416 | } | 416 | } |
417 | switch (rule->action) { | 417 | switch (rule->action) { |
418 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; | 418 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; |
419 | case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break; | 419 | case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break; |
420 | case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break; | 420 | case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break; |
421 | } | 421 | } |
422 | return 1; | 422 | return 1; |
423 | } | 423 | } |
424 | 424 | ||
425 | /* At process creation time, we can determine if system-call auditing is | 425 | /* At process creation time, we can determine if system-call auditing is |
426 | * completely disabled for this task. Since we only have the task | 426 | * completely disabled for this task. Since we only have the task |
427 | * structure at this point, we can only check uid and gid. | 427 | * structure at this point, we can only check uid and gid. |
428 | */ | 428 | */ |
429 | static enum audit_state audit_filter_task(struct task_struct *tsk) | 429 | static enum audit_state audit_filter_task(struct task_struct *tsk) |
430 | { | 430 | { |
431 | struct audit_entry *e; | 431 | struct audit_entry *e; |
432 | enum audit_state state; | 432 | enum audit_state state; |
433 | 433 | ||
434 | rcu_read_lock(); | 434 | rcu_read_lock(); |
435 | list_for_each_entry_rcu(e, &audit_tsklist, list) { | 435 | list_for_each_entry_rcu(e, &audit_tsklist, list) { |
436 | if (audit_filter_rules(tsk, &e->rule, NULL, &state)) { | 436 | if (audit_filter_rules(tsk, &e->rule, NULL, &state)) { |
437 | rcu_read_unlock(); | 437 | rcu_read_unlock(); |
438 | return state; | 438 | return state; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | rcu_read_unlock(); | 441 | rcu_read_unlock(); |
442 | return AUDIT_BUILD_CONTEXT; | 442 | return AUDIT_BUILD_CONTEXT; |
443 | } | 443 | } |
444 | 444 | ||
445 | /* At syscall entry and exit time, this filter is called if the | 445 | /* At syscall entry and exit time, this filter is called if the |
446 | * audit_state is not low enough that auditing cannot take place, but is | 446 | * audit_state is not low enough that auditing cannot take place, but is |
447 | * also not high enough that we already know we have to write and audit | 447 | * also not high enough that we already know we have to write and audit |
448 | * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT). | 448 | * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT). |
449 | */ | 449 | */ |
450 | static enum audit_state audit_filter_syscall(struct task_struct *tsk, | 450 | static enum audit_state audit_filter_syscall(struct task_struct *tsk, |
451 | struct audit_context *ctx, | 451 | struct audit_context *ctx, |
452 | struct list_head *list) | 452 | struct list_head *list) |
453 | { | 453 | { |
454 | struct audit_entry *e; | 454 | struct audit_entry *e; |
455 | enum audit_state state; | 455 | enum audit_state state; |
456 | int word = AUDIT_WORD(ctx->major); | 456 | int word = AUDIT_WORD(ctx->major); |
457 | int bit = AUDIT_BIT(ctx->major); | 457 | int bit = AUDIT_BIT(ctx->major); |
458 | 458 | ||
459 | rcu_read_lock(); | 459 | rcu_read_lock(); |
460 | list_for_each_entry_rcu(e, list, list) { | 460 | list_for_each_entry_rcu(e, list, list) { |
461 | if ((e->rule.mask[word] & bit) == bit | 461 | if ((e->rule.mask[word] & bit) == bit |
462 | && audit_filter_rules(tsk, &e->rule, ctx, &state)) { | 462 | && audit_filter_rules(tsk, &e->rule, ctx, &state)) { |
463 | rcu_read_unlock(); | 463 | rcu_read_unlock(); |
464 | return state; | 464 | return state; |
465 | } | 465 | } |
466 | } | 466 | } |
467 | rcu_read_unlock(); | 467 | rcu_read_unlock(); |
468 | return AUDIT_BUILD_CONTEXT; | 468 | return AUDIT_BUILD_CONTEXT; |
469 | } | 469 | } |
470 | 470 | ||
471 | /* This should be called with task_lock() held. */ | 471 | /* This should be called with task_lock() held. */ |
472 | static inline struct audit_context *audit_get_context(struct task_struct *tsk, | 472 | static inline struct audit_context *audit_get_context(struct task_struct *tsk, |
473 | int return_valid, | 473 | int return_valid, |
474 | int return_code) | 474 | int return_code) |
475 | { | 475 | { |
476 | struct audit_context *context = tsk->audit_context; | 476 | struct audit_context *context = tsk->audit_context; |
477 | 477 | ||
478 | if (likely(!context)) | 478 | if (likely(!context)) |
479 | return NULL; | 479 | return NULL; |
480 | context->return_valid = return_valid; | 480 | context->return_valid = return_valid; |
481 | context->return_code = return_code; | 481 | context->return_code = return_code; |
482 | 482 | ||
483 | if (context->in_syscall && !context->auditable) { | 483 | if (context->in_syscall && !context->auditable) { |
484 | enum audit_state state; | 484 | enum audit_state state; |
485 | state = audit_filter_syscall(tsk, context, &audit_extlist); | 485 | state = audit_filter_syscall(tsk, context, &audit_extlist); |
486 | if (state == AUDIT_RECORD_CONTEXT) | 486 | if (state == AUDIT_RECORD_CONTEXT) |
487 | context->auditable = 1; | 487 | context->auditable = 1; |
488 | } | 488 | } |
489 | 489 | ||
490 | context->pid = tsk->pid; | 490 | context->pid = tsk->pid; |
491 | context->uid = tsk->uid; | 491 | context->uid = tsk->uid; |
492 | context->gid = tsk->gid; | 492 | context->gid = tsk->gid; |
493 | context->euid = tsk->euid; | 493 | context->euid = tsk->euid; |
494 | context->suid = tsk->suid; | 494 | context->suid = tsk->suid; |
495 | context->fsuid = tsk->fsuid; | 495 | context->fsuid = tsk->fsuid; |
496 | context->egid = tsk->egid; | 496 | context->egid = tsk->egid; |
497 | context->sgid = tsk->sgid; | 497 | context->sgid = tsk->sgid; |
498 | context->fsgid = tsk->fsgid; | 498 | context->fsgid = tsk->fsgid; |
499 | context->personality = tsk->personality; | 499 | context->personality = tsk->personality; |
500 | tsk->audit_context = NULL; | 500 | tsk->audit_context = NULL; |
501 | return context; | 501 | return context; |
502 | } | 502 | } |
503 | 503 | ||
504 | static inline void audit_free_names(struct audit_context *context) | 504 | static inline void audit_free_names(struct audit_context *context) |
505 | { | 505 | { |
506 | int i; | 506 | int i; |
507 | 507 | ||
508 | #if AUDIT_DEBUG == 2 | 508 | #if AUDIT_DEBUG == 2 |
509 | if (context->auditable | 509 | if (context->auditable |
510 | ||context->put_count + context->ino_count != context->name_count) { | 510 | ||context->put_count + context->ino_count != context->name_count) { |
511 | printk(KERN_ERR "audit.c:%d(:%d): major=%d in_syscall=%d" | 511 | printk(KERN_ERR "audit.c:%d(:%d): major=%d in_syscall=%d" |
512 | " name_count=%d put_count=%d" | 512 | " name_count=%d put_count=%d" |
513 | " ino_count=%d [NOT freeing]\n", | 513 | " ino_count=%d [NOT freeing]\n", |
514 | __LINE__, | 514 | __LINE__, |
515 | context->serial, context->major, context->in_syscall, | 515 | context->serial, context->major, context->in_syscall, |
516 | context->name_count, context->put_count, | 516 | context->name_count, context->put_count, |
517 | context->ino_count); | 517 | context->ino_count); |
518 | for (i = 0; i < context->name_count; i++) | 518 | for (i = 0; i < context->name_count; i++) |
519 | printk(KERN_ERR "names[%d] = %p = %s\n", i, | 519 | printk(KERN_ERR "names[%d] = %p = %s\n", i, |
520 | context->names[i].name, | 520 | context->names[i].name, |
521 | context->names[i].name); | 521 | context->names[i].name); |
522 | dump_stack(); | 522 | dump_stack(); |
523 | return; | 523 | return; |
524 | } | 524 | } |
525 | #endif | 525 | #endif |
526 | #if AUDIT_DEBUG | 526 | #if AUDIT_DEBUG |
527 | context->put_count = 0; | 527 | context->put_count = 0; |
528 | context->ino_count = 0; | 528 | context->ino_count = 0; |
529 | #endif | 529 | #endif |
530 | 530 | ||
531 | for (i = 0; i < context->name_count; i++) | 531 | for (i = 0; i < context->name_count; i++) |
532 | if (context->names[i].name) | 532 | if (context->names[i].name) |
533 | __putname(context->names[i].name); | 533 | __putname(context->names[i].name); |
534 | context->name_count = 0; | 534 | context->name_count = 0; |
535 | } | 535 | } |
536 | 536 | ||
537 | static inline void audit_free_aux(struct audit_context *context) | 537 | static inline void audit_free_aux(struct audit_context *context) |
538 | { | 538 | { |
539 | struct audit_aux_data *aux; | 539 | struct audit_aux_data *aux; |
540 | 540 | ||
541 | while ((aux = context->aux)) { | 541 | while ((aux = context->aux)) { |
542 | context->aux = aux->next; | 542 | context->aux = aux->next; |
543 | kfree(aux); | 543 | kfree(aux); |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | static inline void audit_zero_context(struct audit_context *context, | 547 | static inline void audit_zero_context(struct audit_context *context, |
548 | enum audit_state state) | 548 | enum audit_state state) |
549 | { | 549 | { |
550 | uid_t loginuid = context->loginuid; | 550 | uid_t loginuid = context->loginuid; |
551 | 551 | ||
552 | memset(context, 0, sizeof(*context)); | 552 | memset(context, 0, sizeof(*context)); |
553 | context->state = state; | 553 | context->state = state; |
554 | context->loginuid = loginuid; | 554 | context->loginuid = loginuid; |
555 | } | 555 | } |
556 | 556 | ||
557 | static inline struct audit_context *audit_alloc_context(enum audit_state state) | 557 | static inline struct audit_context *audit_alloc_context(enum audit_state state) |
558 | { | 558 | { |
559 | struct audit_context *context; | 559 | struct audit_context *context; |
560 | 560 | ||
561 | if (!(context = kmalloc(sizeof(*context), GFP_KERNEL))) | 561 | if (!(context = kmalloc(sizeof(*context), GFP_KERNEL))) |
562 | return NULL; | 562 | return NULL; |
563 | audit_zero_context(context, state); | 563 | audit_zero_context(context, state); |
564 | return context; | 564 | return context; |
565 | } | 565 | } |
566 | 566 | ||
567 | /* Filter on the task information and allocate a per-task audit context | 567 | /* Filter on the task information and allocate a per-task audit context |
568 | * if necessary. Doing so turns on system call auditing for the | 568 | * if necessary. Doing so turns on system call auditing for the |
569 | * specified task. This is called from copy_process, so no lock is | 569 | * specified task. This is called from copy_process, so no lock is |
570 | * needed. */ | 570 | * needed. */ |
571 | int audit_alloc(struct task_struct *tsk) | 571 | int audit_alloc(struct task_struct *tsk) |
572 | { | 572 | { |
573 | struct audit_context *context; | 573 | struct audit_context *context; |
574 | enum audit_state state; | 574 | enum audit_state state; |
575 | 575 | ||
576 | if (likely(!audit_enabled)) | 576 | if (likely(!audit_enabled)) |
577 | return 0; /* Return if not auditing. */ | 577 | return 0; /* Return if not auditing. */ |
578 | 578 | ||
579 | state = audit_filter_task(tsk); | 579 | state = audit_filter_task(tsk); |
580 | if (likely(state == AUDIT_DISABLED)) | 580 | if (likely(state == AUDIT_DISABLED)) |
581 | return 0; | 581 | return 0; |
582 | 582 | ||
583 | if (!(context = audit_alloc_context(state))) { | 583 | if (!(context = audit_alloc_context(state))) { |
584 | audit_log_lost("out of memory in audit_alloc"); | 584 | audit_log_lost("out of memory in audit_alloc"); |
585 | return -ENOMEM; | 585 | return -ENOMEM; |
586 | } | 586 | } |
587 | 587 | ||
588 | /* Preserve login uid */ | 588 | /* Preserve login uid */ |
589 | context->loginuid = -1; | 589 | context->loginuid = -1; |
590 | if (current->audit_context) | 590 | if (current->audit_context) |
591 | context->loginuid = current->audit_context->loginuid; | 591 | context->loginuid = current->audit_context->loginuid; |
592 | 592 | ||
593 | tsk->audit_context = context; | 593 | tsk->audit_context = context; |
594 | set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT); | 594 | set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT); |
595 | return 0; | 595 | return 0; |
596 | } | 596 | } |
597 | 597 | ||
598 | static inline void audit_free_context(struct audit_context *context) | 598 | static inline void audit_free_context(struct audit_context *context) |
599 | { | 599 | { |
600 | struct audit_context *previous; | 600 | struct audit_context *previous; |
601 | int count = 0; | 601 | int count = 0; |
602 | 602 | ||
603 | do { | 603 | do { |
604 | previous = context->previous; | 604 | previous = context->previous; |
605 | if (previous || (count && count < 10)) { | 605 | if (previous || (count && count < 10)) { |
606 | ++count; | 606 | ++count; |
607 | printk(KERN_ERR "audit(:%d): major=%d name_count=%d:" | 607 | printk(KERN_ERR "audit(:%d): major=%d name_count=%d:" |
608 | " freeing multiple contexts (%d)\n", | 608 | " freeing multiple contexts (%d)\n", |
609 | context->serial, context->major, | 609 | context->serial, context->major, |
610 | context->name_count, count); | 610 | context->name_count, count); |
611 | } | 611 | } |
612 | audit_free_names(context); | 612 | audit_free_names(context); |
613 | audit_free_aux(context); | 613 | audit_free_aux(context); |
614 | kfree(context); | 614 | kfree(context); |
615 | context = previous; | 615 | context = previous; |
616 | } while (context); | 616 | } while (context); |
617 | if (count >= 10) | 617 | if (count >= 10) |
618 | printk(KERN_ERR "audit: freed %d contexts\n", count); | 618 | printk(KERN_ERR "audit: freed %d contexts\n", count); |
619 | } | 619 | } |
620 | 620 | ||
621 | static void audit_log_task_info(struct audit_buffer *ab) | 621 | static void audit_log_task_info(struct audit_buffer *ab) |
622 | { | 622 | { |
623 | char name[sizeof(current->comm)]; | 623 | char name[sizeof(current->comm)]; |
624 | struct mm_struct *mm = current->mm; | 624 | struct mm_struct *mm = current->mm; |
625 | struct vm_area_struct *vma; | 625 | struct vm_area_struct *vma; |
626 | 626 | ||
627 | get_task_comm(name, current); | 627 | get_task_comm(name, current); |
628 | audit_log_format(ab, " comm=%s", name); | 628 | audit_log_format(ab, " comm=%s", name); |
629 | 629 | ||
630 | if (!mm) | 630 | if (!mm) |
631 | return; | 631 | return; |
632 | 632 | ||
633 | down_read(&mm->mmap_sem); | 633 | down_read(&mm->mmap_sem); |
634 | vma = mm->mmap; | 634 | vma = mm->mmap; |
635 | while (vma) { | 635 | while (vma) { |
636 | if ((vma->vm_flags & VM_EXECUTABLE) && | 636 | if ((vma->vm_flags & VM_EXECUTABLE) && |
637 | vma->vm_file) { | 637 | vma->vm_file) { |
638 | audit_log_d_path(ab, "exe=", | 638 | audit_log_d_path(ab, "exe=", |
639 | vma->vm_file->f_dentry, | 639 | vma->vm_file->f_dentry, |
640 | vma->vm_file->f_vfsmnt); | 640 | vma->vm_file->f_vfsmnt); |
641 | break; | 641 | break; |
642 | } | 642 | } |
643 | vma = vma->vm_next; | 643 | vma = vma->vm_next; |
644 | } | 644 | } |
645 | up_read(&mm->mmap_sem); | 645 | up_read(&mm->mmap_sem); |
646 | } | 646 | } |
647 | 647 | ||
648 | static void audit_log_exit(struct audit_context *context) | 648 | static void audit_log_exit(struct audit_context *context) |
649 | { | 649 | { |
650 | int i; | 650 | int i; |
651 | struct audit_buffer *ab; | 651 | struct audit_buffer *ab; |
652 | 652 | ||
653 | ab = audit_log_start(context); | 653 | ab = audit_log_start(context); |
654 | if (!ab) | 654 | if (!ab) |
655 | return; /* audit_panic has been called */ | 655 | return; /* audit_panic has been called */ |
656 | audit_log_format(ab, "syscall=%d", context->major); | 656 | audit_log_format(ab, "syscall=%d", context->major); |
657 | if (context->personality != PER_LINUX) | 657 | if (context->personality != PER_LINUX) |
658 | audit_log_format(ab, " per=%lx", context->personality); | 658 | audit_log_format(ab, " per=%lx", context->personality); |
659 | audit_log_format(ab, " arch=%x", context->arch); | 659 | audit_log_format(ab, " arch=%x", context->arch); |
660 | if (context->return_valid) | 660 | if (context->return_valid) |
661 | audit_log_format(ab, " success=%s exit=%ld", | 661 | audit_log_format(ab, " success=%s exit=%ld", |
662 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", | 662 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", |
663 | context->return_code); | 663 | context->return_code); |
664 | audit_log_format(ab, | 664 | audit_log_format(ab, |
665 | " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" | 665 | " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" |
666 | " pid=%d loginuid=%d uid=%d gid=%d" | 666 | " pid=%d loginuid=%d uid=%d gid=%d" |
667 | " euid=%d suid=%d fsuid=%d" | 667 | " euid=%d suid=%d fsuid=%d" |
668 | " egid=%d sgid=%d fsgid=%d", | 668 | " egid=%d sgid=%d fsgid=%d", |
669 | context->argv[0], | 669 | context->argv[0], |
670 | context->argv[1], | 670 | context->argv[1], |
671 | context->argv[2], | 671 | context->argv[2], |
672 | context->argv[3], | 672 | context->argv[3], |
673 | context->name_count, | 673 | context->name_count, |
674 | context->pid, | 674 | context->pid, |
675 | context->loginuid, | 675 | context->loginuid, |
676 | context->uid, | 676 | context->uid, |
677 | context->gid, | 677 | context->gid, |
678 | context->euid, context->suid, context->fsuid, | 678 | context->euid, context->suid, context->fsuid, |
679 | context->egid, context->sgid, context->fsgid); | 679 | context->egid, context->sgid, context->fsgid); |
680 | audit_log_task_info(ab); | 680 | audit_log_task_info(ab); |
681 | audit_log_end(ab); | 681 | audit_log_end(ab); |
682 | while (context->aux) { | 682 | while (context->aux) { |
683 | struct audit_aux_data *aux; | 683 | struct audit_aux_data *aux; |
684 | 684 | ||
685 | ab = audit_log_start(context); | 685 | ab = audit_log_start(context); |
686 | if (!ab) | 686 | if (!ab) |
687 | continue; /* audit_panic has been called */ | 687 | continue; /* audit_panic has been called */ |
688 | 688 | ||
689 | aux = context->aux; | 689 | aux = context->aux; |
690 | context->aux = aux->next; | 690 | context->aux = aux->next; |
691 | 691 | ||
692 | audit_log_format(ab, "auxitem=%d", aux->type); | 692 | audit_log_format(ab, "auxitem=%d", aux->type); |
693 | switch (aux->type) { | 693 | switch (aux->type) { |
694 | case AUDIT_AUX_IPCPERM: { | 694 | case AUDIT_AUX_IPCPERM: { |
695 | struct audit_aux_data_ipcctl *axi = (void *)aux; | 695 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
696 | audit_log_format(ab, | 696 | audit_log_format(ab, |
697 | " qbytes=%lx uid=%d gid=%d mode=%x", | 697 | " qbytes=%lx uid=%d gid=%d mode=%x", |
698 | axi->qbytes, axi->uid, axi->gid, axi->mode); | 698 | axi->qbytes, axi->uid, axi->gid, axi->mode); |
699 | } | 699 | } |
700 | } | 700 | } |
701 | audit_log_end(ab); | 701 | audit_log_end(ab); |
702 | kfree(aux); | 702 | kfree(aux); |
703 | } | 703 | } |
704 | 704 | ||
705 | for (i = 0; i < context->name_count; i++) { | 705 | for (i = 0; i < context->name_count; i++) { |
706 | ab = audit_log_start(context); | 706 | ab = audit_log_start(context); |
707 | if (!ab) | 707 | if (!ab) |
708 | continue; /* audit_panic has been called */ | 708 | continue; /* audit_panic has been called */ |
709 | audit_log_format(ab, "item=%d", i); | 709 | audit_log_format(ab, "item=%d", i); |
710 | if (context->names[i].name) { | 710 | if (context->names[i].name) { |
711 | audit_log_format(ab, " name="); | 711 | audit_log_format(ab, " name="); |
712 | audit_log_untrustedstring(ab, context->names[i].name); | 712 | audit_log_untrustedstring(ab, context->names[i].name); |
713 | } | 713 | } |
714 | if (context->names[i].ino != (unsigned long)-1) | 714 | if (context->names[i].ino != (unsigned long)-1) |
715 | audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o" | 715 | audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o" |
716 | " uid=%d gid=%d rdev=%02x:%02x", | 716 | " uid=%d gid=%d rdev=%02x:%02x", |
717 | context->names[i].ino, | 717 | context->names[i].ino, |
718 | MAJOR(context->names[i].dev), | 718 | MAJOR(context->names[i].dev), |
719 | MINOR(context->names[i].dev), | 719 | MINOR(context->names[i].dev), |
720 | context->names[i].mode, | 720 | context->names[i].mode, |
721 | context->names[i].uid, | 721 | context->names[i].uid, |
722 | context->names[i].gid, | 722 | context->names[i].gid, |
723 | MAJOR(context->names[i].rdev), | 723 | MAJOR(context->names[i].rdev), |
724 | MINOR(context->names[i].rdev)); | 724 | MINOR(context->names[i].rdev)); |
725 | audit_log_end(ab); | 725 | audit_log_end(ab); |
726 | } | 726 | } |
727 | } | 727 | } |
728 | 728 | ||
729 | /* Free a per-task audit context. Called from copy_process and | 729 | /* Free a per-task audit context. Called from copy_process and |
730 | * __put_task_struct. */ | 730 | * __put_task_struct. */ |
731 | void audit_free(struct task_struct *tsk) | 731 | void audit_free(struct task_struct *tsk) |
732 | { | 732 | { |
733 | struct audit_context *context; | 733 | struct audit_context *context; |
734 | 734 | ||
735 | task_lock(tsk); | 735 | task_lock(tsk); |
736 | context = audit_get_context(tsk, 0, 0); | 736 | context = audit_get_context(tsk, 0, 0); |
737 | task_unlock(tsk); | 737 | task_unlock(tsk); |
738 | 738 | ||
739 | if (likely(!context)) | 739 | if (likely(!context)) |
740 | return; | 740 | return; |
741 | 741 | ||
742 | /* Check for system calls that do not go through the exit | 742 | /* Check for system calls that do not go through the exit |
743 | * function (e.g., exit_group), then free context block. */ | 743 | * function (e.g., exit_group), then free context block. */ |
744 | if (context->in_syscall && context->auditable) | 744 | if (context->in_syscall && context->auditable) |
745 | audit_log_exit(context); | 745 | audit_log_exit(context); |
746 | 746 | ||
747 | audit_free_context(context); | 747 | audit_free_context(context); |
748 | } | 748 | } |
749 | 749 | ||
750 | /* Compute a serial number for the audit record. Audit records are | 750 | /* Compute a serial number for the audit record. Audit records are |
751 | * written to user-space as soon as they are generated, so a complete | 751 | * written to user-space as soon as they are generated, so a complete |
752 | * audit record may be written in several pieces. The timestamp of the | 752 | * audit record may be written in several pieces. The timestamp of the |
753 | * record and this serial number are used by the user-space daemon to | 753 | * record and this serial number are used by the user-space daemon to |
754 | * determine which pieces belong to the same audit record. The | 754 | * determine which pieces belong to the same audit record. The |
755 | * (timestamp,serial) tuple is unique for each syscall and is live from | 755 | * (timestamp,serial) tuple is unique for each syscall and is live from |
756 | * syscall entry to syscall exit. | 756 | * syscall entry to syscall exit. |
757 | * | 757 | * |
758 | * Atomic values are only guaranteed to be 24-bit, so we count down. | 758 | * Atomic values are only guaranteed to be 24-bit, so we count down. |
759 | * | 759 | * |
760 | * NOTE: Another possibility is to store the formatted records off the | 760 | * NOTE: Another possibility is to store the formatted records off the |
761 | * audit context (for those records that have a context), and emit them | 761 | * audit context (for those records that have a context), and emit them |
762 | * all at syscall exit. However, this could delay the reporting of | 762 | * all at syscall exit. However, this could delay the reporting of |
763 | * significant errors until syscall exit (or never, if the system | 763 | * significant errors until syscall exit (or never, if the system |
764 | * halts). */ | 764 | * halts). */ |
765 | static inline unsigned int audit_serial(void) | 765 | static inline unsigned int audit_serial(void) |
766 | { | 766 | { |
767 | static atomic_t serial = ATOMIC_INIT(0xffffff); | 767 | static atomic_t serial = ATOMIC_INIT(0xffffff); |
768 | unsigned int a, b; | 768 | unsigned int a, b; |
769 | 769 | ||
770 | do { | 770 | do { |
771 | a = atomic_read(&serial); | 771 | a = atomic_read(&serial); |
772 | if (atomic_dec_and_test(&serial)) | 772 | if (atomic_dec_and_test(&serial)) |
773 | atomic_set(&serial, 0xffffff); | 773 | atomic_set(&serial, 0xffffff); |
774 | b = atomic_read(&serial); | 774 | b = atomic_read(&serial); |
775 | } while (b != a - 1); | 775 | } while (b != a - 1); |
776 | 776 | ||
777 | return 0xffffff - b; | 777 | return 0xffffff - b; |
778 | } | 778 | } |
779 | 779 | ||
780 | /* Fill in audit context at syscall entry. This only happens if the | 780 | /* Fill in audit context at syscall entry. This only happens if the |
781 | * audit context was created when the task was created and the state or | 781 | * audit context was created when the task was created and the state or |
782 | * filters demand the audit context be built. If the state from the | 782 | * filters demand the audit context be built. If the state from the |
783 | * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT, | 783 | * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT, |
784 | * then the record will be written at syscall exit time (otherwise, it | 784 | * then the record will be written at syscall exit time (otherwise, it |
785 | * will only be written if another part of the kernel requests that it | 785 | * will only be written if another part of the kernel requests that it |
786 | * be written). */ | 786 | * be written). */ |
787 | void audit_syscall_entry(struct task_struct *tsk, int arch, int major, | 787 | void audit_syscall_entry(struct task_struct *tsk, int arch, int major, |
788 | unsigned long a1, unsigned long a2, | 788 | unsigned long a1, unsigned long a2, |
789 | unsigned long a3, unsigned long a4) | 789 | unsigned long a3, unsigned long a4) |
790 | { | 790 | { |
791 | struct audit_context *context = tsk->audit_context; | 791 | struct audit_context *context = tsk->audit_context; |
792 | enum audit_state state; | 792 | enum audit_state state; |
793 | 793 | ||
794 | BUG_ON(!context); | 794 | BUG_ON(!context); |
795 | 795 | ||
796 | /* This happens only on certain architectures that make system | 796 | /* This happens only on certain architectures that make system |
797 | * calls in kernel_thread via the entry.S interface, instead of | 797 | * calls in kernel_thread via the entry.S interface, instead of |
798 | * with direct calls. (If you are porting to a new | 798 | * with direct calls. (If you are porting to a new |
799 | * architecture, hitting this condition can indicate that you | 799 | * architecture, hitting this condition can indicate that you |
800 | * got the _exit/_leave calls backward in entry.S.) | 800 | * got the _exit/_leave calls backward in entry.S.) |
801 | * | 801 | * |
802 | * i386 no | 802 | * i386 no |
803 | * x86_64 no | 803 | * x86_64 no |
804 | * ppc64 yes (see arch/ppc64/kernel/misc.S) | 804 | * ppc64 yes (see arch/ppc64/kernel/misc.S) |
805 | * | 805 | * |
806 | * This also happens with vm86 emulation in a non-nested manner | 806 | * This also happens with vm86 emulation in a non-nested manner |
807 | * (entries without exits), so this case must be caught. | 807 | * (entries without exits), so this case must be caught. |
808 | */ | 808 | */ |
809 | if (context->in_syscall) { | 809 | if (context->in_syscall) { |
810 | struct audit_context *newctx; | 810 | struct audit_context *newctx; |
811 | 811 | ||
812 | #if defined(__NR_vm86) && defined(__NR_vm86old) | 812 | #if defined(__NR_vm86) && defined(__NR_vm86old) |
813 | /* vm86 mode should only be entered once */ | 813 | /* vm86 mode should only be entered once */ |
814 | if (major == __NR_vm86 || major == __NR_vm86old) | 814 | if (major == __NR_vm86 || major == __NR_vm86old) |
815 | return; | 815 | return; |
816 | #endif | 816 | #endif |
817 | #if AUDIT_DEBUG | 817 | #if AUDIT_DEBUG |
818 | printk(KERN_ERR | 818 | printk(KERN_ERR |
819 | "audit(:%d) pid=%d in syscall=%d;" | 819 | "audit(:%d) pid=%d in syscall=%d;" |
820 | " entering syscall=%d\n", | 820 | " entering syscall=%d\n", |
821 | context->serial, tsk->pid, context->major, major); | 821 | context->serial, tsk->pid, context->major, major); |
822 | #endif | 822 | #endif |
823 | newctx = audit_alloc_context(context->state); | 823 | newctx = audit_alloc_context(context->state); |
824 | if (newctx) { | 824 | if (newctx) { |
825 | newctx->previous = context; | 825 | newctx->previous = context; |
826 | context = newctx; | 826 | context = newctx; |
827 | tsk->audit_context = newctx; | 827 | tsk->audit_context = newctx; |
828 | } else { | 828 | } else { |
829 | /* If we can't alloc a new context, the best we | 829 | /* If we can't alloc a new context, the best we |
830 | * can do is to leak memory (any pending putname | 830 | * can do is to leak memory (any pending putname |
831 | * will be lost). The only other alternative is | 831 | * will be lost). The only other alternative is |
832 | * to abandon auditing. */ | 832 | * to abandon auditing. */ |
833 | audit_zero_context(context, context->state); | 833 | audit_zero_context(context, context->state); |
834 | } | 834 | } |
835 | } | 835 | } |
836 | BUG_ON(context->in_syscall || context->name_count); | 836 | BUG_ON(context->in_syscall || context->name_count); |
837 | 837 | ||
838 | if (!audit_enabled) | 838 | if (!audit_enabled) |
839 | return; | 839 | return; |
840 | 840 | ||
841 | context->arch = arch; | 841 | context->arch = arch; |
842 | context->major = major; | 842 | context->major = major; |
843 | context->argv[0] = a1; | 843 | context->argv[0] = a1; |
844 | context->argv[1] = a2; | 844 | context->argv[1] = a2; |
845 | context->argv[2] = a3; | 845 | context->argv[2] = a3; |
846 | context->argv[3] = a4; | 846 | context->argv[3] = a4; |
847 | 847 | ||
848 | state = context->state; | 848 | state = context->state; |
849 | if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT) | 849 | if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT) |
850 | state = audit_filter_syscall(tsk, context, &audit_entlist); | 850 | state = audit_filter_syscall(tsk, context, &audit_entlist); |
851 | if (likely(state == AUDIT_DISABLED)) | 851 | if (likely(state == AUDIT_DISABLED)) |
852 | return; | 852 | return; |
853 | 853 | ||
854 | context->serial = audit_serial(); | 854 | context->serial = audit_serial(); |
855 | context->ctime = CURRENT_TIME; | 855 | context->ctime = CURRENT_TIME; |
856 | context->in_syscall = 1; | 856 | context->in_syscall = 1; |
857 | context->auditable = !!(state == AUDIT_RECORD_CONTEXT); | 857 | context->auditable = !!(state == AUDIT_RECORD_CONTEXT); |
858 | } | 858 | } |
859 | 859 | ||
860 | /* Tear down after system call. If the audit context has been marked as | 860 | /* Tear down after system call. If the audit context has been marked as |
861 | * auditable (either because of the AUDIT_RECORD_CONTEXT state from | 861 | * auditable (either because of the AUDIT_RECORD_CONTEXT state from |
862 | * filtering, or because some other part of the kernel write an audit | 862 | * filtering, or because some other part of the kernel write an audit |
863 | * message), then write out the syscall information. In call cases, | 863 | * message), then write out the syscall information. In call cases, |
864 | * free the names stored from getname(). */ | 864 | * free the names stored from getname(). */ |
865 | void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) | 865 | void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code) |
866 | { | 866 | { |
867 | struct audit_context *context; | 867 | struct audit_context *context; |
868 | 868 | ||
869 | get_task_struct(tsk); | 869 | get_task_struct(tsk); |
870 | task_lock(tsk); | 870 | task_lock(tsk); |
871 | context = audit_get_context(tsk, valid, return_code); | 871 | context = audit_get_context(tsk, valid, return_code); |
872 | task_unlock(tsk); | 872 | task_unlock(tsk); |
873 | 873 | ||
874 | /* Not having a context here is ok, since the parent may have | 874 | /* Not having a context here is ok, since the parent may have |
875 | * called __put_task_struct. */ | 875 | * called __put_task_struct. */ |
876 | if (likely(!context)) | 876 | if (likely(!context)) |
877 | return; | 877 | return; |
878 | 878 | ||
879 | if (context->in_syscall && context->auditable) | 879 | if (context->in_syscall && context->auditable) |
880 | audit_log_exit(context); | 880 | audit_log_exit(context); |
881 | 881 | ||
882 | context->in_syscall = 0; | 882 | context->in_syscall = 0; |
883 | context->auditable = 0; | 883 | context->auditable = 0; |
884 | 884 | ||
885 | if (context->previous) { | 885 | if (context->previous) { |
886 | struct audit_context *new_context = context->previous; | 886 | struct audit_context *new_context = context->previous; |
887 | context->previous = NULL; | 887 | context->previous = NULL; |
888 | audit_free_context(context); | 888 | audit_free_context(context); |
889 | tsk->audit_context = new_context; | 889 | tsk->audit_context = new_context; |
890 | } else { | 890 | } else { |
891 | audit_free_names(context); | 891 | audit_free_names(context); |
892 | audit_free_aux(context); | 892 | audit_free_aux(context); |
893 | audit_zero_context(context, context->state); | 893 | audit_zero_context(context, context->state); |
894 | tsk->audit_context = context; | 894 | tsk->audit_context = context; |
895 | } | 895 | } |
896 | put_task_struct(tsk); | 896 | put_task_struct(tsk); |
897 | } | 897 | } |
898 | 898 | ||
899 | /* Add a name to the list. Called from fs/namei.c:getname(). */ | 899 | /* Add a name to the list. Called from fs/namei.c:getname(). */ |
900 | void audit_getname(const char *name) | 900 | void audit_getname(const char *name) |
901 | { | 901 | { |
902 | struct audit_context *context = current->audit_context; | 902 | struct audit_context *context = current->audit_context; |
903 | 903 | ||
904 | if (!context || IS_ERR(name) || !name) | 904 | if (!context || IS_ERR(name) || !name) |
905 | return; | 905 | return; |
906 | 906 | ||
907 | if (!context->in_syscall) { | 907 | if (!context->in_syscall) { |
908 | #if AUDIT_DEBUG == 2 | 908 | #if AUDIT_DEBUG == 2 |
909 | printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n", | 909 | printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n", |
910 | __FILE__, __LINE__, context->serial, name); | 910 | __FILE__, __LINE__, context->serial, name); |
911 | dump_stack(); | 911 | dump_stack(); |
912 | #endif | 912 | #endif |
913 | return; | 913 | return; |
914 | } | 914 | } |
915 | BUG_ON(context->name_count >= AUDIT_NAMES); | 915 | BUG_ON(context->name_count >= AUDIT_NAMES); |
916 | context->names[context->name_count].name = name; | 916 | context->names[context->name_count].name = name; |
917 | context->names[context->name_count].ino = (unsigned long)-1; | 917 | context->names[context->name_count].ino = (unsigned long)-1; |
918 | ++context->name_count; | 918 | ++context->name_count; |
919 | } | 919 | } |
920 | 920 | ||
921 | /* Intercept a putname request. Called from | 921 | /* Intercept a putname request. Called from |
922 | * include/linux/fs.h:putname(). If we have stored the name from | 922 | * include/linux/fs.h:putname(). If we have stored the name from |
923 | * getname in the audit context, then we delay the putname until syscall | 923 | * getname in the audit context, then we delay the putname until syscall |
924 | * exit. */ | 924 | * exit. */ |
925 | void audit_putname(const char *name) | 925 | void audit_putname(const char *name) |
926 | { | 926 | { |
927 | struct audit_context *context = current->audit_context; | 927 | struct audit_context *context = current->audit_context; |
928 | 928 | ||
929 | BUG_ON(!context); | 929 | BUG_ON(!context); |
930 | if (!context->in_syscall) { | 930 | if (!context->in_syscall) { |
931 | #if AUDIT_DEBUG == 2 | 931 | #if AUDIT_DEBUG == 2 |
932 | printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n", | 932 | printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n", |
933 | __FILE__, __LINE__, context->serial, name); | 933 | __FILE__, __LINE__, context->serial, name); |
934 | if (context->name_count) { | 934 | if (context->name_count) { |
935 | int i; | 935 | int i; |
936 | for (i = 0; i < context->name_count; i++) | 936 | for (i = 0; i < context->name_count; i++) |
937 | printk(KERN_ERR "name[%d] = %p = %s\n", i, | 937 | printk(KERN_ERR "name[%d] = %p = %s\n", i, |
938 | context->names[i].name, | 938 | context->names[i].name, |
939 | context->names[i].name); | 939 | context->names[i].name); |
940 | } | 940 | } |
941 | #endif | 941 | #endif |
942 | __putname(name); | 942 | __putname(name); |
943 | } | 943 | } |
944 | #if AUDIT_DEBUG | 944 | #if AUDIT_DEBUG |
945 | else { | 945 | else { |
946 | ++context->put_count; | 946 | ++context->put_count; |
947 | if (context->put_count > context->name_count) { | 947 | if (context->put_count > context->name_count) { |
948 | printk(KERN_ERR "%s:%d(:%d): major=%d" | 948 | printk(KERN_ERR "%s:%d(:%d): major=%d" |
949 | " in_syscall=%d putname(%p) name_count=%d" | 949 | " in_syscall=%d putname(%p) name_count=%d" |
950 | " put_count=%d\n", | 950 | " put_count=%d\n", |
951 | __FILE__, __LINE__, | 951 | __FILE__, __LINE__, |
952 | context->serial, context->major, | 952 | context->serial, context->major, |
953 | context->in_syscall, name, context->name_count, | 953 | context->in_syscall, name, context->name_count, |
954 | context->put_count); | 954 | context->put_count); |
955 | dump_stack(); | 955 | dump_stack(); |
956 | } | 956 | } |
957 | } | 957 | } |
958 | #endif | 958 | #endif |
959 | } | 959 | } |
960 | 960 | ||
961 | /* Store the inode and device from a lookup. Called from | 961 | /* Store the inode and device from a lookup. Called from |
962 | * fs/namei.c:path_lookup(). */ | 962 | * fs/namei.c:path_lookup(). */ |
963 | void audit_inode(const char *name, const struct inode *inode) | 963 | void audit_inode(const char *name, const struct inode *inode) |
964 | { | 964 | { |
965 | int idx; | 965 | int idx; |
966 | struct audit_context *context = current->audit_context; | 966 | struct audit_context *context = current->audit_context; |
967 | 967 | ||
968 | if (!context->in_syscall) | 968 | if (!context->in_syscall) |
969 | return; | 969 | return; |
970 | if (context->name_count | 970 | if (context->name_count |
971 | && context->names[context->name_count-1].name | 971 | && context->names[context->name_count-1].name |
972 | && context->names[context->name_count-1].name == name) | 972 | && context->names[context->name_count-1].name == name) |
973 | idx = context->name_count - 1; | 973 | idx = context->name_count - 1; |
974 | else if (context->name_count > 1 | 974 | else if (context->name_count > 1 |
975 | && context->names[context->name_count-2].name | 975 | && context->names[context->name_count-2].name |
976 | && context->names[context->name_count-2].name == name) | 976 | && context->names[context->name_count-2].name == name) |
977 | idx = context->name_count - 2; | 977 | idx = context->name_count - 2; |
978 | else { | 978 | else { |
979 | /* FIXME: how much do we care about inodes that have no | 979 | /* FIXME: how much do we care about inodes that have no |
980 | * associated name? */ | 980 | * associated name? */ |
981 | if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED) | 981 | if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED) |
982 | return; | 982 | return; |
983 | idx = context->name_count++; | 983 | idx = context->name_count++; |
984 | context->names[idx].name = NULL; | 984 | context->names[idx].name = NULL; |
985 | #if AUDIT_DEBUG | 985 | #if AUDIT_DEBUG |
986 | ++context->ino_count; | 986 | ++context->ino_count; |
987 | #endif | 987 | #endif |
988 | } | 988 | } |
989 | context->names[idx].ino = inode->i_ino; | 989 | context->names[idx].ino = inode->i_ino; |
990 | context->names[idx].dev = inode->i_sb->s_dev; | 990 | context->names[idx].dev = inode->i_sb->s_dev; |
991 | context->names[idx].mode = inode->i_mode; | 991 | context->names[idx].mode = inode->i_mode; |
992 | context->names[idx].uid = inode->i_uid; | 992 | context->names[idx].uid = inode->i_uid; |
993 | context->names[idx].gid = inode->i_gid; | 993 | context->names[idx].gid = inode->i_gid; |
994 | context->names[idx].rdev = inode->i_rdev; | 994 | context->names[idx].rdev = inode->i_rdev; |
995 | } | 995 | } |
996 | 996 | ||
997 | void audit_get_stamp(struct audit_context *ctx, | 997 | void audit_get_stamp(struct audit_context *ctx, |
998 | struct timespec *t, unsigned int *serial) | 998 | struct timespec *t, unsigned int *serial) |
999 | { | 999 | { |
1000 | if (ctx) { | 1000 | if (ctx) { |
1001 | t->tv_sec = ctx->ctime.tv_sec; | 1001 | t->tv_sec = ctx->ctime.tv_sec; |
1002 | t->tv_nsec = ctx->ctime.tv_nsec; | 1002 | t->tv_nsec = ctx->ctime.tv_nsec; |
1003 | *serial = ctx->serial; | 1003 | *serial = ctx->serial; |
1004 | ctx->auditable = 1; | 1004 | ctx->auditable = 1; |
1005 | } else { | 1005 | } else { |
1006 | *t = CURRENT_TIME; | 1006 | *t = CURRENT_TIME; |
1007 | *serial = 0; | 1007 | *serial = 0; |
1008 | } | 1008 | } |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | extern int audit_set_type(struct audit_buffer *ab, int type); | 1011 | extern int audit_set_type(struct audit_buffer *ab, int type); |
1012 | 1012 | ||
1013 | int audit_set_loginuid(struct audit_context *ctx, uid_t loginuid) | 1013 | int audit_set_loginuid(struct task_struct *task, uid_t loginuid) |
1014 | { | 1014 | { |
1015 | if (ctx) { | 1015 | if (task->audit_context) { |
1016 | struct audit_buffer *ab; | 1016 | struct audit_buffer *ab; |
1017 | 1017 | ||
1018 | ab = audit_log_start(NULL); | 1018 | ab = audit_log_start(NULL); |
1019 | if (ab) { | 1019 | if (ab) { |
1020 | audit_log_format(ab, "login pid=%d uid=%u " | 1020 | audit_log_format(ab, "login pid=%d uid=%u " |
1021 | "old loginuid=%u new loginuid=%u", | 1021 | "old loginuid=%u new loginuid=%u", |
1022 | ctx->pid, ctx->uid, ctx->loginuid, loginuid); | 1022 | task->pid, task->uid, |
1023 | task->audit_context->loginuid, loginuid); | ||
1023 | audit_set_type(ab, AUDIT_LOGIN); | 1024 | audit_set_type(ab, AUDIT_LOGIN); |
1024 | audit_log_end(ab); | 1025 | audit_log_end(ab); |
1025 | } | 1026 | } |
1026 | ctx->loginuid = loginuid; | 1027 | task->audit_context->loginuid = loginuid; |
1027 | } | 1028 | } |
1028 | return 0; | 1029 | return 0; |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | uid_t audit_get_loginuid(struct audit_context *ctx) | 1032 | uid_t audit_get_loginuid(struct audit_context *ctx) |
1032 | { | 1033 | { |
1033 | return ctx ? ctx->loginuid : -1; | 1034 | return ctx ? ctx->loginuid : -1; |
1034 | } | 1035 | } |
1035 | 1036 | ||
1036 | int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode) | 1037 | int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode) |
1037 | { | 1038 | { |
1038 | struct audit_aux_data_ipcctl *ax; | 1039 | struct audit_aux_data_ipcctl *ax; |
1039 | struct audit_context *context = current->audit_context; | 1040 | struct audit_context *context = current->audit_context; |
1040 | 1041 | ||
1041 | if (likely(!context)) | 1042 | if (likely(!context)) |
1042 | return 0; | 1043 | return 0; |
1043 | 1044 | ||
1044 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); | 1045 | ax = kmalloc(sizeof(*ax), GFP_KERNEL); |
1045 | if (!ax) | 1046 | if (!ax) |
1046 | return -ENOMEM; | 1047 | return -ENOMEM; |
1047 | 1048 | ||
1048 | ax->qbytes = qbytes; | 1049 | ax->qbytes = qbytes; |
1049 | ax->uid = uid; | 1050 | ax->uid = uid; |
1050 | ax->gid = gid; | 1051 | ax->gid = gid; |
1051 | ax->mode = mode; | 1052 | ax->mode = mode; |
1052 | 1053 | ||
1053 | ax->d.type = AUDIT_AUX_IPCPERM; | 1054 | ax->d.type = AUDIT_AUX_IPCPERM; |
1054 | ax->d.next = context->aux; | 1055 | ax->d.next = context->aux; |
1055 | context->aux = (void *)ax; | 1056 | context->aux = (void *)ax; |
1056 | return 0; | 1057 | return 0; |
1057 | } | 1058 | } |
1058 | 1059 |