base.c (ea77f7a2e8561012cf100c530170f12351c3b53e) base.c (3864601387cf4196371e3c1897fdffa5228296f9)
1/*
2 * linux/fs/proc/base.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * proc base directory handling functions
7 *
8 * 1999, Al Viro. Rewritten. Now it covers the whole per-process part.

--- 586 unchanged lines hidden (view full) ---

595 task = get_proc_task(inode);
596 if (task) {
597 allowed = ptrace_may_access(task, PTRACE_MODE_READ);
598 put_task_struct(task);
599 }
600 return allowed;
601}
602
1/*
2 * linux/fs/proc/base.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * proc base directory handling functions
7 *
8 * 1999, Al Viro. Rewritten. Now it covers the whole per-process part.

--- 586 unchanged lines hidden (view full) ---

595 task = get_proc_task(inode);
596 if (task) {
597 allowed = ptrace_may_access(task, PTRACE_MODE_READ);
598 put_task_struct(task);
599 }
600 return allowed;
601}
602
603static int proc_setattr(struct dentry *dentry, struct iattr *attr)
603int proc_setattr(struct dentry *dentry, struct iattr *attr)
604{
605 int error;
606 struct inode *inode = dentry->d_inode;
607
608 if (attr->ia_valid & ATTR_MODE)
609 return -EPERM;
610
611 error = inode_change_ok(inode, attr);

--- 959 unchanged lines hidden (view full) ---

1571static const struct file_operations proc_pid_set_comm_operations = {
1572 .open = comm_open,
1573 .read = seq_read,
1574 .write = comm_write,
1575 .llseek = seq_lseek,
1576 .release = single_release,
1577};
1578
604{
605 int error;
606 struct inode *inode = dentry->d_inode;
607
608 if (attr->ia_valid & ATTR_MODE)
609 return -EPERM;
610
611 error = inode_change_ok(inode, attr);

--- 959 unchanged lines hidden (view full) ---

1571static const struct file_operations proc_pid_set_comm_operations = {
1572 .open = comm_open,
1573 .read = seq_read,
1574 .write = comm_write,
1575 .llseek = seq_lseek,
1576 .release = single_release,
1577};
1578
1579/*
1580 * We added or removed a vma mapping the executable. The vmas are only mapped
1581 * during exec and are not mapped with the mmap system call.
1582 * Callers must hold down_write() on the mm's mmap_sem for these
1583 */
1584void added_exe_file_vma(struct mm_struct *mm)
1585{
1586 mm->num_exe_file_vmas++;
1587}
1588
1589void removed_exe_file_vma(struct mm_struct *mm)
1590{
1591 mm->num_exe_file_vmas--;
1592 if ((mm->num_exe_file_vmas == 0) && mm->exe_file){
1593 fput(mm->exe_file);
1594 mm->exe_file = NULL;
1595 }
1596
1597}
1598
1599void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
1600{
1601 if (new_exe_file)
1602 get_file(new_exe_file);
1603 if (mm->exe_file)
1604 fput(mm->exe_file);
1605 mm->exe_file = new_exe_file;
1606 mm->num_exe_file_vmas = 0;
1607}
1608
1609struct file *get_mm_exe_file(struct mm_struct *mm)
1610{
1611 struct file *exe_file;
1612
1613 /* We need mmap_sem to protect against races with removal of
1614 * VM_EXECUTABLE vmas */
1615 down_read(&mm->mmap_sem);
1616 exe_file = mm->exe_file;
1617 if (exe_file)
1618 get_file(exe_file);
1619 up_read(&mm->mmap_sem);
1620 return exe_file;
1621}
1622
1623void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm)
1624{
1625 /* It's safe to write the exe_file pointer without exe_file_lock because
1626 * this is called during fork when the task is not yet in /proc */
1627 newmm->exe_file = get_mm_exe_file(oldmm);
1628}
1629
1630static int proc_exe_link(struct inode *inode, struct path *exe_path)
1631{
1632 struct task_struct *task;
1633 struct mm_struct *mm;
1634 struct file *exe_file;
1635
1636 task = get_proc_task(inode);
1637 if (!task)

--- 93 unchanged lines hidden (view full) ---

1731 if (mm)
1732 dumpable = get_dumpable(mm);
1733 task_unlock(task);
1734 if(dumpable == 1)
1735 return 1;
1736 return 0;
1737}
1738
1579static int proc_exe_link(struct inode *inode, struct path *exe_path)
1580{
1581 struct task_struct *task;
1582 struct mm_struct *mm;
1583 struct file *exe_file;
1584
1585 task = get_proc_task(inode);
1586 if (!task)

--- 93 unchanged lines hidden (view full) ---

1680 if (mm)
1681 dumpable = get_dumpable(mm);
1682 task_unlock(task);
1683 if(dumpable == 1)
1684 return 1;
1685 return 0;
1686}
1687
1739
1740static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task)
1688struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task)
1741{
1742 struct inode * inode;
1743 struct proc_inode *ei;
1744 const struct cred *cred;
1745
1746 /* We need a new inode */
1747
1748 inode = new_inode(sb);

--- 25 unchanged lines hidden (view full) ---

1774out:
1775 return inode;
1776
1777out_unlock:
1778 iput(inode);
1779 return NULL;
1780}
1781
1689{
1690 struct inode * inode;
1691 struct proc_inode *ei;
1692 const struct cred *cred;
1693
1694 /* We need a new inode */
1695
1696 inode = new_inode(sb);

--- 25 unchanged lines hidden (view full) ---

1722out:
1723 return inode;
1724
1725out_unlock:
1726 iput(inode);
1727 return NULL;
1728}
1729
1782static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1730int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1783{
1784 struct inode *inode = dentry->d_inode;
1785 struct task_struct *task;
1786 const struct cred *cred;
1787
1788 generic_fillattr(inode, stat);
1789
1790 rcu_read_lock();

--- 24 unchanged lines hidden (view full) ---

1815 *
1816 * Before the /proc/pid/status file was created the only way to read
1817 * the effective uid of a /process was to stat /proc/pid. Reading
1818 * /proc/pid/status is slow enough that procps and other packages
1819 * kept stating /proc/pid. To keep the rules in /proc simple I have
1820 * made this apply to all per process world readable and executable
1821 * directories.
1822 */
1731{
1732 struct inode *inode = dentry->d_inode;
1733 struct task_struct *task;
1734 const struct cred *cred;
1735
1736 generic_fillattr(inode, stat);
1737
1738 rcu_read_lock();

--- 24 unchanged lines hidden (view full) ---

1763 *
1764 * Before the /proc/pid/status file was created the only way to read
1765 * the effective uid of a /process was to stat /proc/pid. Reading
1766 * /proc/pid/status is slow enough that procps and other packages
1767 * kept stating /proc/pid. To keep the rules in /proc simple I have
1768 * made this apply to all per process world readable and executable
1769 * directories.
1770 */
1823static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
1771int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
1824{
1825 struct inode *inode;
1826 struct task_struct *task;
1827 const struct cred *cred;
1828
1829 if (nd && nd->flags & LOOKUP_RCU)
1830 return -ECHILD;
1831

--- 25 unchanged lines hidden (view full) ---

1857{
1858 /* Is the task we represent dead?
1859 * If so, then don't put the dentry on the lru list,
1860 * kill it immediately.
1861 */
1862 return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
1863}
1864
1772{
1773 struct inode *inode;
1774 struct task_struct *task;
1775 const struct cred *cred;
1776
1777 if (nd && nd->flags & LOOKUP_RCU)
1778 return -ECHILD;
1779

--- 25 unchanged lines hidden (view full) ---

1805{
1806 /* Is the task we represent dead?
1807 * If so, then don't put the dentry on the lru list,
1808 * kill it immediately.
1809 */
1810 return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
1811}
1812
1865static const struct dentry_operations pid_dentry_operations =
1813const struct dentry_operations pid_dentry_operations =
1866{
1867 .d_revalidate = pid_revalidate,
1868 .d_delete = pid_delete_dentry,
1869};
1870
1871/* Lookups */
1872
1814{
1815 .d_revalidate = pid_revalidate,
1816 .d_delete = pid_delete_dentry,
1817};
1818
1819/* Lookups */
1820
1873typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
1874 struct task_struct *, const void *);
1875
1876/*
1877 * Fill a directory entry.
1878 *
1879 * If possible create the dcache entry and derive our inode number and
1880 * file type from dcache entry.
1881 *
1882 * Since all of the proc inode numbers are dynamically generated, the inode
1883 * numbers do not exist until the inode is cache. This means creating the
1884 * the dcache entry in readdir is necessary to keep the inode numbers
1885 * reported by readdir in sync with the inode numbers reported
1886 * by stat.
1887 */
1821/*
1822 * Fill a directory entry.
1823 *
1824 * If possible create the dcache entry and derive our inode number and
1825 * file type from dcache entry.
1826 *
1827 * Since all of the proc inode numbers are dynamically generated, the inode
1828 * numbers do not exist until the inode is cache. This means creating the
1829 * the dcache entry in readdir is necessary to keep the inode numbers
1830 * reported by readdir in sync with the inode numbers reported
1831 * by stat.
1832 */
1888static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
1889 char *name, int len,
1833int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
1834 const char *name, int len,
1890 instantiate_t instantiate, struct task_struct *task, const void *ptr)
1891{
1892 struct dentry *child, *dir = filp->f_path.dentry;
1893 struct inode *inode;
1894 struct qstr qname;
1895 ino_t ino = 0;
1896 unsigned type = DT_UNKNOWN;
1897

--- 917 unchanged lines hidden (view full) ---

2815 */
2816static const struct file_operations proc_task_operations;
2817static const struct inode_operations proc_task_inode_operations;
2818
2819static const struct pid_entry tgid_base_stuff[] = {
2820 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
2821 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
2822 DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
1835 instantiate_t instantiate, struct task_struct *task, const void *ptr)
1836{
1837 struct dentry *child, *dir = filp->f_path.dentry;
1838 struct inode *inode;
1839 struct qstr qname;
1840 ino_t ino = 0;
1841 unsigned type = DT_UNKNOWN;
1842

--- 917 unchanged lines hidden (view full) ---

2760 */
2761static const struct file_operations proc_task_operations;
2762static const struct inode_operations proc_task_inode_operations;
2763
2764static const struct pid_entry tgid_base_stuff[] = {
2765 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
2766 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
2767 DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
2768 DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
2823#ifdef CONFIG_NET
2824 DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations),
2825#endif
2826 REG("environ", S_IRUSR, proc_environ_operations),
2827 INF("auxv", S_IRUSR, proc_pid_auxv),
2828 ONE("status", S_IRUGO, proc_pid_status),
2829 ONE("personality", S_IRUGO, proc_pid_personality),
2830 INF("limits", S_IRUGO, proc_pid_limits),

--- 332 unchanged lines hidden (view full) ---

3163}
3164
3165/*
3166 * Tasks
3167 */
3168static const struct pid_entry tid_base_stuff[] = {
3169 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
3170 DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
2769#ifdef CONFIG_NET
2770 DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations),
2771#endif
2772 REG("environ", S_IRUSR, proc_environ_operations),
2773 INF("auxv", S_IRUSR, proc_pid_auxv),
2774 ONE("status", S_IRUGO, proc_pid_status),
2775 ONE("personality", S_IRUGO, proc_pid_personality),
2776 INF("limits", S_IRUGO, proc_pid_limits),

--- 332 unchanged lines hidden (view full) ---

3109}
3110
3111/*
3112 * Tasks
3113 */
3114static const struct pid_entry tid_base_stuff[] = {
3115 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
3116 DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
3117 DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
3171 REG("environ", S_IRUSR, proc_environ_operations),
3172 INF("auxv", S_IRUSR, proc_pid_auxv),
3173 ONE("status", S_IRUGO, proc_pid_status),
3174 ONE("personality", S_IRUGO, proc_pid_personality),
3175 INF("limits", S_IRUGO, proc_pid_limits),
3176#ifdef CONFIG_SCHED_DEBUG
3177 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
3178#endif

--- 312 unchanged lines hidden ---
3118 REG("environ", S_IRUSR, proc_environ_operations),
3119 INF("auxv", S_IRUSR, proc_pid_auxv),
3120 ONE("status", S_IRUGO, proc_pid_status),
3121 ONE("personality", S_IRUGO, proc_pid_personality),
3122 INF("limits", S_IRUGO, proc_pid_limits),
3123#ifdef CONFIG_SCHED_DEBUG
3124 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
3125#endif

--- 312 unchanged lines hidden ---