.. | .. |
---|
24 | 24 | #include <linux/seq_file.h> |
---|
25 | 25 | #include <linux/slab.h> |
---|
26 | 26 | #include <linux/mount.h> |
---|
27 | | -#include <linux/magic.h> |
---|
| 27 | +#include <linux/bug.h> |
---|
28 | 28 | |
---|
29 | 29 | #include <linux/uaccess.h> |
---|
30 | 30 | |
---|
.. | .. |
---|
34 | 34 | { |
---|
35 | 35 | struct proc_dir_entry *de; |
---|
36 | 36 | struct ctl_table_header *head; |
---|
| 37 | + struct proc_inode *ei = PROC_I(inode); |
---|
37 | 38 | |
---|
38 | 39 | truncate_inode_pages_final(&inode->i_data); |
---|
39 | 40 | clear_inode(inode); |
---|
40 | 41 | |
---|
41 | 42 | /* Stop tracking associated processes */ |
---|
42 | | - put_pid(PROC_I(inode)->pid); |
---|
| 43 | + if (ei->pid) { |
---|
| 44 | + proc_pid_evict_inode(ei); |
---|
| 45 | + ei->pid = NULL; |
---|
| 46 | + } |
---|
43 | 47 | |
---|
44 | 48 | /* Let go of any associated proc directory entry */ |
---|
45 | | - de = PDE(inode); |
---|
46 | | - if (de) |
---|
| 49 | + de = ei->pde; |
---|
| 50 | + if (de) { |
---|
47 | 51 | pde_put(de); |
---|
| 52 | + ei->pde = NULL; |
---|
| 53 | + } |
---|
48 | 54 | |
---|
49 | | - head = PROC_I(inode)->sysctl; |
---|
| 55 | + head = ei->sysctl; |
---|
50 | 56 | if (head) { |
---|
51 | | - RCU_INIT_POINTER(PROC_I(inode)->sysctl, NULL); |
---|
| 57 | + RCU_INIT_POINTER(ei->sysctl, NULL); |
---|
52 | 58 | proc_sys_evict_inode(inode, head); |
---|
53 | 59 | } |
---|
54 | 60 | } |
---|
.. | .. |
---|
59 | 65 | static struct inode *proc_alloc_inode(struct super_block *sb) |
---|
60 | 66 | { |
---|
61 | 67 | struct proc_inode *ei; |
---|
62 | | - struct inode *inode; |
---|
63 | 68 | |
---|
64 | 69 | ei = kmem_cache_alloc(proc_inode_cachep, GFP_KERNEL); |
---|
65 | 70 | if (!ei) |
---|
.. | .. |
---|
70 | 75 | ei->pde = NULL; |
---|
71 | 76 | ei->sysctl = NULL; |
---|
72 | 77 | ei->sysctl_entry = NULL; |
---|
| 78 | + INIT_HLIST_NODE(&ei->sibling_inodes); |
---|
73 | 79 | ei->ns_ops = NULL; |
---|
74 | | - inode = &ei->vfs_inode; |
---|
75 | | - return inode; |
---|
| 80 | + return &ei->vfs_inode; |
---|
76 | 81 | } |
---|
77 | 82 | |
---|
78 | | -static void proc_i_callback(struct rcu_head *head) |
---|
| 83 | +static void proc_free_inode(struct inode *inode) |
---|
79 | 84 | { |
---|
80 | | - struct inode *inode = container_of(head, struct inode, i_rcu); |
---|
81 | 85 | kmem_cache_free(proc_inode_cachep, PROC_I(inode)); |
---|
82 | | -} |
---|
83 | | - |
---|
84 | | -static void proc_destroy_inode(struct inode *inode) |
---|
85 | | -{ |
---|
86 | | - call_rcu(&inode->i_rcu, proc_i_callback); |
---|
87 | 86 | } |
---|
88 | 87 | |
---|
89 | 88 | static void init_once(void *foo) |
---|
.. | .. |
---|
111 | 110 | BUILD_BUG_ON(sizeof(struct proc_dir_entry) >= SIZEOF_PDE); |
---|
112 | 111 | } |
---|
113 | 112 | |
---|
| 113 | +void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock) |
---|
| 114 | +{ |
---|
| 115 | + struct inode *inode; |
---|
| 116 | + struct proc_inode *ei; |
---|
| 117 | + struct hlist_node *node; |
---|
| 118 | + struct super_block *old_sb = NULL; |
---|
| 119 | + |
---|
| 120 | + rcu_read_lock(); |
---|
| 121 | + for (;;) { |
---|
| 122 | + struct super_block *sb; |
---|
| 123 | + node = hlist_first_rcu(inodes); |
---|
| 124 | + if (!node) |
---|
| 125 | + break; |
---|
| 126 | + ei = hlist_entry(node, struct proc_inode, sibling_inodes); |
---|
| 127 | + spin_lock(lock); |
---|
| 128 | + hlist_del_init_rcu(&ei->sibling_inodes); |
---|
| 129 | + spin_unlock(lock); |
---|
| 130 | + |
---|
| 131 | + inode = &ei->vfs_inode; |
---|
| 132 | + sb = inode->i_sb; |
---|
| 133 | + if ((sb != old_sb) && !atomic_inc_not_zero(&sb->s_active)) |
---|
| 134 | + continue; |
---|
| 135 | + inode = igrab(inode); |
---|
| 136 | + rcu_read_unlock(); |
---|
| 137 | + if (sb != old_sb) { |
---|
| 138 | + if (old_sb) |
---|
| 139 | + deactivate_super(old_sb); |
---|
| 140 | + old_sb = sb; |
---|
| 141 | + } |
---|
| 142 | + if (unlikely(!inode)) { |
---|
| 143 | + rcu_read_lock(); |
---|
| 144 | + continue; |
---|
| 145 | + } |
---|
| 146 | + |
---|
| 147 | + if (S_ISDIR(inode->i_mode)) { |
---|
| 148 | + struct dentry *dir = d_find_any_alias(inode); |
---|
| 149 | + if (dir) { |
---|
| 150 | + d_invalidate(dir); |
---|
| 151 | + dput(dir); |
---|
| 152 | + } |
---|
| 153 | + } else { |
---|
| 154 | + struct dentry *dentry; |
---|
| 155 | + while ((dentry = d_find_alias(inode))) { |
---|
| 156 | + d_invalidate(dentry); |
---|
| 157 | + dput(dentry); |
---|
| 158 | + } |
---|
| 159 | + } |
---|
| 160 | + iput(inode); |
---|
| 161 | + |
---|
| 162 | + rcu_read_lock(); |
---|
| 163 | + } |
---|
| 164 | + rcu_read_unlock(); |
---|
| 165 | + if (old_sb) |
---|
| 166 | + deactivate_super(old_sb); |
---|
| 167 | +} |
---|
| 168 | + |
---|
| 169 | +static inline const char *hidepid2str(enum proc_hidepid v) |
---|
| 170 | +{ |
---|
| 171 | + switch (v) { |
---|
| 172 | + case HIDEPID_OFF: return "off"; |
---|
| 173 | + case HIDEPID_NO_ACCESS: return "noaccess"; |
---|
| 174 | + case HIDEPID_INVISIBLE: return "invisible"; |
---|
| 175 | + case HIDEPID_NOT_PTRACEABLE: return "ptraceable"; |
---|
| 176 | + } |
---|
| 177 | + WARN_ONCE(1, "bad hide_pid value: %d\n", v); |
---|
| 178 | + return "unknown"; |
---|
| 179 | +} |
---|
| 180 | + |
---|
114 | 181 | static int proc_show_options(struct seq_file *seq, struct dentry *root) |
---|
115 | 182 | { |
---|
116 | | - struct super_block *sb = root->d_sb; |
---|
117 | | - struct pid_namespace *pid = sb->s_fs_info; |
---|
| 183 | + struct proc_fs_info *fs_info = proc_sb_info(root->d_sb); |
---|
118 | 184 | |
---|
119 | | - if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID)) |
---|
120 | | - seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid)); |
---|
121 | | - if (pid->hide_pid != HIDEPID_OFF) |
---|
122 | | - seq_printf(seq, ",hidepid=%u", pid->hide_pid); |
---|
| 185 | + if (!gid_eq(fs_info->pid_gid, GLOBAL_ROOT_GID)) |
---|
| 186 | + seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, fs_info->pid_gid)); |
---|
| 187 | + if (fs_info->hide_pid != HIDEPID_OFF) |
---|
| 188 | + seq_printf(seq, ",hidepid=%s", hidepid2str(fs_info->hide_pid)); |
---|
| 189 | + if (fs_info->pidonly != PROC_PIDONLY_OFF) |
---|
| 190 | + seq_printf(seq, ",subset=pid"); |
---|
123 | 191 | |
---|
124 | 192 | return 0; |
---|
125 | 193 | } |
---|
126 | 194 | |
---|
127 | | -static const struct super_operations proc_sops = { |
---|
| 195 | +const struct super_operations proc_sops = { |
---|
128 | 196 | .alloc_inode = proc_alloc_inode, |
---|
129 | | - .destroy_inode = proc_destroy_inode, |
---|
| 197 | + .free_inode = proc_free_inode, |
---|
130 | 198 | .drop_inode = generic_delete_inode, |
---|
131 | 199 | .evict_inode = proc_evict_inode, |
---|
132 | 200 | .statfs = simple_statfs, |
---|
133 | | - .remount_fs = proc_remount, |
---|
134 | 201 | .show_options = proc_show_options, |
---|
135 | 202 | }; |
---|
136 | 203 | |
---|
.. | .. |
---|
149 | 216 | |
---|
150 | 217 | /* pde is locked on entry, unlocked on exit */ |
---|
151 | 218 | static void close_pdeo(struct proc_dir_entry *pde, struct pde_opener *pdeo) |
---|
| 219 | + __releases(&pde->pde_unload_lock) |
---|
152 | 220 | { |
---|
153 | 221 | /* |
---|
154 | 222 | * close() (proc_reg_release()) can't delete an entry and proceed: |
---|
.. | .. |
---|
173 | 241 | pdeo->closing = true; |
---|
174 | 242 | spin_unlock(&pde->pde_unload_lock); |
---|
175 | 243 | file = pdeo->file; |
---|
176 | | - pde->proc_fops->release(file_inode(file), file); |
---|
| 244 | + pde->proc_ops->proc_release(file_inode(file), file); |
---|
177 | 245 | spin_lock(&pde->pde_unload_lock); |
---|
178 | 246 | /* After ->release. */ |
---|
179 | 247 | list_del(&pdeo->lh); |
---|
.. | .. |
---|
205 | 273 | spin_unlock(&de->pde_unload_lock); |
---|
206 | 274 | } |
---|
207 | 275 | |
---|
| 276 | +static loff_t pde_lseek(struct proc_dir_entry *pde, struct file *file, loff_t offset, int whence) |
---|
| 277 | +{ |
---|
| 278 | + typeof_member(struct proc_ops, proc_lseek) lseek; |
---|
| 279 | + |
---|
| 280 | + lseek = pde->proc_ops->proc_lseek; |
---|
| 281 | + if (!lseek) |
---|
| 282 | + lseek = default_llseek; |
---|
| 283 | + return lseek(file, offset, whence); |
---|
| 284 | +} |
---|
| 285 | + |
---|
208 | 286 | static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) |
---|
209 | 287 | { |
---|
210 | 288 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
211 | 289 | loff_t rv = -EINVAL; |
---|
212 | | - if (use_pde(pde)) { |
---|
213 | | - loff_t (*llseek)(struct file *, loff_t, int); |
---|
214 | | - llseek = pde->proc_fops->llseek; |
---|
215 | | - if (!llseek) |
---|
216 | | - llseek = default_llseek; |
---|
217 | | - rv = llseek(file, offset, whence); |
---|
| 290 | + |
---|
| 291 | + if (pde_is_permanent(pde)) { |
---|
| 292 | + return pde_lseek(pde, file, offset, whence); |
---|
| 293 | + } else if (use_pde(pde)) { |
---|
| 294 | + rv = pde_lseek(pde, file, offset, whence); |
---|
218 | 295 | unuse_pde(pde); |
---|
219 | 296 | } |
---|
220 | 297 | return rv; |
---|
| 298 | +} |
---|
| 299 | + |
---|
| 300 | +static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter) |
---|
| 301 | +{ |
---|
| 302 | + struct proc_dir_entry *pde = PDE(file_inode(iocb->ki_filp)); |
---|
| 303 | + ssize_t ret; |
---|
| 304 | + |
---|
| 305 | + if (pde_is_permanent(pde)) |
---|
| 306 | + return pde->proc_ops->proc_read_iter(iocb, iter); |
---|
| 307 | + |
---|
| 308 | + if (!use_pde(pde)) |
---|
| 309 | + return -EIO; |
---|
| 310 | + ret = pde->proc_ops->proc_read_iter(iocb, iter); |
---|
| 311 | + unuse_pde(pde); |
---|
| 312 | + return ret; |
---|
| 313 | +} |
---|
| 314 | + |
---|
| 315 | +static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos) |
---|
| 316 | +{ |
---|
| 317 | + typeof_member(struct proc_ops, proc_read) read; |
---|
| 318 | + |
---|
| 319 | + read = pde->proc_ops->proc_read; |
---|
| 320 | + if (read) |
---|
| 321 | + return read(file, buf, count, ppos); |
---|
| 322 | + return -EIO; |
---|
221 | 323 | } |
---|
222 | 324 | |
---|
223 | 325 | static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
---|
224 | 326 | { |
---|
225 | | - ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); |
---|
226 | 327 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
227 | 328 | ssize_t rv = -EIO; |
---|
228 | | - if (use_pde(pde)) { |
---|
229 | | - read = pde->proc_fops->read; |
---|
230 | | - if (read) |
---|
231 | | - rv = read(file, buf, count, ppos); |
---|
| 329 | + |
---|
| 330 | + if (pde_is_permanent(pde)) { |
---|
| 331 | + return pde_read(pde, file, buf, count, ppos); |
---|
| 332 | + } else if (use_pde(pde)) { |
---|
| 333 | + rv = pde_read(pde, file, buf, count, ppos); |
---|
232 | 334 | unuse_pde(pde); |
---|
233 | 335 | } |
---|
234 | 336 | return rv; |
---|
235 | 337 | } |
---|
236 | 338 | |
---|
| 339 | +static ssize_t pde_write(struct proc_dir_entry *pde, struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
---|
| 340 | +{ |
---|
| 341 | + typeof_member(struct proc_ops, proc_write) write; |
---|
| 342 | + |
---|
| 343 | + write = pde->proc_ops->proc_write; |
---|
| 344 | + if (write) |
---|
| 345 | + return write(file, buf, count, ppos); |
---|
| 346 | + return -EIO; |
---|
| 347 | +} |
---|
| 348 | + |
---|
237 | 349 | static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
---|
238 | 350 | { |
---|
239 | | - ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); |
---|
240 | 351 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
241 | 352 | ssize_t rv = -EIO; |
---|
242 | | - if (use_pde(pde)) { |
---|
243 | | - write = pde->proc_fops->write; |
---|
244 | | - if (write) |
---|
245 | | - rv = write(file, buf, count, ppos); |
---|
| 353 | + |
---|
| 354 | + if (pde_is_permanent(pde)) { |
---|
| 355 | + return pde_write(pde, file, buf, count, ppos); |
---|
| 356 | + } else if (use_pde(pde)) { |
---|
| 357 | + rv = pde_write(pde, file, buf, count, ppos); |
---|
246 | 358 | unuse_pde(pde); |
---|
247 | 359 | } |
---|
248 | 360 | return rv; |
---|
| 361 | +} |
---|
| 362 | + |
---|
| 363 | +static __poll_t pde_poll(struct proc_dir_entry *pde, struct file *file, struct poll_table_struct *pts) |
---|
| 364 | +{ |
---|
| 365 | + typeof_member(struct proc_ops, proc_poll) poll; |
---|
| 366 | + |
---|
| 367 | + poll = pde->proc_ops->proc_poll; |
---|
| 368 | + if (poll) |
---|
| 369 | + return poll(file, pts); |
---|
| 370 | + return DEFAULT_POLLMASK; |
---|
249 | 371 | } |
---|
250 | 372 | |
---|
251 | 373 | static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts) |
---|
252 | 374 | { |
---|
253 | 375 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
254 | 376 | __poll_t rv = DEFAULT_POLLMASK; |
---|
255 | | - __poll_t (*poll)(struct file *, struct poll_table_struct *); |
---|
256 | | - if (use_pde(pde)) { |
---|
257 | | - poll = pde->proc_fops->poll; |
---|
258 | | - if (poll) |
---|
259 | | - rv = poll(file, pts); |
---|
| 377 | + |
---|
| 378 | + if (pde_is_permanent(pde)) { |
---|
| 379 | + return pde_poll(pde, file, pts); |
---|
| 380 | + } else if (use_pde(pde)) { |
---|
| 381 | + rv = pde_poll(pde, file, pts); |
---|
260 | 382 | unuse_pde(pde); |
---|
261 | 383 | } |
---|
262 | 384 | return rv; |
---|
| 385 | +} |
---|
| 386 | + |
---|
| 387 | +static long pde_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg) |
---|
| 388 | +{ |
---|
| 389 | + typeof_member(struct proc_ops, proc_ioctl) ioctl; |
---|
| 390 | + |
---|
| 391 | + ioctl = pde->proc_ops->proc_ioctl; |
---|
| 392 | + if (ioctl) |
---|
| 393 | + return ioctl(file, cmd, arg); |
---|
| 394 | + return -ENOTTY; |
---|
263 | 395 | } |
---|
264 | 396 | |
---|
265 | 397 | static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
---|
266 | 398 | { |
---|
267 | 399 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
268 | 400 | long rv = -ENOTTY; |
---|
269 | | - long (*ioctl)(struct file *, unsigned int, unsigned long); |
---|
270 | | - if (use_pde(pde)) { |
---|
271 | | - ioctl = pde->proc_fops->unlocked_ioctl; |
---|
272 | | - if (ioctl) |
---|
273 | | - rv = ioctl(file, cmd, arg); |
---|
| 401 | + |
---|
| 402 | + if (pde_is_permanent(pde)) { |
---|
| 403 | + return pde_ioctl(pde, file, cmd, arg); |
---|
| 404 | + } else if (use_pde(pde)) { |
---|
| 405 | + rv = pde_ioctl(pde, file, cmd, arg); |
---|
274 | 406 | unuse_pde(pde); |
---|
275 | 407 | } |
---|
276 | 408 | return rv; |
---|
277 | 409 | } |
---|
278 | 410 | |
---|
279 | 411 | #ifdef CONFIG_COMPAT |
---|
| 412 | +static long pde_compat_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg) |
---|
| 413 | +{ |
---|
| 414 | + typeof_member(struct proc_ops, proc_compat_ioctl) compat_ioctl; |
---|
| 415 | + |
---|
| 416 | + compat_ioctl = pde->proc_ops->proc_compat_ioctl; |
---|
| 417 | + if (compat_ioctl) |
---|
| 418 | + return compat_ioctl(file, cmd, arg); |
---|
| 419 | + return -ENOTTY; |
---|
| 420 | +} |
---|
| 421 | + |
---|
280 | 422 | static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
---|
281 | 423 | { |
---|
282 | 424 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
283 | 425 | long rv = -ENOTTY; |
---|
284 | | - long (*compat_ioctl)(struct file *, unsigned int, unsigned long); |
---|
285 | | - if (use_pde(pde)) { |
---|
286 | | - compat_ioctl = pde->proc_fops->compat_ioctl; |
---|
287 | | - if (compat_ioctl) |
---|
288 | | - rv = compat_ioctl(file, cmd, arg); |
---|
| 426 | + if (pde_is_permanent(pde)) { |
---|
| 427 | + return pde_compat_ioctl(pde, file, cmd, arg); |
---|
| 428 | + } else if (use_pde(pde)) { |
---|
| 429 | + rv = pde_compat_ioctl(pde, file, cmd, arg); |
---|
289 | 430 | unuse_pde(pde); |
---|
290 | 431 | } |
---|
291 | 432 | return rv; |
---|
292 | 433 | } |
---|
293 | 434 | #endif |
---|
294 | 435 | |
---|
| 436 | +static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct vm_area_struct *vma) |
---|
| 437 | +{ |
---|
| 438 | + typeof_member(struct proc_ops, proc_mmap) mmap; |
---|
| 439 | + |
---|
| 440 | + mmap = pde->proc_ops->proc_mmap; |
---|
| 441 | + if (mmap) |
---|
| 442 | + return mmap(file, vma); |
---|
| 443 | + return -EIO; |
---|
| 444 | +} |
---|
| 445 | + |
---|
295 | 446 | static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma) |
---|
296 | 447 | { |
---|
297 | 448 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
298 | 449 | int rv = -EIO; |
---|
299 | | - int (*mmap)(struct file *, struct vm_area_struct *); |
---|
300 | | - if (use_pde(pde)) { |
---|
301 | | - mmap = pde->proc_fops->mmap; |
---|
302 | | - if (mmap) |
---|
303 | | - rv = mmap(file, vma); |
---|
| 450 | + |
---|
| 451 | + if (pde_is_permanent(pde)) { |
---|
| 452 | + return pde_mmap(pde, file, vma); |
---|
| 453 | + } else if (use_pde(pde)) { |
---|
| 454 | + rv = pde_mmap(pde, file, vma); |
---|
304 | 455 | unuse_pde(pde); |
---|
305 | 456 | } |
---|
306 | 457 | return rv; |
---|
| 458 | +} |
---|
| 459 | + |
---|
| 460 | +static unsigned long |
---|
| 461 | +pde_get_unmapped_area(struct proc_dir_entry *pde, struct file *file, unsigned long orig_addr, |
---|
| 462 | + unsigned long len, unsigned long pgoff, |
---|
| 463 | + unsigned long flags) |
---|
| 464 | +{ |
---|
| 465 | + typeof_member(struct proc_ops, proc_get_unmapped_area) get_area; |
---|
| 466 | + |
---|
| 467 | + get_area = pde->proc_ops->proc_get_unmapped_area; |
---|
| 468 | +#ifdef CONFIG_MMU |
---|
| 469 | + if (!get_area) |
---|
| 470 | + get_area = current->mm->get_unmapped_area; |
---|
| 471 | +#endif |
---|
| 472 | + if (get_area) |
---|
| 473 | + return get_area(file, orig_addr, len, pgoff, flags); |
---|
| 474 | + return orig_addr; |
---|
307 | 475 | } |
---|
308 | 476 | |
---|
309 | 477 | static unsigned long |
---|
.. | .. |
---|
314 | 482 | struct proc_dir_entry *pde = PDE(file_inode(file)); |
---|
315 | 483 | unsigned long rv = -EIO; |
---|
316 | 484 | |
---|
317 | | - if (use_pde(pde)) { |
---|
318 | | - typeof(proc_reg_get_unmapped_area) *get_area; |
---|
319 | | - |
---|
320 | | - get_area = pde->proc_fops->get_unmapped_area; |
---|
321 | | -#ifdef CONFIG_MMU |
---|
322 | | - if (!get_area) |
---|
323 | | - get_area = current->mm->get_unmapped_area; |
---|
324 | | -#endif |
---|
325 | | - |
---|
326 | | - if (get_area) |
---|
327 | | - rv = get_area(file, orig_addr, len, pgoff, flags); |
---|
328 | | - else |
---|
329 | | - rv = orig_addr; |
---|
| 485 | + if (pde_is_permanent(pde)) { |
---|
| 486 | + return pde_get_unmapped_area(pde, file, orig_addr, len, pgoff, flags); |
---|
| 487 | + } else if (use_pde(pde)) { |
---|
| 488 | + rv = pde_get_unmapped_area(pde, file, orig_addr, len, pgoff, flags); |
---|
330 | 489 | unuse_pde(pde); |
---|
331 | 490 | } |
---|
332 | 491 | return rv; |
---|
.. | .. |
---|
334 | 493 | |
---|
335 | 494 | static int proc_reg_open(struct inode *inode, struct file *file) |
---|
336 | 495 | { |
---|
| 496 | + struct proc_fs_info *fs_info = proc_sb_info(inode->i_sb); |
---|
337 | 497 | struct proc_dir_entry *pde = PDE(inode); |
---|
338 | 498 | int rv = 0; |
---|
339 | | - int (*open)(struct inode *, struct file *); |
---|
340 | | - int (*release)(struct inode *, struct file *); |
---|
| 499 | + typeof_member(struct proc_ops, proc_open) open; |
---|
| 500 | + typeof_member(struct proc_ops, proc_release) release; |
---|
341 | 501 | struct pde_opener *pdeo; |
---|
| 502 | + |
---|
| 503 | + if (pde_is_permanent(pde)) { |
---|
| 504 | + open = pde->proc_ops->proc_open; |
---|
| 505 | + if (open) |
---|
| 506 | + rv = open(inode, file); |
---|
| 507 | + return rv; |
---|
| 508 | + } |
---|
| 509 | + |
---|
| 510 | + if (fs_info->pidonly == PROC_PIDONLY_ON) |
---|
| 511 | + return -ENOENT; |
---|
342 | 512 | |
---|
343 | 513 | /* |
---|
344 | 514 | * Ensure that |
---|
.. | .. |
---|
354 | 524 | if (!use_pde(pde)) |
---|
355 | 525 | return -ENOENT; |
---|
356 | 526 | |
---|
357 | | - release = pde->proc_fops->release; |
---|
| 527 | + release = pde->proc_ops->proc_release; |
---|
358 | 528 | if (release) { |
---|
359 | 529 | pdeo = kmem_cache_alloc(pde_opener_cache, GFP_KERNEL); |
---|
360 | 530 | if (!pdeo) { |
---|
.. | .. |
---|
363 | 533 | } |
---|
364 | 534 | } |
---|
365 | 535 | |
---|
366 | | - open = pde->proc_fops->open; |
---|
| 536 | + open = pde->proc_ops->proc_open; |
---|
367 | 537 | if (open) |
---|
368 | 538 | rv = open(inode, file); |
---|
369 | 539 | |
---|
.. | .. |
---|
389 | 559 | { |
---|
390 | 560 | struct proc_dir_entry *pde = PDE(inode); |
---|
391 | 561 | struct pde_opener *pdeo; |
---|
| 562 | + |
---|
| 563 | + if (pde_is_permanent(pde)) { |
---|
| 564 | + typeof_member(struct proc_ops, proc_release) release; |
---|
| 565 | + |
---|
| 566 | + release = pde->proc_ops->proc_release; |
---|
| 567 | + if (release) { |
---|
| 568 | + return release(inode, file); |
---|
| 569 | + } |
---|
| 570 | + return 0; |
---|
| 571 | + } |
---|
| 572 | + |
---|
392 | 573 | spin_lock(&pde->pde_unload_lock); |
---|
393 | 574 | list_for_each_entry(pdeo, &pde->pde_openers, lh) { |
---|
394 | 575 | if (pdeo->file == file) { |
---|
.. | .. |
---|
406 | 587 | .write = proc_reg_write, |
---|
407 | 588 | .poll = proc_reg_poll, |
---|
408 | 589 | .unlocked_ioctl = proc_reg_unlocked_ioctl, |
---|
409 | | -#ifdef CONFIG_COMPAT |
---|
410 | | - .compat_ioctl = proc_reg_compat_ioctl, |
---|
411 | | -#endif |
---|
| 590 | + .mmap = proc_reg_mmap, |
---|
| 591 | + .get_unmapped_area = proc_reg_get_unmapped_area, |
---|
| 592 | + .open = proc_reg_open, |
---|
| 593 | + .release = proc_reg_release, |
---|
| 594 | +}; |
---|
| 595 | + |
---|
| 596 | +static const struct file_operations proc_iter_file_ops = { |
---|
| 597 | + .llseek = proc_reg_llseek, |
---|
| 598 | + .read_iter = proc_reg_read_iter, |
---|
| 599 | + .write = proc_reg_write, |
---|
| 600 | + .splice_read = generic_file_splice_read, |
---|
| 601 | + .poll = proc_reg_poll, |
---|
| 602 | + .unlocked_ioctl = proc_reg_unlocked_ioctl, |
---|
412 | 603 | .mmap = proc_reg_mmap, |
---|
413 | 604 | .get_unmapped_area = proc_reg_get_unmapped_area, |
---|
414 | 605 | .open = proc_reg_open, |
---|
.. | .. |
---|
416 | 607 | }; |
---|
417 | 608 | |
---|
418 | 609 | #ifdef CONFIG_COMPAT |
---|
419 | | -static const struct file_operations proc_reg_file_ops_no_compat = { |
---|
| 610 | +static const struct file_operations proc_reg_file_ops_compat = { |
---|
420 | 611 | .llseek = proc_reg_llseek, |
---|
421 | 612 | .read = proc_reg_read, |
---|
422 | 613 | .write = proc_reg_write, |
---|
423 | 614 | .poll = proc_reg_poll, |
---|
424 | 615 | .unlocked_ioctl = proc_reg_unlocked_ioctl, |
---|
| 616 | + .compat_ioctl = proc_reg_compat_ioctl, |
---|
| 617 | + .mmap = proc_reg_mmap, |
---|
| 618 | + .get_unmapped_area = proc_reg_get_unmapped_area, |
---|
| 619 | + .open = proc_reg_open, |
---|
| 620 | + .release = proc_reg_release, |
---|
| 621 | +}; |
---|
| 622 | + |
---|
| 623 | +static const struct file_operations proc_iter_file_ops_compat = { |
---|
| 624 | + .llseek = proc_reg_llseek, |
---|
| 625 | + .read_iter = proc_reg_read_iter, |
---|
| 626 | + .splice_read = generic_file_splice_read, |
---|
| 627 | + .write = proc_reg_write, |
---|
| 628 | + .poll = proc_reg_poll, |
---|
| 629 | + .unlocked_ioctl = proc_reg_unlocked_ioctl, |
---|
| 630 | + .compat_ioctl = proc_reg_compat_ioctl, |
---|
425 | 631 | .mmap = proc_reg_mmap, |
---|
426 | 632 | .get_unmapped_area = proc_reg_get_unmapped_area, |
---|
427 | 633 | .open = proc_reg_open, |
---|
.. | .. |
---|
453 | 659 | { |
---|
454 | 660 | struct inode *inode = new_inode(sb); |
---|
455 | 661 | |
---|
456 | | - if (inode) { |
---|
457 | | - inode->i_ino = de->low_ino; |
---|
458 | | - inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); |
---|
459 | | - PROC_I(inode)->pde = de; |
---|
| 662 | + if (!inode) { |
---|
| 663 | + pde_put(de); |
---|
| 664 | + return NULL; |
---|
| 665 | + } |
---|
460 | 666 | |
---|
461 | | - if (is_empty_pde(de)) { |
---|
462 | | - make_empty_dir_inode(inode); |
---|
463 | | - return inode; |
---|
464 | | - } |
---|
465 | | - if (de->mode) { |
---|
466 | | - inode->i_mode = de->mode; |
---|
467 | | - inode->i_uid = de->uid; |
---|
468 | | - inode->i_gid = de->gid; |
---|
469 | | - } |
---|
470 | | - if (de->size) |
---|
471 | | - inode->i_size = de->size; |
---|
472 | | - if (de->nlink) |
---|
473 | | - set_nlink(inode, de->nlink); |
---|
474 | | - WARN_ON(!de->proc_iops); |
---|
| 667 | + inode->i_ino = de->low_ino; |
---|
| 668 | + inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); |
---|
| 669 | + PROC_I(inode)->pde = de; |
---|
| 670 | + if (is_empty_pde(de)) { |
---|
| 671 | + make_empty_dir_inode(inode); |
---|
| 672 | + return inode; |
---|
| 673 | + } |
---|
| 674 | + |
---|
| 675 | + if (de->mode) { |
---|
| 676 | + inode->i_mode = de->mode; |
---|
| 677 | + inode->i_uid = de->uid; |
---|
| 678 | + inode->i_gid = de->gid; |
---|
| 679 | + } |
---|
| 680 | + if (de->size) |
---|
| 681 | + inode->i_size = de->size; |
---|
| 682 | + if (de->nlink) |
---|
| 683 | + set_nlink(inode, de->nlink); |
---|
| 684 | + |
---|
| 685 | + if (S_ISREG(inode->i_mode)) { |
---|
475 | 686 | inode->i_op = de->proc_iops; |
---|
476 | | - if (de->proc_fops) { |
---|
477 | | - if (S_ISREG(inode->i_mode)) { |
---|
| 687 | + if (de->proc_ops->proc_read_iter) |
---|
| 688 | + inode->i_fop = &proc_iter_file_ops; |
---|
| 689 | + else |
---|
| 690 | + inode->i_fop = &proc_reg_file_ops; |
---|
478 | 691 | #ifdef CONFIG_COMPAT |
---|
479 | | - if (!de->proc_fops->compat_ioctl) |
---|
480 | | - inode->i_fop = |
---|
481 | | - &proc_reg_file_ops_no_compat; |
---|
482 | | - else |
---|
483 | | -#endif |
---|
484 | | - inode->i_fop = &proc_reg_file_ops; |
---|
485 | | - } else { |
---|
486 | | - inode->i_fop = de->proc_fops; |
---|
487 | | - } |
---|
| 692 | + if (de->proc_ops->proc_compat_ioctl) { |
---|
| 693 | + if (de->proc_ops->proc_read_iter) |
---|
| 694 | + inode->i_fop = &proc_iter_file_ops_compat; |
---|
| 695 | + else |
---|
| 696 | + inode->i_fop = &proc_reg_file_ops_compat; |
---|
488 | 697 | } |
---|
489 | | - } else |
---|
490 | | - pde_put(de); |
---|
| 698 | +#endif |
---|
| 699 | + } else if (S_ISDIR(inode->i_mode)) { |
---|
| 700 | + inode->i_op = de->proc_iops; |
---|
| 701 | + inode->i_fop = de->proc_dir_ops; |
---|
| 702 | + } else if (S_ISLNK(inode->i_mode)) { |
---|
| 703 | + inode->i_op = de->proc_iops; |
---|
| 704 | + inode->i_fop = NULL; |
---|
| 705 | + } else { |
---|
| 706 | + BUG(); |
---|
| 707 | + } |
---|
491 | 708 | return inode; |
---|
492 | | -} |
---|
493 | | - |
---|
494 | | -int proc_fill_super(struct super_block *s) |
---|
495 | | -{ |
---|
496 | | - struct inode *root_inode; |
---|
497 | | - int ret; |
---|
498 | | - |
---|
499 | | - /* User space would break if executables or devices appear on proc */ |
---|
500 | | - s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NODEV; |
---|
501 | | - s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC; |
---|
502 | | - s->s_blocksize = 1024; |
---|
503 | | - s->s_blocksize_bits = 10; |
---|
504 | | - s->s_magic = PROC_SUPER_MAGIC; |
---|
505 | | - s->s_op = &proc_sops; |
---|
506 | | - s->s_time_gran = 1; |
---|
507 | | - |
---|
508 | | - /* |
---|
509 | | - * procfs isn't actually a stacking filesystem; however, there is |
---|
510 | | - * too much magic going on inside it to permit stacking things on |
---|
511 | | - * top of it |
---|
512 | | - */ |
---|
513 | | - s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH; |
---|
514 | | - |
---|
515 | | - pde_get(&proc_root); |
---|
516 | | - root_inode = proc_get_inode(s, &proc_root); |
---|
517 | | - if (!root_inode) { |
---|
518 | | - pr_err("proc_fill_super: get root inode failed\n"); |
---|
519 | | - return -ENOMEM; |
---|
520 | | - } |
---|
521 | | - |
---|
522 | | - s->s_root = d_make_root(root_inode); |
---|
523 | | - if (!s->s_root) { |
---|
524 | | - pr_err("proc_fill_super: allocate dentry failed\n"); |
---|
525 | | - return -ENOMEM; |
---|
526 | | - } |
---|
527 | | - |
---|
528 | | - ret = proc_setup_self(s); |
---|
529 | | - if (ret) { |
---|
530 | | - return ret; |
---|
531 | | - } |
---|
532 | | - return proc_setup_thread_self(s); |
---|
533 | 709 | } |
---|