aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/base.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2007-01-17 18:34:51 -0500
committerDavid Woodhouse <dwmw2@infradead.org>2007-01-17 18:34:51 -0500
commit9cdf083f981b8d37b3212400a359368661385099 (patch)
treeaa15a6a08ad87e650dea40fb59b3180bef0d345b /fs/proc/base.c
parente499e01d234a31d59679b7b1e1cf628d917ba49a (diff)
parenta8b3485287731978899ced11f24628c927890e78 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r--fs/proc/base.c172
1 files changed, 132 insertions, 40 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 795319c54f72..77a57b5799c4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -59,7 +59,7 @@
59#include <linux/string.h> 59#include <linux/string.h>
60#include <linux/seq_file.h> 60#include <linux/seq_file.h>
61#include <linux/namei.h> 61#include <linux/namei.h>
62#include <linux/namespace.h> 62#include <linux/mnt_namespace.h>
63#include <linux/mm.h> 63#include <linux/mm.h>
64#include <linux/smp_lock.h> 64#include <linux/smp_lock.h>
65#include <linux/rcupdate.h> 65#include <linux/rcupdate.h>
@@ -365,33 +365,33 @@ struct proc_mounts {
365static int mounts_open(struct inode *inode, struct file *file) 365static int mounts_open(struct inode *inode, struct file *file)
366{ 366{
367 struct task_struct *task = get_proc_task(inode); 367 struct task_struct *task = get_proc_task(inode);
368 struct namespace *namespace = NULL; 368 struct mnt_namespace *ns = NULL;
369 struct proc_mounts *p; 369 struct proc_mounts *p;
370 int ret = -EINVAL; 370 int ret = -EINVAL;
371 371
372 if (task) { 372 if (task) {
373 task_lock(task); 373 task_lock(task);
374 namespace = task->nsproxy->namespace; 374 ns = task->nsproxy->mnt_ns;
375 if (namespace) 375 if (ns)
376 get_namespace(namespace); 376 get_mnt_ns(ns);
377 task_unlock(task); 377 task_unlock(task);
378 put_task_struct(task); 378 put_task_struct(task);
379 } 379 }
380 380
381 if (namespace) { 381 if (ns) {
382 ret = -ENOMEM; 382 ret = -ENOMEM;
383 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); 383 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
384 if (p) { 384 if (p) {
385 file->private_data = &p->m; 385 file->private_data = &p->m;
386 ret = seq_open(file, &mounts_op); 386 ret = seq_open(file, &mounts_op);
387 if (!ret) { 387 if (!ret) {
388 p->m.private = namespace; 388 p->m.private = ns;
389 p->event = namespace->event; 389 p->event = ns->event;
390 return 0; 390 return 0;
391 } 391 }
392 kfree(p); 392 kfree(p);
393 } 393 }
394 put_namespace(namespace); 394 put_mnt_ns(ns);
395 } 395 }
396 return ret; 396 return ret;
397} 397}
@@ -399,15 +399,15 @@ static int mounts_open(struct inode *inode, struct file *file)
399static int mounts_release(struct inode *inode, struct file *file) 399static int mounts_release(struct inode *inode, struct file *file)
400{ 400{
401 struct seq_file *m = file->private_data; 401 struct seq_file *m = file->private_data;
402 struct namespace *namespace = m->private; 402 struct mnt_namespace *ns = m->private;
403 put_namespace(namespace); 403 put_mnt_ns(ns);
404 return seq_release(inode, file); 404 return seq_release(inode, file);
405} 405}
406 406
407static unsigned mounts_poll(struct file *file, poll_table *wait) 407static unsigned mounts_poll(struct file *file, poll_table *wait)
408{ 408{
409 struct proc_mounts *p = file->private_data; 409 struct proc_mounts *p = file->private_data;
410 struct namespace *ns = p->m.private; 410 struct mnt_namespace *ns = p->m.private;
411 unsigned res = 0; 411 unsigned res = 0;
412 412
413 poll_wait(file, &ns->poll, wait); 413 poll_wait(file, &ns->poll, wait);
@@ -437,21 +437,21 @@ static int mountstats_open(struct inode *inode, struct file *file)
437 437
438 if (!ret) { 438 if (!ret) {
439 struct seq_file *m = file->private_data; 439 struct seq_file *m = file->private_data;
440 struct namespace *namespace = NULL; 440 struct mnt_namespace *mnt_ns = NULL;
441 struct task_struct *task = get_proc_task(inode); 441 struct task_struct *task = get_proc_task(inode);
442 442
443 if (task) { 443 if (task) {
444 task_lock(task); 444 task_lock(task);
445 if (task->nsproxy) 445 if (task->nsproxy)
446 namespace = task->nsproxy->namespace; 446 mnt_ns = task->nsproxy->mnt_ns;
447 if (namespace) 447 if (mnt_ns)
448 get_namespace(namespace); 448 get_mnt_ns(mnt_ns);
449 task_unlock(task); 449 task_unlock(task);
450 put_task_struct(task); 450 put_task_struct(task);
451 } 451 }
452 452
453 if (namespace) 453 if (mnt_ns)
454 m->private = namespace; 454 m->private = mnt_ns;
455 else { 455 else {
456 seq_release(inode, file); 456 seq_release(inode, file);
457 ret = -EINVAL; 457 ret = -EINVAL;
@@ -472,7 +472,7 @@ static struct file_operations proc_mountstats_operations = {
472static ssize_t proc_info_read(struct file * file, char __user * buf, 472static ssize_t proc_info_read(struct file * file, char __user * buf,
473 size_t count, loff_t *ppos) 473 size_t count, loff_t *ppos)
474{ 474{
475 struct inode * inode = file->f_dentry->d_inode; 475 struct inode * inode = file->f_path.dentry->d_inode;
476 unsigned long page; 476 unsigned long page;
477 ssize_t length; 477 ssize_t length;
478 struct task_struct *task = get_proc_task(inode); 478 struct task_struct *task = get_proc_task(inode);
@@ -512,7 +512,7 @@ static int mem_open(struct inode* inode, struct file* file)
512static ssize_t mem_read(struct file * file, char __user * buf, 512static ssize_t mem_read(struct file * file, char __user * buf,
513 size_t count, loff_t *ppos) 513 size_t count, loff_t *ppos)
514{ 514{
515 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 515 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
516 char *page; 516 char *page;
517 unsigned long src = *ppos; 517 unsigned long src = *ppos;
518 int ret = -ESRCH; 518 int ret = -ESRCH;
@@ -584,7 +584,7 @@ static ssize_t mem_write(struct file * file, const char * buf,
584{ 584{
585 int copied; 585 int copied;
586 char *page; 586 char *page;
587 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 587 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
588 unsigned long dst = *ppos; 588 unsigned long dst = *ppos;
589 589
590 copied = -ESRCH; 590 copied = -ESRCH;
@@ -654,7 +654,7 @@ static struct file_operations proc_mem_operations = {
654static ssize_t oom_adjust_read(struct file *file, char __user *buf, 654static ssize_t oom_adjust_read(struct file *file, char __user *buf,
655 size_t count, loff_t *ppos) 655 size_t count, loff_t *ppos)
656{ 656{
657 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 657 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
658 char buffer[PROC_NUMBUF]; 658 char buffer[PROC_NUMBUF];
659 size_t len; 659 size_t len;
660 int oom_adjust; 660 int oom_adjust;
@@ -683,8 +683,6 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
683 char buffer[PROC_NUMBUF], *end; 683 char buffer[PROC_NUMBUF], *end;
684 int oom_adjust; 684 int oom_adjust;
685 685
686 if (!capable(CAP_SYS_RESOURCE))
687 return -EPERM;
688 memset(buffer, 0, sizeof(buffer)); 686 memset(buffer, 0, sizeof(buffer));
689 if (count > sizeof(buffer) - 1) 687 if (count > sizeof(buffer) - 1)
690 count = sizeof(buffer) - 1; 688 count = sizeof(buffer) - 1;
@@ -696,9 +694,13 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
696 return -EINVAL; 694 return -EINVAL;
697 if (*end == '\n') 695 if (*end == '\n')
698 end++; 696 end++;
699 task = get_proc_task(file->f_dentry->d_inode); 697 task = get_proc_task(file->f_path.dentry->d_inode);
700 if (!task) 698 if (!task)
701 return -ESRCH; 699 return -ESRCH;
700 if (oom_adjust < task->oomkilladj && !capable(CAP_SYS_RESOURCE)) {
701 put_task_struct(task);
702 return -EACCES;
703 }
702 task->oomkilladj = oom_adjust; 704 task->oomkilladj = oom_adjust;
703 put_task_struct(task); 705 put_task_struct(task);
704 if (end - buffer == 0) 706 if (end - buffer == 0)
@@ -716,7 +718,7 @@ static struct file_operations proc_oom_adjust_operations = {
716static ssize_t proc_loginuid_read(struct file * file, char __user * buf, 718static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
717 size_t count, loff_t *ppos) 719 size_t count, loff_t *ppos)
718{ 720{
719 struct inode * inode = file->f_dentry->d_inode; 721 struct inode * inode = file->f_path.dentry->d_inode;
720 struct task_struct *task = get_proc_task(inode); 722 struct task_struct *task = get_proc_task(inode);
721 ssize_t length; 723 ssize_t length;
722 char tmpbuf[TMPBUFLEN]; 724 char tmpbuf[TMPBUFLEN];
@@ -732,7 +734,7 @@ static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
732static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, 734static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
733 size_t count, loff_t *ppos) 735 size_t count, loff_t *ppos)
734{ 736{
735 struct inode * inode = file->f_dentry->d_inode; 737 struct inode * inode = file->f_path.dentry->d_inode;
736 char *page, *tmp; 738 char *page, *tmp;
737 ssize_t length; 739 ssize_t length;
738 uid_t loginuid; 740 uid_t loginuid;
@@ -851,6 +853,65 @@ static struct file_operations proc_seccomp_operations = {
851}; 853};
852#endif /* CONFIG_SECCOMP */ 854#endif /* CONFIG_SECCOMP */
853 855
856#ifdef CONFIG_FAULT_INJECTION
857static ssize_t proc_fault_inject_read(struct file * file, char __user * buf,
858 size_t count, loff_t *ppos)
859{
860 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
861 char buffer[PROC_NUMBUF];
862 size_t len;
863 int make_it_fail;
864 loff_t __ppos = *ppos;
865
866 if (!task)
867 return -ESRCH;
868 make_it_fail = task->make_it_fail;
869 put_task_struct(task);
870
871 len = snprintf(buffer, sizeof(buffer), "%i\n", make_it_fail);
872 if (__ppos >= len)
873 return 0;
874 if (count > len-__ppos)
875 count = len-__ppos;
876 if (copy_to_user(buf, buffer + __ppos, count))
877 return -EFAULT;
878 *ppos = __ppos + count;
879 return count;
880}
881
882static ssize_t proc_fault_inject_write(struct file * file,
883 const char __user * buf, size_t count, loff_t *ppos)
884{
885 struct task_struct *task;
886 char buffer[PROC_NUMBUF], *end;
887 int make_it_fail;
888
889 if (!capable(CAP_SYS_RESOURCE))
890 return -EPERM;
891 memset(buffer, 0, sizeof(buffer));
892 if (count > sizeof(buffer) - 1)
893 count = sizeof(buffer) - 1;
894 if (copy_from_user(buffer, buf, count))
895 return -EFAULT;
896 make_it_fail = simple_strtol(buffer, &end, 0);
897 if (*end == '\n')
898 end++;
899 task = get_proc_task(file->f_dentry->d_inode);
900 if (!task)
901 return -ESRCH;
902 task->make_it_fail = make_it_fail;
903 put_task_struct(task);
904 if (end - buffer == 0)
905 return -EIO;
906 return end - buffer;
907}
908
909static struct file_operations proc_fault_inject_operations = {
910 .read = proc_fault_inject_read,
911 .write = proc_fault_inject_write,
912};
913#endif
914
854static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) 915static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
855{ 916{
856 struct inode *inode = dentry->d_inode; 917 struct inode *inode = dentry->d_inode;
@@ -1076,7 +1137,7 @@ static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
1076 char *name, int len, 1137 char *name, int len,
1077 instantiate_t instantiate, struct task_struct *task, void *ptr) 1138 instantiate_t instantiate, struct task_struct *task, void *ptr)
1078{ 1139{
1079 struct dentry *child, *dir = filp->f_dentry; 1140 struct dentry *child, *dir = filp->f_path.dentry;
1080 struct inode *inode; 1141 struct inode *inode;
1081 struct qstr qname; 1142 struct qstr qname;
1082 ino_t ino = 0; 1143 ino_t ino = 0;
@@ -1155,8 +1216,8 @@ static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsm
1155 spin_lock(&files->file_lock); 1216 spin_lock(&files->file_lock);
1156 file = fcheck_files(files, fd); 1217 file = fcheck_files(files, fd);
1157 if (file) { 1218 if (file) {
1158 *mnt = mntget(file->f_vfsmnt); 1219 *mnt = mntget(file->f_path.mnt);
1159 *dentry = dget(file->f_dentry); 1220 *dentry = dget(file->f_path.dentry);
1160 spin_unlock(&files->file_lock); 1221 spin_unlock(&files->file_lock);
1161 put_files_struct(files); 1222 put_files_struct(files);
1162 return 0; 1223 return 0;
@@ -1291,7 +1352,7 @@ static int proc_fd_fill_cache(struct file *filp, void *dirent, filldir_t filldir
1291 1352
1292static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir) 1353static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1293{ 1354{
1294 struct dentry *dentry = filp->f_dentry; 1355 struct dentry *dentry = filp->f_path.dentry;
1295 struct inode *inode = dentry->d_inode; 1356 struct inode *inode = dentry->d_inode;
1296 struct task_struct *p = get_proc_task(inode); 1357 struct task_struct *p = get_proc_task(inode);
1297 unsigned int fd, tid, ino; 1358 unsigned int fd, tid, ino;
@@ -1438,7 +1499,7 @@ static int proc_pident_readdir(struct file *filp,
1438{ 1499{
1439 int i; 1500 int i;
1440 int pid; 1501 int pid;
1441 struct dentry *dentry = filp->f_dentry; 1502 struct dentry *dentry = filp->f_path.dentry;
1442 struct inode *inode = dentry->d_inode; 1503 struct inode *inode = dentry->d_inode;
1443 struct task_struct *task = get_proc_task(inode); 1504 struct task_struct *task = get_proc_task(inode);
1444 struct pid_entry *p, *last; 1505 struct pid_entry *p, *last;
@@ -1494,7 +1555,7 @@ out_no_task:
1494static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, 1555static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
1495 size_t count, loff_t *ppos) 1556 size_t count, loff_t *ppos)
1496{ 1557{
1497 struct inode * inode = file->f_dentry->d_inode; 1558 struct inode * inode = file->f_path.dentry->d_inode;
1498 unsigned long page; 1559 unsigned long page;
1499 ssize_t length; 1560 ssize_t length;
1500 struct task_struct *task = get_proc_task(inode); 1561 struct task_struct *task = get_proc_task(inode);
@@ -1510,7 +1571,7 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
1510 goto out; 1571 goto out;
1511 1572
1512 length = security_getprocattr(task, 1573 length = security_getprocattr(task,
1513 (char*)file->f_dentry->d_name.name, 1574 (char*)file->f_path.dentry->d_name.name,
1514 (void*)page, count); 1575 (void*)page, count);
1515 if (length >= 0) 1576 if (length >= 0)
1516 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); 1577 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
@@ -1524,7 +1585,7 @@ out_no_task:
1524static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, 1585static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
1525 size_t count, loff_t *ppos) 1586 size_t count, loff_t *ppos)
1526{ 1587{
1527 struct inode * inode = file->f_dentry->d_inode; 1588 struct inode * inode = file->f_path.dentry->d_inode;
1528 char *page; 1589 char *page;
1529 ssize_t length; 1590 ssize_t length;
1530 struct task_struct *task = get_proc_task(inode); 1591 struct task_struct *task = get_proc_task(inode);
@@ -1550,7 +1611,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
1550 goto out_free; 1611 goto out_free;
1551 1612
1552 length = security_setprocattr(task, 1613 length = security_setprocattr(task,
1553 (char*)file->f_dentry->d_name.name, 1614 (char*)file->f_path.dentry->d_name.name,
1554 (void*)page, count); 1615 (void*)page, count);
1555out_free: 1616out_free:
1556 free_page((unsigned long) page); 1617 free_page((unsigned long) page);
@@ -1743,6 +1804,27 @@ static int proc_base_fill_cache(struct file *filp, void *dirent, filldir_t filld
1743 proc_base_instantiate, task, p); 1804 proc_base_instantiate, task, p);
1744} 1805}
1745 1806
1807#ifdef CONFIG_TASK_IO_ACCOUNTING
1808static int proc_pid_io_accounting(struct task_struct *task, char *buffer)
1809{
1810 return sprintf(buffer,
1811 "rchar: %llu\n"
1812 "wchar: %llu\n"
1813 "syscr: %llu\n"
1814 "syscw: %llu\n"
1815 "read_bytes: %llu\n"
1816 "write_bytes: %llu\n"
1817 "cancelled_write_bytes: %llu\n",
1818 (unsigned long long)task->rchar,
1819 (unsigned long long)task->wchar,
1820 (unsigned long long)task->syscr,
1821 (unsigned long long)task->syscw,
1822 (unsigned long long)task->ioac.read_bytes,
1823 (unsigned long long)task->ioac.write_bytes,
1824 (unsigned long long)task->ioac.cancelled_write_bytes);
1825}
1826#endif
1827
1746/* 1828/*
1747 * Thread groups 1829 * Thread groups
1748 */ 1830 */
@@ -1791,6 +1873,12 @@ static struct pid_entry tgid_base_stuff[] = {
1791#ifdef CONFIG_AUDITSYSCALL 1873#ifdef CONFIG_AUDITSYSCALL
1792 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 1874 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
1793#endif 1875#endif
1876#ifdef CONFIG_FAULT_INJECTION
1877 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
1878#endif
1879#ifdef CONFIG_TASK_IO_ACCOUNTING
1880 INF("io", S_IRUGO, pid_io_accounting),
1881#endif
1794}; 1882};
1795 1883
1796static int proc_tgid_base_readdir(struct file * filp, 1884static int proc_tgid_base_readdir(struct file * filp,
@@ -1883,8 +1971,9 @@ out:
1883 return; 1971 return;
1884} 1972}
1885 1973
1886struct dentry *proc_pid_instantiate(struct inode *dir, 1974static struct dentry *proc_pid_instantiate(struct inode *dir,
1887 struct dentry * dentry, struct task_struct *task, void *ptr) 1975 struct dentry * dentry,
1976 struct task_struct *task, void *ptr)
1888{ 1977{
1889 struct dentry *error = ERR_PTR(-ENOENT); 1978 struct dentry *error = ERR_PTR(-ENOENT);
1890 struct inode *inode; 1979 struct inode *inode;
@@ -1991,7 +2080,7 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
1991int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) 2080int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
1992{ 2081{
1993 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; 2082 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
1994 struct task_struct *reaper = get_proc_task(filp->f_dentry->d_inode); 2083 struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
1995 struct task_struct *task; 2084 struct task_struct *task;
1996 int tgid; 2085 int tgid;
1997 2086
@@ -2065,6 +2154,9 @@ static struct pid_entry tid_base_stuff[] = {
2065#ifdef CONFIG_AUDITSYSCALL 2154#ifdef CONFIG_AUDITSYSCALL
2066 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 2155 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
2067#endif 2156#endif
2157#ifdef CONFIG_FAULT_INJECTION
2158 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
2159#endif
2068}; 2160};
2069 2161
2070static int proc_tid_base_readdir(struct file * filp, 2162static int proc_tid_base_readdir(struct file * filp,
@@ -2232,7 +2324,7 @@ static int proc_task_fill_cache(struct file *filp, void *dirent, filldir_t filld
2232/* for the /proc/TGID/task/ directories */ 2324/* for the /proc/TGID/task/ directories */
2233static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir) 2325static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir)
2234{ 2326{
2235 struct dentry *dentry = filp->f_dentry; 2327 struct dentry *dentry = filp->f_path.dentry;
2236 struct inode *inode = dentry->d_inode; 2328 struct inode *inode = dentry->d_inode;
2237 struct task_struct *leader = get_proc_task(inode); 2329 struct task_struct *leader = get_proc_task(inode);
2238 struct task_struct *task; 2330 struct task_struct *task;