aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/base.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r--fs/proc/base.c186
1 files changed, 8 insertions, 178 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9e28356a959a..9b43ff77a51e 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -542,13 +542,6 @@ int proc_setattr(struct dentry *dentry, struct iattr *attr)
542 if (error) 542 if (error)
543 return error; 543 return error;
544 544
545 if ((attr->ia_valid & ATTR_SIZE) &&
546 attr->ia_size != i_size_read(inode)) {
547 error = vmtruncate(inode, attr->ia_size);
548 if (error)
549 return error;
550 }
551
552 setattr_copy(inode, attr); 545 setattr_copy(inode, attr);
553 mark_inode_dirty(inode); 546 mark_inode_dirty(inode);
554 return 0; 547 return 0;
@@ -985,7 +978,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
985{ 978{
986 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode); 979 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
987 char buffer[PROC_NUMBUF]; 980 char buffer[PROC_NUMBUF];
988 int oom_score_adj = OOM_SCORE_ADJ_MIN; 981 short oom_score_adj = OOM_SCORE_ADJ_MIN;
989 unsigned long flags; 982 unsigned long flags;
990 size_t len; 983 size_t len;
991 984
@@ -996,7 +989,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
996 unlock_task_sighand(task, &flags); 989 unlock_task_sighand(task, &flags);
997 } 990 }
998 put_task_struct(task); 991 put_task_struct(task);
999 len = snprintf(buffer, sizeof(buffer), "%d\n", oom_score_adj); 992 len = snprintf(buffer, sizeof(buffer), "%hd\n", oom_score_adj);
1000 return simple_read_from_buffer(buf, count, ppos, buffer, len); 993 return simple_read_from_buffer(buf, count, ppos, buffer, len);
1001} 994}
1002 995
@@ -1043,15 +1036,15 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
1043 goto err_task_lock; 1036 goto err_task_lock;
1044 } 1037 }
1045 1038
1046 if (oom_score_adj < task->signal->oom_score_adj_min && 1039 if ((short)oom_score_adj < task->signal->oom_score_adj_min &&
1047 !capable(CAP_SYS_RESOURCE)) { 1040 !capable(CAP_SYS_RESOURCE)) {
1048 err = -EACCES; 1041 err = -EACCES;
1049 goto err_sighand; 1042 goto err_sighand;
1050 } 1043 }
1051 1044
1052 task->signal->oom_score_adj = oom_score_adj; 1045 task->signal->oom_score_adj = (short)oom_score_adj;
1053 if (has_capability_noaudit(current, CAP_SYS_RESOURCE)) 1046 if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
1054 task->signal->oom_score_adj_min = oom_score_adj; 1047 task->signal->oom_score_adj_min = (short)oom_score_adj;
1055 trace_oom_score_adj_update(task); 1048 trace_oom_score_adj_update(task);
1056 1049
1057err_sighand: 1050err_sighand:
@@ -2345,146 +2338,6 @@ static const struct file_operations proc_coredump_filter_operations = {
2345}; 2338};
2346#endif 2339#endif
2347 2340
2348/*
2349 * /proc/self:
2350 */
2351static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
2352 int buflen)
2353{
2354 struct pid_namespace *ns = dentry->d_sb->s_fs_info;
2355 pid_t tgid = task_tgid_nr_ns(current, ns);
2356 char tmp[PROC_NUMBUF];
2357 if (!tgid)
2358 return -ENOENT;
2359 sprintf(tmp, "%d", tgid);
2360 return vfs_readlink(dentry,buffer,buflen,tmp);
2361}
2362
2363static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
2364{
2365 struct pid_namespace *ns = dentry->d_sb->s_fs_info;
2366 pid_t tgid = task_tgid_nr_ns(current, ns);
2367 char *name = ERR_PTR(-ENOENT);
2368 if (tgid) {
2369 /* 11 for max length of signed int in decimal + NULL term */
2370 name = kmalloc(12, GFP_KERNEL);
2371 if (!name)
2372 name = ERR_PTR(-ENOMEM);
2373 else
2374 sprintf(name, "%d", tgid);
2375 }
2376 nd_set_link(nd, name);
2377 return NULL;
2378}
2379
2380static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
2381 void *cookie)
2382{
2383 char *s = nd_get_link(nd);
2384 if (!IS_ERR(s))
2385 kfree(s);
2386}
2387
2388static const struct inode_operations proc_self_inode_operations = {
2389 .readlink = proc_self_readlink,
2390 .follow_link = proc_self_follow_link,
2391 .put_link = proc_self_put_link,
2392};
2393
2394/*
2395 * proc base
2396 *
2397 * These are the directory entries in the root directory of /proc
2398 * that properly belong to the /proc filesystem, as they describe
2399 * describe something that is process related.
2400 */
2401static const struct pid_entry proc_base_stuff[] = {
2402 NOD("self", S_IFLNK|S_IRWXUGO,
2403 &proc_self_inode_operations, NULL, {}),
2404};
2405
2406static struct dentry *proc_base_instantiate(struct inode *dir,
2407 struct dentry *dentry, struct task_struct *task, const void *ptr)
2408{
2409 const struct pid_entry *p = ptr;
2410 struct inode *inode;
2411 struct proc_inode *ei;
2412 struct dentry *error;
2413
2414 /* Allocate the inode */
2415 error = ERR_PTR(-ENOMEM);
2416 inode = new_inode(dir->i_sb);
2417 if (!inode)
2418 goto out;
2419
2420 /* Initialize the inode */
2421 ei = PROC_I(inode);
2422 inode->i_ino = get_next_ino();
2423 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2424
2425 /*
2426 * grab the reference to the task.
2427 */
2428 ei->pid = get_task_pid(task, PIDTYPE_PID);
2429 if (!ei->pid)
2430 goto out_iput;
2431
2432 inode->i_mode = p->mode;
2433 if (S_ISDIR(inode->i_mode))
2434 set_nlink(inode, 2);
2435 if (S_ISLNK(inode->i_mode))
2436 inode->i_size = 64;
2437 if (p->iop)
2438 inode->i_op = p->iop;
2439 if (p->fop)
2440 inode->i_fop = p->fop;
2441 ei->op = p->op;
2442 d_add(dentry, inode);
2443 error = NULL;
2444out:
2445 return error;
2446out_iput:
2447 iput(inode);
2448 goto out;
2449}
2450
2451static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
2452{
2453 struct dentry *error;
2454 struct task_struct *task = get_proc_task(dir);
2455 const struct pid_entry *p, *last;
2456
2457 error = ERR_PTR(-ENOENT);
2458
2459 if (!task)
2460 goto out_no_task;
2461
2462 /* Lookup the directory entry */
2463 last = &proc_base_stuff[ARRAY_SIZE(proc_base_stuff) - 1];
2464 for (p = proc_base_stuff; p <= last; p++) {
2465 if (p->len != dentry->d_name.len)
2466 continue;
2467 if (!memcmp(dentry->d_name.name, p->name, p->len))
2468 break;
2469 }
2470 if (p > last)
2471 goto out;
2472
2473 error = proc_base_instantiate(dir, dentry, task, p);
2474
2475out:
2476 put_task_struct(task);
2477out_no_task:
2478 return error;
2479}
2480
2481static int proc_base_fill_cache(struct file *filp, void *dirent,
2482 filldir_t filldir, struct task_struct *task, const struct pid_entry *p)
2483{
2484 return proc_fill_cache(filp, dirent, filldir, p->name, p->len,
2485 proc_base_instantiate, task, p);
2486}
2487
2488#ifdef CONFIG_TASK_IO_ACCOUNTING 2341#ifdef CONFIG_TASK_IO_ACCOUNTING
2489static int do_io_accounting(struct task_struct *task, char *buffer, int whole) 2342static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
2490{ 2343{
@@ -2839,10 +2692,6 @@ void proc_flush_task(struct task_struct *task)
2839 proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr, 2692 proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr,
2840 tgid->numbers[i].nr); 2693 tgid->numbers[i].nr);
2841 } 2694 }
2842
2843 upid = &pid->numbers[pid->level];
2844 if (upid->nr == 1)
2845 pid_ns_release_proc(upid->ns);
2846} 2695}
2847 2696
2848static struct dentry *proc_pid_instantiate(struct inode *dir, 2697static struct dentry *proc_pid_instantiate(struct inode *dir,
@@ -2876,15 +2725,11 @@ out:
2876 2725
2877struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) 2726struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags)
2878{ 2727{
2879 struct dentry *result; 2728 struct dentry *result = NULL;
2880 struct task_struct *task; 2729 struct task_struct *task;
2881 unsigned tgid; 2730 unsigned tgid;
2882 struct pid_namespace *ns; 2731 struct pid_namespace *ns;
2883 2732
2884 result = proc_base_lookup(dir, dentry);
2885 if (!IS_ERR(result) || PTR_ERR(result) != -ENOENT)
2886 goto out;
2887
2888 tgid = name_to_int(dentry); 2733 tgid = name_to_int(dentry);
2889 if (tgid == ~0U) 2734 if (tgid == ~0U)
2890 goto out; 2735 goto out;
@@ -2947,7 +2792,7 @@ retry:
2947 return iter; 2792 return iter;
2948} 2793}
2949 2794
2950#define TGID_OFFSET (FIRST_PROCESS_ENTRY + ARRAY_SIZE(proc_base_stuff)) 2795#define TGID_OFFSET (FIRST_PROCESS_ENTRY)
2951 2796
2952static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldir, 2797static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
2953 struct tgid_iter iter) 2798 struct tgid_iter iter)
@@ -2967,25 +2812,12 @@ static int fake_filldir(void *buf, const char *name, int namelen,
2967/* for the /proc/ directory itself, after non-process stuff has been done */ 2812/* for the /proc/ directory itself, after non-process stuff has been done */
2968int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) 2813int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
2969{ 2814{
2970 unsigned int nr;
2971 struct task_struct *reaper;
2972 struct tgid_iter iter; 2815 struct tgid_iter iter;
2973 struct pid_namespace *ns; 2816 struct pid_namespace *ns;
2974 filldir_t __filldir; 2817 filldir_t __filldir;
2975 2818
2976 if (filp->f_pos >= PID_MAX_LIMIT + TGID_OFFSET) 2819 if (filp->f_pos >= PID_MAX_LIMIT + TGID_OFFSET)
2977 goto out_no_task; 2820 goto out;
2978 nr = filp->f_pos - FIRST_PROCESS_ENTRY;
2979
2980 reaper = get_proc_task(filp->f_path.dentry->d_inode);
2981 if (!reaper)
2982 goto out_no_task;
2983
2984 for (; nr < ARRAY_SIZE(proc_base_stuff); filp->f_pos++, nr++) {
2985 const struct pid_entry *p = &proc_base_stuff[nr];
2986 if (proc_base_fill_cache(filp, dirent, filldir, reaper, p) < 0)
2987 goto out;
2988 }
2989 2821
2990 ns = filp->f_dentry->d_sb->s_fs_info; 2822 ns = filp->f_dentry->d_sb->s_fs_info;
2991 iter.task = NULL; 2823 iter.task = NULL;
@@ -3006,8 +2838,6 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
3006 } 2838 }
3007 filp->f_pos = PID_MAX_LIMIT + TGID_OFFSET; 2839 filp->f_pos = PID_MAX_LIMIT + TGID_OFFSET;
3008out: 2840out:
3009 put_task_struct(reaper);
3010out_no_task:
3011 return 0; 2841 return 0;
3012} 2842}
3013 2843