diff options
Diffstat (limited to 'fs/proc')
| -rw-r--r-- | fs/proc/array.c | 9 | ||||
| -rw-r--r-- | fs/proc/base.c | 105 | ||||
| -rw-r--r-- | fs/proc/generic.c | 5 | ||||
| -rw-r--r-- | fs/proc/inode.c | 7 | ||||
| -rw-r--r-- | fs/proc/proc_sysctl.c | 429 |
5 files changed, 256 insertions, 299 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c index 797d775e0354..0d6eb33597c6 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
| @@ -80,6 +80,7 @@ | |||
| 80 | #include <linux/delayacct.h> | 80 | #include <linux/delayacct.h> |
| 81 | #include <linux/seq_file.h> | 81 | #include <linux/seq_file.h> |
| 82 | #include <linux/pid_namespace.h> | 82 | #include <linux/pid_namespace.h> |
| 83 | #include <linux/tracehook.h> | ||
| 83 | 84 | ||
| 84 | #include <asm/pgtable.h> | 85 | #include <asm/pgtable.h> |
| 85 | #include <asm/processor.h> | 86 | #include <asm/processor.h> |
| @@ -168,8 +169,12 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, | |||
| 168 | rcu_read_lock(); | 169 | rcu_read_lock(); |
| 169 | ppid = pid_alive(p) ? | 170 | ppid = pid_alive(p) ? |
| 170 | task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0; | 171 | task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0; |
| 171 | tpid = pid_alive(p) && p->ptrace ? | 172 | tpid = 0; |
| 172 | task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0; | 173 | if (pid_alive(p)) { |
| 174 | struct task_struct *tracer = tracehook_tracer_task(p); | ||
| 175 | if (tracer) | ||
| 176 | tpid = task_pid_nr_ns(tracer, ns); | ||
| 177 | } | ||
| 173 | seq_printf(m, | 178 | seq_printf(m, |
| 174 | "State:\t%s\n" | 179 | "State:\t%s\n" |
| 175 | "Tgid:\t%d\n" | 180 | "Tgid:\t%d\n" |
diff --git a/fs/proc/base.c b/fs/proc/base.c index a891fe4cb43b..01ed610f9b87 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | #include <linux/time.h> | 53 | #include <linux/time.h> |
| 54 | #include <linux/proc_fs.h> | 54 | #include <linux/proc_fs.h> |
| 55 | #include <linux/stat.h> | 55 | #include <linux/stat.h> |
| 56 | #include <linux/task_io_accounting_ops.h> | ||
| 56 | #include <linux/init.h> | 57 | #include <linux/init.h> |
| 57 | #include <linux/capability.h> | 58 | #include <linux/capability.h> |
| 58 | #include <linux/file.h> | 59 | #include <linux/file.h> |
| @@ -69,6 +70,7 @@ | |||
| 69 | #include <linux/mount.h> | 70 | #include <linux/mount.h> |
| 70 | #include <linux/security.h> | 71 | #include <linux/security.h> |
| 71 | #include <linux/ptrace.h> | 72 | #include <linux/ptrace.h> |
| 73 | #include <linux/tracehook.h> | ||
| 72 | #include <linux/cgroup.h> | 74 | #include <linux/cgroup.h> |
| 73 | #include <linux/cpuset.h> | 75 | #include <linux/cpuset.h> |
| 74 | #include <linux/audit.h> | 76 | #include <linux/audit.h> |
| @@ -231,10 +233,14 @@ static int check_mem_permission(struct task_struct *task) | |||
| 231 | * If current is actively ptrace'ing, and would also be | 233 | * If current is actively ptrace'ing, and would also be |
| 232 | * permitted to freshly attach with ptrace now, permit it. | 234 | * permitted to freshly attach with ptrace now, permit it. |
| 233 | */ | 235 | */ |
| 234 | if (task->parent == current && (task->ptrace & PT_PTRACED) && | 236 | if (task_is_stopped_or_traced(task)) { |
| 235 | task_is_stopped_or_traced(task) && | 237 | int match; |
| 236 | ptrace_may_access(task, PTRACE_MODE_ATTACH)) | 238 | rcu_read_lock(); |
| 237 | return 0; | 239 | match = (tracehook_tracer_task(task) == current); |
| 240 | rcu_read_unlock(); | ||
| 241 | if (match && ptrace_may_access(task, PTRACE_MODE_ATTACH)) | ||
| 242 | return 0; | ||
| 243 | } | ||
| 238 | 244 | ||
| 239 | /* | 245 | /* |
| 240 | * Noone else is allowed. | 246 | * Noone else is allowed. |
| @@ -504,6 +510,26 @@ static int proc_pid_limits(struct task_struct *task, char *buffer) | |||
| 504 | return count; | 510 | return count; |
| 505 | } | 511 | } |
| 506 | 512 | ||
| 513 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK | ||
| 514 | static int proc_pid_syscall(struct task_struct *task, char *buffer) | ||
| 515 | { | ||
| 516 | long nr; | ||
| 517 | unsigned long args[6], sp, pc; | ||
| 518 | |||
| 519 | if (task_current_syscall(task, &nr, args, 6, &sp, &pc)) | ||
| 520 | return sprintf(buffer, "running\n"); | ||
| 521 | |||
| 522 | if (nr < 0) | ||
| 523 | return sprintf(buffer, "%ld 0x%lx 0x%lx\n", nr, sp, pc); | ||
| 524 | |||
| 525 | return sprintf(buffer, | ||
| 526 | "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", | ||
| 527 | nr, | ||
| 528 | args[0], args[1], args[2], args[3], args[4], args[5], | ||
| 529 | sp, pc); | ||
| 530 | } | ||
| 531 | #endif /* CONFIG_HAVE_ARCH_TRACEHOOK */ | ||
| 532 | |||
| 507 | /************************************************************************/ | 533 | /************************************************************************/ |
| 508 | /* Here the fs part begins */ | 534 | /* Here the fs part begins */ |
| 509 | /************************************************************************/ | 535 | /************************************************************************/ |
| @@ -1834,8 +1860,7 @@ static const struct file_operations proc_fd_operations = { | |||
| 1834 | * /proc/pid/fd needs a special permission handler so that a process can still | 1860 | * /proc/pid/fd needs a special permission handler so that a process can still |
| 1835 | * access /proc/self/fd after it has executed a setuid(). | 1861 | * access /proc/self/fd after it has executed a setuid(). |
| 1836 | */ | 1862 | */ |
| 1837 | static int proc_fd_permission(struct inode *inode, int mask, | 1863 | static int proc_fd_permission(struct inode *inode, int mask) |
| 1838 | struct nameidata *nd) | ||
| 1839 | { | 1864 | { |
| 1840 | int rv; | 1865 | int rv; |
| 1841 | 1866 | ||
| @@ -2378,53 +2403,18 @@ static int proc_base_fill_cache(struct file *filp, void *dirent, | |||
| 2378 | #ifdef CONFIG_TASK_IO_ACCOUNTING | 2403 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
| 2379 | static int do_io_accounting(struct task_struct *task, char *buffer, int whole) | 2404 | static int do_io_accounting(struct task_struct *task, char *buffer, int whole) |
| 2380 | { | 2405 | { |
| 2381 | u64 rchar, wchar, syscr, syscw; | 2406 | struct task_io_accounting acct = task->ioac; |
| 2382 | struct task_io_accounting ioac; | 2407 | unsigned long flags; |
| 2383 | |||
| 2384 | if (!whole) { | ||
| 2385 | rchar = task->rchar; | ||
| 2386 | wchar = task->wchar; | ||
| 2387 | syscr = task->syscr; | ||
| 2388 | syscw = task->syscw; | ||
| 2389 | memcpy(&ioac, &task->ioac, sizeof(ioac)); | ||
| 2390 | } else { | ||
| 2391 | unsigned long flags; | ||
| 2392 | struct task_struct *t = task; | ||
| 2393 | rchar = wchar = syscr = syscw = 0; | ||
| 2394 | memset(&ioac, 0, sizeof(ioac)); | ||
| 2395 | |||
| 2396 | rcu_read_lock(); | ||
| 2397 | do { | ||
| 2398 | rchar += t->rchar; | ||
| 2399 | wchar += t->wchar; | ||
| 2400 | syscr += t->syscr; | ||
| 2401 | syscw += t->syscw; | ||
| 2402 | |||
| 2403 | ioac.read_bytes += t->ioac.read_bytes; | ||
| 2404 | ioac.write_bytes += t->ioac.write_bytes; | ||
| 2405 | ioac.cancelled_write_bytes += | ||
| 2406 | t->ioac.cancelled_write_bytes; | ||
| 2407 | t = next_thread(t); | ||
| 2408 | } while (t != task); | ||
| 2409 | rcu_read_unlock(); | ||
| 2410 | |||
| 2411 | if (lock_task_sighand(task, &flags)) { | ||
| 2412 | struct signal_struct *sig = task->signal; | ||
| 2413 | 2408 | ||
| 2414 | rchar += sig->rchar; | 2409 | if (whole && lock_task_sighand(task, &flags)) { |
| 2415 | wchar += sig->wchar; | 2410 | struct task_struct *t = task; |
| 2416 | syscr += sig->syscr; | ||
| 2417 | syscw += sig->syscw; | ||
| 2418 | 2411 | ||
| 2419 | ioac.read_bytes += sig->ioac.read_bytes; | 2412 | task_io_accounting_add(&acct, &task->signal->ioac); |
| 2420 | ioac.write_bytes += sig->ioac.write_bytes; | 2413 | while_each_thread(task, t) |
| 2421 | ioac.cancelled_write_bytes += | 2414 | task_io_accounting_add(&acct, &t->ioac); |
| 2422 | sig->ioac.cancelled_write_bytes; | ||
| 2423 | 2415 | ||
| 2424 | unlock_task_sighand(task, &flags); | 2416 | unlock_task_sighand(task, &flags); |
| 2425 | } | ||
| 2426 | } | 2417 | } |
| 2427 | |||
| 2428 | return sprintf(buffer, | 2418 | return sprintf(buffer, |
| 2429 | "rchar: %llu\n" | 2419 | "rchar: %llu\n" |
| 2430 | "wchar: %llu\n" | 2420 | "wchar: %llu\n" |
| @@ -2433,13 +2423,10 @@ static int do_io_accounting(struct task_struct *task, char *buffer, int whole) | |||
| 2433 | "read_bytes: %llu\n" | 2423 | "read_bytes: %llu\n" |
| 2434 | "write_bytes: %llu\n" | 2424 | "write_bytes: %llu\n" |
| 2435 | "cancelled_write_bytes: %llu\n", | 2425 | "cancelled_write_bytes: %llu\n", |
| 2436 | (unsigned long long)rchar, | 2426 | acct.rchar, acct.wchar, |
| 2437 | (unsigned long long)wchar, | 2427 | acct.syscr, acct.syscw, |
| 2438 | (unsigned long long)syscr, | 2428 | acct.read_bytes, acct.write_bytes, |
| 2439 | (unsigned long long)syscw, | 2429 | acct.cancelled_write_bytes); |
| 2440 | (unsigned long long)ioac.read_bytes, | ||
| 2441 | (unsigned long long)ioac.write_bytes, | ||
| 2442 | (unsigned long long)ioac.cancelled_write_bytes); | ||
| 2443 | } | 2430 | } |
| 2444 | 2431 | ||
| 2445 | static int proc_tid_io_accounting(struct task_struct *task, char *buffer) | 2432 | static int proc_tid_io_accounting(struct task_struct *task, char *buffer) |
| @@ -2473,6 +2460,9 @@ static const struct pid_entry tgid_base_stuff[] = { | |||
| 2473 | #ifdef CONFIG_SCHED_DEBUG | 2460 | #ifdef CONFIG_SCHED_DEBUG |
| 2474 | REG("sched", S_IRUGO|S_IWUSR, pid_sched), | 2461 | REG("sched", S_IRUGO|S_IWUSR, pid_sched), |
| 2475 | #endif | 2462 | #endif |
| 2463 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK | ||
| 2464 | INF("syscall", S_IRUSR, pid_syscall), | ||
| 2465 | #endif | ||
| 2476 | INF("cmdline", S_IRUGO, pid_cmdline), | 2466 | INF("cmdline", S_IRUGO, pid_cmdline), |
| 2477 | ONE("stat", S_IRUGO, tgid_stat), | 2467 | ONE("stat", S_IRUGO, tgid_stat), |
| 2478 | ONE("statm", S_IRUGO, pid_statm), | 2468 | ONE("statm", S_IRUGO, pid_statm), |
| @@ -2805,6 +2795,9 @@ static const struct pid_entry tid_base_stuff[] = { | |||
| 2805 | #ifdef CONFIG_SCHED_DEBUG | 2795 | #ifdef CONFIG_SCHED_DEBUG |
| 2806 | REG("sched", S_IRUGO|S_IWUSR, pid_sched), | 2796 | REG("sched", S_IRUGO|S_IWUSR, pid_sched), |
| 2807 | #endif | 2797 | #endif |
| 2798 | #ifdef CONFIG_HAVE_ARCH_TRACEHOOK | ||
| 2799 | INF("syscall", S_IRUSR, pid_syscall), | ||
| 2800 | #endif | ||
| 2808 | INF("cmdline", S_IRUGO, pid_cmdline), | 2801 | INF("cmdline", S_IRUGO, pid_cmdline), |
| 2809 | ONE("stat", S_IRUGO, tid_stat), | 2802 | ONE("stat", S_IRUGO, tid_stat), |
| 2810 | ONE("statm", S_IRUGO, pid_statm), | 2803 | ONE("statm", S_IRUGO, pid_statm), |
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index bc0a0dd2d844..cb4096cc3fb7 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
| @@ -806,12 +806,9 @@ continue_removing: | |||
| 806 | if (S_ISDIR(de->mode)) | 806 | if (S_ISDIR(de->mode)) |
| 807 | parent->nlink--; | 807 | parent->nlink--; |
| 808 | de->nlink = 0; | 808 | de->nlink = 0; |
| 809 | if (de->subdir) { | 809 | WARN(de->subdir, KERN_WARNING "%s: removing non-empty directory " |
| 810 | printk(KERN_WARNING "%s: removing non-empty directory " | ||
| 811 | "'%s/%s', leaking at least '%s'\n", __func__, | 810 | "'%s/%s', leaking at least '%s'\n", __func__, |
| 812 | de->parent->name, de->name, de->subdir->name); | 811 | de->parent->name, de->name, de->subdir->name); |
| 813 | WARN_ON(1); | ||
| 814 | } | ||
| 815 | if (atomic_dec_and_test(&de->count)) | 812 | if (atomic_dec_and_test(&de->count)) |
| 816 | free_proc_entry(de); | 813 | free_proc_entry(de); |
| 817 | } | 814 | } |
diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 02eca2ed9dd7..8bb03f056c28 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
| 19 | #include <linux/smp_lock.h> | 19 | #include <linux/smp_lock.h> |
| 20 | #include <linux/sysctl.h> | ||
| 20 | 21 | ||
| 21 | #include <asm/system.h> | 22 | #include <asm/system.h> |
| 22 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
| @@ -65,6 +66,8 @@ static void proc_delete_inode(struct inode *inode) | |||
| 65 | module_put(de->owner); | 66 | module_put(de->owner); |
| 66 | de_put(de); | 67 | de_put(de); |
| 67 | } | 68 | } |
| 69 | if (PROC_I(inode)->sysctl) | ||
| 70 | sysctl_head_put(PROC_I(inode)->sysctl); | ||
| 68 | clear_inode(inode); | 71 | clear_inode(inode); |
| 69 | } | 72 | } |
| 70 | 73 | ||
| @@ -84,6 +87,8 @@ static struct inode *proc_alloc_inode(struct super_block *sb) | |||
| 84 | ei->fd = 0; | 87 | ei->fd = 0; |
| 85 | ei->op.proc_get_link = NULL; | 88 | ei->op.proc_get_link = NULL; |
| 86 | ei->pde = NULL; | 89 | ei->pde = NULL; |
| 90 | ei->sysctl = NULL; | ||
| 91 | ei->sysctl_entry = NULL; | ||
| 87 | inode = &ei->vfs_inode; | 92 | inode = &ei->vfs_inode; |
| 88 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 93 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 89 | return inode; | 94 | return inode; |
| @@ -94,7 +99,7 @@ static void proc_destroy_inode(struct inode *inode) | |||
| 94 | kmem_cache_free(proc_inode_cachep, PROC_I(inode)); | 99 | kmem_cache_free(proc_inode_cachep, PROC_I(inode)); |
| 95 | } | 100 | } |
| 96 | 101 | ||
| 97 | static void init_once(struct kmem_cache * cachep, void *foo) | 102 | static void init_once(void *foo) |
| 98 | { | 103 | { |
| 99 | struct proc_inode *ei = (struct proc_inode *) foo; | 104 | struct proc_inode *ei = (struct proc_inode *) foo; |
| 100 | 105 | ||
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5acc001d49f6..f9a8b892718f 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c | |||
| @@ -10,149 +10,110 @@ | |||
| 10 | static struct dentry_operations proc_sys_dentry_operations; | 10 | static struct dentry_operations proc_sys_dentry_operations; |
| 11 | static const struct file_operations proc_sys_file_operations; | 11 | static const struct file_operations proc_sys_file_operations; |
| 12 | static const struct inode_operations proc_sys_inode_operations; | 12 | static const struct inode_operations proc_sys_inode_operations; |
| 13 | static const struct file_operations proc_sys_dir_file_operations; | ||
| 14 | static const struct inode_operations proc_sys_dir_operations; | ||
| 13 | 15 | ||
| 14 | static void proc_sys_refresh_inode(struct inode *inode, struct ctl_table *table) | 16 | static struct inode *proc_sys_make_inode(struct super_block *sb, |
| 15 | { | 17 | struct ctl_table_header *head, struct ctl_table *table) |
| 16 | /* Refresh the cached information bits in the inode */ | ||
| 17 | if (table) { | ||
| 18 | inode->i_uid = 0; | ||
| 19 | inode->i_gid = 0; | ||
| 20 | inode->i_mode = table->mode; | ||
| 21 | if (table->proc_handler) { | ||
| 22 | inode->i_mode |= S_IFREG; | ||
| 23 | inode->i_nlink = 1; | ||
| 24 | } else { | ||
| 25 | inode->i_mode |= S_IFDIR; | ||
| 26 | inode->i_nlink = 0; /* It is too hard to figure out */ | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | static struct inode *proc_sys_make_inode(struct inode *dir, struct ctl_table *table) | ||
| 32 | { | 18 | { |
| 33 | struct inode *inode; | 19 | struct inode *inode; |
| 34 | struct proc_inode *dir_ei, *ei; | 20 | struct proc_inode *ei; |
| 35 | int depth; | ||
| 36 | 21 | ||
| 37 | inode = new_inode(dir->i_sb); | 22 | inode = new_inode(sb); |
| 38 | if (!inode) | 23 | if (!inode) |
| 39 | goto out; | 24 | goto out; |
| 40 | 25 | ||
| 41 | /* A directory is always one deeper than it's parent */ | 26 | sysctl_head_get(head); |
| 42 | dir_ei = PROC_I(dir); | ||
| 43 | depth = dir_ei->fd + 1; | ||
| 44 | |||
| 45 | ei = PROC_I(inode); | 27 | ei = PROC_I(inode); |
| 46 | ei->fd = depth; | 28 | ei->sysctl = head; |
| 29 | ei->sysctl_entry = table; | ||
| 30 | |||
| 47 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 31 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 48 | inode->i_op = &proc_sys_inode_operations; | ||
| 49 | inode->i_fop = &proc_sys_file_operations; | ||
| 50 | inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */ | 32 | inode->i_flags |= S_PRIVATE; /* tell selinux to ignore this inode */ |
| 51 | proc_sys_refresh_inode(inode, table); | 33 | inode->i_mode = table->mode; |
| 34 | if (!table->child) { | ||
| 35 | inode->i_mode |= S_IFREG; | ||
| 36 | inode->i_op = &proc_sys_inode_operations; | ||
| 37 | inode->i_fop = &proc_sys_file_operations; | ||
| 38 | } else { | ||
| 39 | inode->i_mode |= S_IFDIR; | ||
| 40 | inode->i_nlink = 0; | ||
| 41 | inode->i_op = &proc_sys_dir_operations; | ||
| 42 | inode->i_fop = &proc_sys_dir_file_operations; | ||
| 43 | } | ||
| 52 | out: | 44 | out: |
| 53 | return inode; | 45 | return inode; |
| 54 | } | 46 | } |
| 55 | 47 | ||
| 56 | static struct dentry *proc_sys_ancestor(struct dentry *dentry, int depth) | 48 | static struct ctl_table *find_in_table(struct ctl_table *p, struct qstr *name) |
| 57 | { | ||
| 58 | for (;;) { | ||
| 59 | struct proc_inode *ei; | ||
| 60 | |||
| 61 | ei = PROC_I(dentry->d_inode); | ||
| 62 | if (ei->fd == depth) | ||
| 63 | break; /* found */ | ||
| 64 | |||
| 65 | dentry = dentry->d_parent; | ||
| 66 | } | ||
| 67 | return dentry; | ||
| 68 | } | ||
| 69 | |||
| 70 | static struct ctl_table *proc_sys_lookup_table_one(struct ctl_table *table, | ||
| 71 | struct qstr *name) | ||
| 72 | { | 49 | { |
| 73 | int len; | 50 | int len; |
| 74 | for ( ; table->ctl_name || table->procname; table++) { | 51 | for ( ; p->ctl_name || p->procname; p++) { |
| 75 | 52 | ||
| 76 | if (!table->procname) | 53 | if (!p->procname) |
| 77 | continue; | 54 | continue; |
| 78 | 55 | ||
| 79 | len = strlen(table->procname); | 56 | len = strlen(p->procname); |
| 80 | if (len != name->len) | 57 | if (len != name->len) |
| 81 | continue; | 58 | continue; |
| 82 | 59 | ||
| 83 | if (memcmp(table->procname, name->name, len) != 0) | 60 | if (memcmp(p->procname, name->name, len) != 0) |
| 84 | continue; | 61 | continue; |
| 85 | 62 | ||
| 86 | /* I have a match */ | 63 | /* I have a match */ |
| 87 | return table; | 64 | return p; |
| 88 | } | 65 | } |
| 89 | return NULL; | 66 | return NULL; |
| 90 | } | 67 | } |
| 91 | 68 | ||
| 92 | static struct ctl_table *proc_sys_lookup_table(struct dentry *dentry, | 69 | struct ctl_table_header *grab_header(struct inode *inode) |
| 93 | struct ctl_table *table) | ||
| 94 | { | 70 | { |
| 95 | struct dentry *ancestor; | 71 | if (PROC_I(inode)->sysctl) |
| 96 | struct proc_inode *ei; | 72 | return sysctl_head_grab(PROC_I(inode)->sysctl); |
| 97 | int depth, i; | 73 | else |
| 74 | return sysctl_head_next(NULL); | ||
| 75 | } | ||
| 98 | 76 | ||
| 99 | ei = PROC_I(dentry->d_inode); | 77 | static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, |
| 100 | depth = ei->fd; | 78 | struct nameidata *nd) |
| 79 | { | ||
| 80 | struct ctl_table_header *head = grab_header(dir); | ||
| 81 | struct ctl_table *table = PROC_I(dir)->sysctl_entry; | ||
| 82 | struct ctl_table_header *h = NULL; | ||
| 83 | struct qstr *name = &dentry->d_name; | ||
| 84 | struct ctl_table *p; | ||
| 85 | struct inode *inode; | ||
| 86 | struct dentry *err = ERR_PTR(-ENOENT); | ||
| 101 | 87 | ||
| 102 | if (depth == 0) | 88 | if (IS_ERR(head)) |
| 103 | return table; | 89 | return ERR_CAST(head); |
| 104 | 90 | ||
| 105 | for (i = 1; table && (i <= depth); i++) { | 91 | if (table && !table->child) { |
| 106 | ancestor = proc_sys_ancestor(dentry, i); | 92 | WARN_ON(1); |
| 107 | table = proc_sys_lookup_table_one(table, &ancestor->d_name); | 93 | goto out; |
| 108 | if (table) | ||
| 109 | table = table->child; | ||
| 110 | } | 94 | } |
| 111 | return table; | ||
| 112 | |||
| 113 | } | ||
| 114 | static struct ctl_table *proc_sys_lookup_entry(struct dentry *dparent, | ||
| 115 | struct qstr *name, | ||
| 116 | struct ctl_table *table) | ||
| 117 | { | ||
| 118 | table = proc_sys_lookup_table(dparent, table); | ||
| 119 | if (table) | ||
| 120 | table = proc_sys_lookup_table_one(table, name); | ||
| 121 | return table; | ||
| 122 | } | ||
| 123 | 95 | ||
| 124 | static struct ctl_table *do_proc_sys_lookup(struct dentry *parent, | 96 | table = table ? table->child : head->ctl_table; |
| 125 | struct qstr *name, | ||
| 126 | struct ctl_table_header **ptr) | ||
| 127 | { | ||
| 128 | struct ctl_table_header *head; | ||
| 129 | struct ctl_table *table = NULL; | ||
| 130 | 97 | ||
| 131 | for (head = sysctl_head_next(NULL); head; | 98 | p = find_in_table(table, name); |
| 132 | head = sysctl_head_next(head)) { | 99 | if (!p) { |
| 133 | table = proc_sys_lookup_entry(parent, name, head->ctl_table); | 100 | for (h = sysctl_head_next(NULL); h; h = sysctl_head_next(h)) { |
| 134 | if (table) | 101 | if (h->attached_to != table) |
| 135 | break; | 102 | continue; |
| 103 | p = find_in_table(h->attached_by, name); | ||
| 104 | if (p) | ||
| 105 | break; | ||
| 106 | } | ||
| 136 | } | 107 | } |
| 137 | *ptr = head; | ||
| 138 | return table; | ||
| 139 | } | ||
| 140 | |||
| 141 | static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, | ||
| 142 | struct nameidata *nd) | ||
| 143 | { | ||
| 144 | struct ctl_table_header *head; | ||
| 145 | struct inode *inode; | ||
| 146 | struct dentry *err; | ||
| 147 | struct ctl_table *table; | ||
| 148 | 108 | ||
| 149 | err = ERR_PTR(-ENOENT); | 109 | if (!p) |
| 150 | table = do_proc_sys_lookup(dentry->d_parent, &dentry->d_name, &head); | ||
| 151 | if (!table) | ||
| 152 | goto out; | 110 | goto out; |
| 153 | 111 | ||
| 154 | err = ERR_PTR(-ENOMEM); | 112 | err = ERR_PTR(-ENOMEM); |
| 155 | inode = proc_sys_make_inode(dir, table); | 113 | inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); |
| 114 | if (h) | ||
| 115 | sysctl_head_finish(h); | ||
| 116 | |||
| 156 | if (!inode) | 117 | if (!inode) |
| 157 | goto out; | 118 | goto out; |
| 158 | 119 | ||
| @@ -168,22 +129,14 @@ out: | |||
| 168 | static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf, | 129 | static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf, |
| 169 | size_t count, loff_t *ppos, int write) | 130 | size_t count, loff_t *ppos, int write) |
| 170 | { | 131 | { |
| 171 | struct dentry *dentry = filp->f_dentry; | 132 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 172 | struct ctl_table_header *head; | 133 | struct ctl_table_header *head = grab_header(inode); |
| 173 | struct ctl_table *table; | 134 | struct ctl_table *table = PROC_I(inode)->sysctl_entry; |
| 174 | ssize_t error; | 135 | ssize_t error; |
| 175 | size_t res; | 136 | size_t res; |
| 176 | 137 | ||
| 177 | table = do_proc_sys_lookup(dentry->d_parent, &dentry->d_name, &head); | 138 | if (IS_ERR(head)) |
| 178 | /* Has the sysctl entry disappeared on us? */ | 139 | return PTR_ERR(head); |
| 179 | error = -ENOENT; | ||
| 180 | if (!table) | ||
| 181 | goto out; | ||
| 182 | |||
| 183 | /* Has the sysctl entry been replaced by a directory? */ | ||
| 184 | error = -EISDIR; | ||
| 185 | if (!table->proc_handler) | ||
| 186 | goto out; | ||
| 187 | 140 | ||
| 188 | /* | 141 | /* |
| 189 | * At this point we know that the sysctl was not unregistered | 142 | * At this point we know that the sysctl was not unregistered |
| @@ -193,6 +146,11 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf, | |||
| 193 | if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ)) | 146 | if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ)) |
| 194 | goto out; | 147 | goto out; |
| 195 | 148 | ||
| 149 | /* if that can happen at all, it should be -EINVAL, not -EISDIR */ | ||
| 150 | error = -EINVAL; | ||
| 151 | if (!table->proc_handler) | ||
| 152 | goto out; | ||
| 153 | |||
| 196 | /* careful: calling conventions are nasty here */ | 154 | /* careful: calling conventions are nasty here */ |
| 197 | res = count; | 155 | res = count; |
| 198 | error = table->proc_handler(table, write, filp, buf, &res, ppos); | 156 | error = table->proc_handler(table, write, filp, buf, &res, ppos); |
| @@ -218,82 +176,86 @@ static ssize_t proc_sys_write(struct file *filp, const char __user *buf, | |||
| 218 | 176 | ||
| 219 | 177 | ||
| 220 | static int proc_sys_fill_cache(struct file *filp, void *dirent, | 178 | static int proc_sys_fill_cache(struct file *filp, void *dirent, |
| 221 | filldir_t filldir, struct ctl_table *table) | 179 | filldir_t filldir, |
| 180 | struct ctl_table_header *head, | ||
| 181 | struct ctl_table *table) | ||
| 222 | { | 182 | { |
| 223 | struct ctl_table_header *head; | ||
| 224 | struct ctl_table *child_table = NULL; | ||
| 225 | struct dentry *child, *dir = filp->f_path.dentry; | 183 | struct dentry *child, *dir = filp->f_path.dentry; |
| 226 | struct inode *inode; | 184 | struct inode *inode; |
| 227 | struct qstr qname; | 185 | struct qstr qname; |
| 228 | ino_t ino = 0; | 186 | ino_t ino = 0; |
| 229 | unsigned type = DT_UNKNOWN; | 187 | unsigned type = DT_UNKNOWN; |
| 230 | int ret; | ||
| 231 | 188 | ||
| 232 | qname.name = table->procname; | 189 | qname.name = table->procname; |
| 233 | qname.len = strlen(table->procname); | 190 | qname.len = strlen(table->procname); |
| 234 | qname.hash = full_name_hash(qname.name, qname.len); | 191 | qname.hash = full_name_hash(qname.name, qname.len); |
| 235 | 192 | ||
| 236 | /* Suppress duplicates. | ||
| 237 | * Only fill a directory entry if it is the value that | ||
| 238 | * an ordinary lookup of that name returns. Hide all | ||
| 239 | * others. | ||
| 240 | * | ||
| 241 | * If we ever cache this translation in the dcache | ||
| 242 | * I should do a dcache lookup first. But for now | ||
| 243 | * it is just simpler not to. | ||
| 244 | */ | ||
| 245 | ret = 0; | ||
| 246 | child_table = do_proc_sys_lookup(dir, &qname, &head); | ||
| 247 | sysctl_head_finish(head); | ||
| 248 | if (child_table != table) | ||
| 249 | return 0; | ||
| 250 | |||
| 251 | child = d_lookup(dir, &qname); | 193 | child = d_lookup(dir, &qname); |
| 252 | if (!child) { | 194 | if (!child) { |
| 253 | struct dentry *new; | 195 | child = d_alloc(dir, &qname); |
| 254 | new = d_alloc(dir, &qname); | 196 | if (child) { |
| 255 | if (new) { | 197 | inode = proc_sys_make_inode(dir->d_sb, head, table); |
| 256 | inode = proc_sys_make_inode(dir->d_inode, table); | 198 | if (!inode) { |
| 257 | if (!inode) | 199 | dput(child); |
| 258 | child = ERR_PTR(-ENOMEM); | 200 | return -ENOMEM; |
| 259 | else { | 201 | } else { |
| 260 | new->d_op = &proc_sys_dentry_operations; | 202 | child->d_op = &proc_sys_dentry_operations; |
| 261 | d_add(new, inode); | 203 | d_add(child, inode); |
| 262 | } | 204 | } |
| 263 | if (child) | 205 | } else { |
| 264 | dput(new); | 206 | return -ENOMEM; |
| 265 | else | ||
| 266 | child = new; | ||
| 267 | } | 207 | } |
| 268 | } | 208 | } |
| 269 | if (!child || IS_ERR(child) || !child->d_inode) | ||
| 270 | goto end_instantiate; | ||
| 271 | inode = child->d_inode; | 209 | inode = child->d_inode; |
| 272 | if (inode) { | 210 | ino = inode->i_ino; |
| 273 | ino = inode->i_ino; | 211 | type = inode->i_mode >> 12; |
| 274 | type = inode->i_mode >> 12; | ||
| 275 | } | ||
| 276 | dput(child); | 212 | dput(child); |
| 277 | end_instantiate: | 213 | return !!filldir(dirent, qname.name, qname.len, filp->f_pos, ino, type); |
| 278 | if (!ino) | 214 | } |
| 279 | ino= find_inode_number(dir, &qname); | 215 | |
| 280 | if (!ino) | 216 | static int scan(struct ctl_table_header *head, ctl_table *table, |
| 281 | ino = 1; | 217 | unsigned long *pos, struct file *file, |
| 282 | return filldir(dirent, qname.name, qname.len, filp->f_pos, ino, type); | 218 | void *dirent, filldir_t filldir) |
| 219 | { | ||
| 220 | |||
| 221 | for (; table->ctl_name || table->procname; table++, (*pos)++) { | ||
| 222 | int res; | ||
| 223 | |||
| 224 | /* Can't do anything without a proc name */ | ||
| 225 | if (!table->procname) | ||
| 226 | continue; | ||
| 227 | |||
| 228 | if (*pos < file->f_pos) | ||
| 229 | continue; | ||
| 230 | |||
| 231 | res = proc_sys_fill_cache(file, dirent, filldir, head, table); | ||
| 232 | if (res) | ||
| 233 | return res; | ||
| 234 | |||
| 235 | file->f_pos = *pos + 1; | ||
| 236 | } | ||
| 237 | return 0; | ||
| 283 | } | 238 | } |
| 284 | 239 | ||
| 285 | static int proc_sys_readdir(struct file *filp, void *dirent, filldir_t filldir) | 240 | static int proc_sys_readdir(struct file *filp, void *dirent, filldir_t filldir) |
| 286 | { | 241 | { |
| 287 | struct dentry *dentry = filp->f_dentry; | 242 | struct dentry *dentry = filp->f_path.dentry; |
| 288 | struct inode *inode = dentry->d_inode; | 243 | struct inode *inode = dentry->d_inode; |
| 289 | struct ctl_table_header *head = NULL; | 244 | struct ctl_table_header *head = grab_header(inode); |
| 290 | struct ctl_table *table; | 245 | struct ctl_table *table = PROC_I(inode)->sysctl_entry; |
| 246 | struct ctl_table_header *h = NULL; | ||
| 291 | unsigned long pos; | 247 | unsigned long pos; |
| 292 | int ret; | 248 | int ret = -EINVAL; |
| 249 | |||
| 250 | if (IS_ERR(head)) | ||
| 251 | return PTR_ERR(head); | ||
| 293 | 252 | ||
| 294 | ret = -ENOTDIR; | 253 | if (table && !table->child) { |
| 295 | if (!S_ISDIR(inode->i_mode)) | 254 | WARN_ON(1); |
| 296 | goto out; | 255 | goto out; |
| 256 | } | ||
| 257 | |||
| 258 | table = table ? table->child : head->ctl_table; | ||
| 297 | 259 | ||
| 298 | ret = 0; | 260 | ret = 0; |
| 299 | /* Avoid a switch here: arm builds fail with missing __cmpdi2 */ | 261 | /* Avoid a switch here: arm builds fail with missing __cmpdi2 */ |
| @@ -311,30 +273,17 @@ static int proc_sys_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
| 311 | } | 273 | } |
| 312 | pos = 2; | 274 | pos = 2; |
| 313 | 275 | ||
| 314 | /* - Find each instance of the directory | 276 | ret = scan(head, table, &pos, filp, dirent, filldir); |
| 315 | * - Read all entries in each instance | 277 | if (ret) |
| 316 | * - Before returning an entry to user space lookup the entry | 278 | goto out; |
| 317 | * by name and if I find a different entry don't return | ||
| 318 | * this one because it means it is a buried dup. | ||
| 319 | * For sysctl this should only happen for directory entries. | ||
| 320 | */ | ||
| 321 | for (head = sysctl_head_next(NULL); head; head = sysctl_head_next(head)) { | ||
| 322 | table = proc_sys_lookup_table(dentry, head->ctl_table); | ||
| 323 | 279 | ||
| 324 | if (!table) | 280 | for (h = sysctl_head_next(NULL); h; h = sysctl_head_next(h)) { |
| 281 | if (h->attached_to != table) | ||
| 325 | continue; | 282 | continue; |
| 326 | 283 | ret = scan(h, h->attached_by, &pos, filp, dirent, filldir); | |
| 327 | for (; table->ctl_name || table->procname; table++, pos++) { | 284 | if (ret) { |
| 328 | /* Can't do anything without a proc name */ | 285 | sysctl_head_finish(h); |
| 329 | if (!table->procname) | 286 | break; |
| 330 | continue; | ||
| 331 | |||
| 332 | if (pos < filp->f_pos) | ||
| 333 | continue; | ||
| 334 | |||
| 335 | if (proc_sys_fill_cache(filp, dirent, filldir, table) < 0) | ||
| 336 | goto out; | ||
| 337 | filp->f_pos = pos + 1; | ||
| 338 | } | 287 | } |
| 339 | } | 288 | } |
| 340 | ret = 1; | 289 | ret = 1; |
| @@ -343,53 +292,24 @@ out: | |||
| 343 | return ret; | 292 | return ret; |
| 344 | } | 293 | } |
| 345 | 294 | ||
| 346 | static int proc_sys_permission(struct inode *inode, int mask, struct nameidata *nd) | 295 | static int proc_sys_permission(struct inode *inode, int mask) |
| 347 | { | 296 | { |
| 348 | /* | 297 | /* |
| 349 | * sysctl entries that are not writeable, | 298 | * sysctl entries that are not writeable, |
| 350 | * are _NOT_ writeable, capabilities or not. | 299 | * are _NOT_ writeable, capabilities or not. |
| 351 | */ | 300 | */ |
| 352 | struct ctl_table_header *head; | 301 | struct ctl_table_header *head = grab_header(inode); |
| 353 | struct ctl_table *table; | 302 | struct ctl_table *table = PROC_I(inode)->sysctl_entry; |
| 354 | struct dentry *dentry; | ||
| 355 | int mode; | ||
| 356 | int depth; | ||
| 357 | int error; | 303 | int error; |
| 358 | 304 | ||
| 359 | head = NULL; | 305 | if (IS_ERR(head)) |
| 360 | depth = PROC_I(inode)->fd; | 306 | return PTR_ERR(head); |
| 361 | |||
| 362 | /* First check the cached permissions, in case we don't have | ||
| 363 | * enough information to lookup the sysctl table entry. | ||
| 364 | */ | ||
| 365 | error = -EACCES; | ||
| 366 | mode = inode->i_mode; | ||
| 367 | |||
| 368 | if (current->euid == 0) | ||
| 369 | mode >>= 6; | ||
| 370 | else if (in_group_p(0)) | ||
| 371 | mode >>= 3; | ||
| 372 | |||
| 373 | if ((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask) | ||
| 374 | error = 0; | ||
| 375 | |||
| 376 | /* If we can't get a sysctl table entry the permission | ||
| 377 | * checks on the cached mode will have to be enough. | ||
| 378 | */ | ||
| 379 | if (!nd || !depth) | ||
| 380 | goto out; | ||
| 381 | 307 | ||
| 382 | dentry = nd->path.dentry; | 308 | if (!table) /* global root - r-xr-xr-x */ |
| 383 | table = do_proc_sys_lookup(dentry->d_parent, &dentry->d_name, &head); | 309 | error = mask & MAY_WRITE ? -EACCES : 0; |
| 310 | else /* Use the permissions on the sysctl table entry */ | ||
| 311 | error = sysctl_perm(head->root, table, mask); | ||
| 384 | 312 | ||
| 385 | /* If the entry does not exist deny permission */ | ||
| 386 | error = -EACCES; | ||
| 387 | if (!table) | ||
| 388 | goto out; | ||
| 389 | |||
| 390 | /* Use the permissions on the sysctl table entry */ | ||
| 391 | error = sysctl_perm(head->root, table, mask); | ||
| 392 | out: | ||
| 393 | sysctl_head_finish(head); | 313 | sysctl_head_finish(head); |
| 394 | return error; | 314 | return error; |
| 395 | } | 315 | } |
| @@ -409,33 +329,70 @@ static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr) | |||
| 409 | return error; | 329 | return error; |
| 410 | } | 330 | } |
| 411 | 331 | ||
| 412 | /* I'm lazy and don't distinguish between files and directories, | 332 | static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) |
| 413 | * until access time. | 333 | { |
| 414 | */ | 334 | struct inode *inode = dentry->d_inode; |
| 335 | struct ctl_table_header *head = grab_header(inode); | ||
| 336 | struct ctl_table *table = PROC_I(inode)->sysctl_entry; | ||
| 337 | |||
| 338 | if (IS_ERR(head)) | ||
| 339 | return PTR_ERR(head); | ||
| 340 | |||
| 341 | generic_fillattr(inode, stat); | ||
| 342 | if (table) | ||
| 343 | stat->mode = (stat->mode & S_IFMT) | table->mode; | ||
| 344 | |||
| 345 | sysctl_head_finish(head); | ||
| 346 | return 0; | ||
| 347 | } | ||
| 348 | |||
| 415 | static const struct file_operations proc_sys_file_operations = { | 349 | static const struct file_operations proc_sys_file_operations = { |
| 416 | .read = proc_sys_read, | 350 | .read = proc_sys_read, |
| 417 | .write = proc_sys_write, | 351 | .write = proc_sys_write, |
| 352 | }; | ||
| 353 | |||
| 354 | static const struct file_operations proc_sys_dir_file_operations = { | ||
| 418 | .readdir = proc_sys_readdir, | 355 | .readdir = proc_sys_readdir, |
| 419 | }; | 356 | }; |
| 420 | 357 | ||
| 421 | static const struct inode_operations proc_sys_inode_operations = { | 358 | static const struct inode_operations proc_sys_inode_operations = { |
| 359 | .permission = proc_sys_permission, | ||
| 360 | .setattr = proc_sys_setattr, | ||
| 361 | .getattr = proc_sys_getattr, | ||
| 362 | }; | ||
| 363 | |||
| 364 | static const struct inode_operations proc_sys_dir_operations = { | ||
| 422 | .lookup = proc_sys_lookup, | 365 | .lookup = proc_sys_lookup, |
| 423 | .permission = proc_sys_permission, | 366 | .permission = proc_sys_permission, |
| 424 | .setattr = proc_sys_setattr, | 367 | .setattr = proc_sys_setattr, |
| 368 | .getattr = proc_sys_getattr, | ||
| 425 | }; | 369 | }; |
| 426 | 370 | ||
| 427 | static int proc_sys_revalidate(struct dentry *dentry, struct nameidata *nd) | 371 | static int proc_sys_revalidate(struct dentry *dentry, struct nameidata *nd) |
| 428 | { | 372 | { |
| 429 | struct ctl_table_header *head; | 373 | return !PROC_I(dentry->d_inode)->sysctl->unregistering; |
| 430 | struct ctl_table *table; | 374 | } |
| 431 | table = do_proc_sys_lookup(dentry->d_parent, &dentry->d_name, &head); | 375 | |
| 432 | proc_sys_refresh_inode(dentry->d_inode, table); | 376 | static int proc_sys_delete(struct dentry *dentry) |
| 433 | sysctl_head_finish(head); | 377 | { |
| 434 | return !!table; | 378 | return !!PROC_I(dentry->d_inode)->sysctl->unregistering; |
| 379 | } | ||
| 380 | |||
| 381 | static int proc_sys_compare(struct dentry *dir, struct qstr *qstr, | ||
| 382 | struct qstr *name) | ||
| 383 | { | ||
| 384 | struct dentry *dentry = container_of(qstr, struct dentry, d_name); | ||
| 385 | if (qstr->len != name->len) | ||
| 386 | return 1; | ||
| 387 | if (memcmp(qstr->name, name->name, name->len)) | ||
| 388 | return 1; | ||
| 389 | return !sysctl_is_seen(PROC_I(dentry->d_inode)->sysctl); | ||
| 435 | } | 390 | } |
| 436 | 391 | ||
| 437 | static struct dentry_operations proc_sys_dentry_operations = { | 392 | static struct dentry_operations proc_sys_dentry_operations = { |
| 438 | .d_revalidate = proc_sys_revalidate, | 393 | .d_revalidate = proc_sys_revalidate, |
| 394 | .d_delete = proc_sys_delete, | ||
| 395 | .d_compare = proc_sys_compare, | ||
| 439 | }; | 396 | }; |
| 440 | 397 | ||
| 441 | static struct proc_dir_entry *proc_sys_root; | 398 | static struct proc_dir_entry *proc_sys_root; |
| @@ -443,8 +400,8 @@ static struct proc_dir_entry *proc_sys_root; | |||
| 443 | int proc_sys_init(void) | 400 | int proc_sys_init(void) |
| 444 | { | 401 | { |
| 445 | proc_sys_root = proc_mkdir("sys", NULL); | 402 | proc_sys_root = proc_mkdir("sys", NULL); |
| 446 | proc_sys_root->proc_iops = &proc_sys_inode_operations; | 403 | proc_sys_root->proc_iops = &proc_sys_dir_operations; |
| 447 | proc_sys_root->proc_fops = &proc_sys_file_operations; | 404 | proc_sys_root->proc_fops = &proc_sys_dir_file_operations; |
| 448 | proc_sys_root->nlink = 0; | 405 | proc_sys_root->nlink = 0; |
| 449 | return 0; | 406 | return 0; |
| 450 | } | 407 | } |
