diff options
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 105 |
1 files changed, 45 insertions, 60 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 0016350ad95e..1485e38daaa3 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -1686,41 +1686,29 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx, | |||
1686 | instantiate_t instantiate, struct task_struct *task, const void *ptr) | 1686 | instantiate_t instantiate, struct task_struct *task, const void *ptr) |
1687 | { | 1687 | { |
1688 | struct dentry *child, *dir = file->f_path.dentry; | 1688 | struct dentry *child, *dir = file->f_path.dentry; |
1689 | struct qstr qname = QSTR_INIT(name, len); | ||
1689 | struct inode *inode; | 1690 | struct inode *inode; |
1690 | struct qstr qname; | 1691 | unsigned type; |
1691 | ino_t ino = 0; | 1692 | ino_t ino; |
1692 | unsigned type = DT_UNKNOWN; | ||
1693 | 1693 | ||
1694 | qname.name = name; | 1694 | child = d_hash_and_lookup(dir, &qname); |
1695 | qname.len = len; | ||
1696 | qname.hash = full_name_hash(name, len); | ||
1697 | |||
1698 | child = d_lookup(dir, &qname); | ||
1699 | if (!child) { | 1695 | if (!child) { |
1700 | struct dentry *new; | 1696 | child = d_alloc(dir, &qname); |
1701 | new = d_alloc(dir, &qname); | 1697 | if (!child) |
1702 | if (new) { | 1698 | goto end_instantiate; |
1703 | child = instantiate(dir->d_inode, new, task, ptr); | 1699 | if (instantiate(dir->d_inode, child, task, ptr) < 0) { |
1704 | if (child) | 1700 | dput(child); |
1705 | dput(new); | 1701 | goto end_instantiate; |
1706 | else | ||
1707 | child = new; | ||
1708 | } | 1702 | } |
1709 | } | 1703 | } |
1710 | if (!child || IS_ERR(child) || !child->d_inode) | ||
1711 | goto end_instantiate; | ||
1712 | inode = child->d_inode; | 1704 | inode = child->d_inode; |
1713 | if (inode) { | 1705 | ino = inode->i_ino; |
1714 | ino = inode->i_ino; | 1706 | type = inode->i_mode >> 12; |
1715 | type = inode->i_mode >> 12; | ||
1716 | } | ||
1717 | dput(child); | 1707 | dput(child); |
1718 | end_instantiate: | ||
1719 | if (!ino) | ||
1720 | ino = find_inode_number(dir, &qname); | ||
1721 | if (!ino) | ||
1722 | ino = 1; | ||
1723 | return dir_emit(ctx, name, len, ino, type); | 1708 | return dir_emit(ctx, name, len, ino, type); |
1709 | |||
1710 | end_instantiate: | ||
1711 | return dir_emit(ctx, name, len, 1, DT_UNKNOWN); | ||
1724 | } | 1712 | } |
1725 | 1713 | ||
1726 | #ifdef CONFIG_CHECKPOINT_RESTORE | 1714 | #ifdef CONFIG_CHECKPOINT_RESTORE |
@@ -1846,7 +1834,7 @@ struct map_files_info { | |||
1846 | unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */ | 1834 | unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */ |
1847 | }; | 1835 | }; |
1848 | 1836 | ||
1849 | static struct dentry * | 1837 | static int |
1850 | proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, | 1838 | proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, |
1851 | struct task_struct *task, const void *ptr) | 1839 | struct task_struct *task, const void *ptr) |
1852 | { | 1840 | { |
@@ -1856,7 +1844,7 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, | |||
1856 | 1844 | ||
1857 | inode = proc_pid_make_inode(dir->i_sb, task); | 1845 | inode = proc_pid_make_inode(dir->i_sb, task); |
1858 | if (!inode) | 1846 | if (!inode) |
1859 | return ERR_PTR(-ENOENT); | 1847 | return -ENOENT; |
1860 | 1848 | ||
1861 | ei = PROC_I(inode); | 1849 | ei = PROC_I(inode); |
1862 | ei->op.proc_get_link = proc_map_files_get_link; | 1850 | ei->op.proc_get_link = proc_map_files_get_link; |
@@ -1873,7 +1861,7 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry, | |||
1873 | d_set_d_op(dentry, &tid_map_files_dentry_operations); | 1861 | d_set_d_op(dentry, &tid_map_files_dentry_operations); |
1874 | d_add(dentry, inode); | 1862 | d_add(dentry, inode); |
1875 | 1863 | ||
1876 | return NULL; | 1864 | return 0; |
1877 | } | 1865 | } |
1878 | 1866 | ||
1879 | static struct dentry *proc_map_files_lookup(struct inode *dir, | 1867 | static struct dentry *proc_map_files_lookup(struct inode *dir, |
@@ -1882,23 +1870,23 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, | |||
1882 | unsigned long vm_start, vm_end; | 1870 | unsigned long vm_start, vm_end; |
1883 | struct vm_area_struct *vma; | 1871 | struct vm_area_struct *vma; |
1884 | struct task_struct *task; | 1872 | struct task_struct *task; |
1885 | struct dentry *result; | 1873 | int result; |
1886 | struct mm_struct *mm; | 1874 | struct mm_struct *mm; |
1887 | 1875 | ||
1888 | result = ERR_PTR(-EPERM); | 1876 | result = -EPERM; |
1889 | if (!capable(CAP_SYS_ADMIN)) | 1877 | if (!capable(CAP_SYS_ADMIN)) |
1890 | goto out; | 1878 | goto out; |
1891 | 1879 | ||
1892 | result = ERR_PTR(-ENOENT); | 1880 | result = -ENOENT; |
1893 | task = get_proc_task(dir); | 1881 | task = get_proc_task(dir); |
1894 | if (!task) | 1882 | if (!task) |
1895 | goto out; | 1883 | goto out; |
1896 | 1884 | ||
1897 | result = ERR_PTR(-EACCES); | 1885 | result = -EACCES; |
1898 | if (!ptrace_may_access(task, PTRACE_MODE_READ)) | 1886 | if (!ptrace_may_access(task, PTRACE_MODE_READ)) |
1899 | goto out_put_task; | 1887 | goto out_put_task; |
1900 | 1888 | ||
1901 | result = ERR_PTR(-ENOENT); | 1889 | result = -ENOENT; |
1902 | if (dname_to_vma_addr(dentry, &vm_start, &vm_end)) | 1890 | if (dname_to_vma_addr(dentry, &vm_start, &vm_end)) |
1903 | goto out_put_task; | 1891 | goto out_put_task; |
1904 | 1892 | ||
@@ -1921,7 +1909,7 @@ out_no_vma: | |||
1921 | out_put_task: | 1909 | out_put_task: |
1922 | put_task_struct(task); | 1910 | put_task_struct(task); |
1923 | out: | 1911 | out: |
1924 | return result; | 1912 | return ERR_PTR(result); |
1925 | } | 1913 | } |
1926 | 1914 | ||
1927 | static const struct inode_operations proc_map_files_inode_operations = { | 1915 | static const struct inode_operations proc_map_files_inode_operations = { |
@@ -2135,13 +2123,12 @@ static const struct file_operations proc_timers_operations = { | |||
2135 | }; | 2123 | }; |
2136 | #endif /* CONFIG_CHECKPOINT_RESTORE */ | 2124 | #endif /* CONFIG_CHECKPOINT_RESTORE */ |
2137 | 2125 | ||
2138 | static struct dentry *proc_pident_instantiate(struct inode *dir, | 2126 | static int proc_pident_instantiate(struct inode *dir, |
2139 | struct dentry *dentry, struct task_struct *task, const void *ptr) | 2127 | struct dentry *dentry, struct task_struct *task, const void *ptr) |
2140 | { | 2128 | { |
2141 | const struct pid_entry *p = ptr; | 2129 | const struct pid_entry *p = ptr; |
2142 | struct inode *inode; | 2130 | struct inode *inode; |
2143 | struct proc_inode *ei; | 2131 | struct proc_inode *ei; |
2144 | struct dentry *error = ERR_PTR(-ENOENT); | ||
2145 | 2132 | ||
2146 | inode = proc_pid_make_inode(dir->i_sb, task); | 2133 | inode = proc_pid_make_inode(dir->i_sb, task); |
2147 | if (!inode) | 2134 | if (!inode) |
@@ -2160,9 +2147,9 @@ static struct dentry *proc_pident_instantiate(struct inode *dir, | |||
2160 | d_add(dentry, inode); | 2147 | d_add(dentry, inode); |
2161 | /* Close the race of the process dying before we return the dentry */ | 2148 | /* Close the race of the process dying before we return the dentry */ |
2162 | if (pid_revalidate(dentry, 0)) | 2149 | if (pid_revalidate(dentry, 0)) |
2163 | error = NULL; | 2150 | return 0; |
2164 | out: | 2151 | out: |
2165 | return error; | 2152 | return -ENOENT; |
2166 | } | 2153 | } |
2167 | 2154 | ||
2168 | static struct dentry *proc_pident_lookup(struct inode *dir, | 2155 | static struct dentry *proc_pident_lookup(struct inode *dir, |
@@ -2170,11 +2157,11 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
2170 | const struct pid_entry *ents, | 2157 | const struct pid_entry *ents, |
2171 | unsigned int nents) | 2158 | unsigned int nents) |
2172 | { | 2159 | { |
2173 | struct dentry *error; | 2160 | int error; |
2174 | struct task_struct *task = get_proc_task(dir); | 2161 | struct task_struct *task = get_proc_task(dir); |
2175 | const struct pid_entry *p, *last; | 2162 | const struct pid_entry *p, *last; |
2176 | 2163 | ||
2177 | error = ERR_PTR(-ENOENT); | 2164 | error = -ENOENT; |
2178 | 2165 | ||
2179 | if (!task) | 2166 | if (!task) |
2180 | goto out_no_task; | 2167 | goto out_no_task; |
@@ -2197,7 +2184,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
2197 | out: | 2184 | out: |
2198 | put_task_struct(task); | 2185 | put_task_struct(task); |
2199 | out_no_task: | 2186 | out_no_task: |
2200 | return error; | 2187 | return ERR_PTR(error); |
2201 | } | 2188 | } |
2202 | 2189 | ||
2203 | static int proc_pident_readdir(struct file *file, struct dir_context *ctx, | 2190 | static int proc_pident_readdir(struct file *file, struct dir_context *ctx, |
@@ -2780,11 +2767,10 @@ void proc_flush_task(struct task_struct *task) | |||
2780 | } | 2767 | } |
2781 | } | 2768 | } |
2782 | 2769 | ||
2783 | static struct dentry *proc_pid_instantiate(struct inode *dir, | 2770 | static int proc_pid_instantiate(struct inode *dir, |
2784 | struct dentry * dentry, | 2771 | struct dentry * dentry, |
2785 | struct task_struct *task, const void *ptr) | 2772 | struct task_struct *task, const void *ptr) |
2786 | { | 2773 | { |
2787 | struct dentry *error = ERR_PTR(-ENOENT); | ||
2788 | struct inode *inode; | 2774 | struct inode *inode; |
2789 | 2775 | ||
2790 | inode = proc_pid_make_inode(dir->i_sb, task); | 2776 | inode = proc_pid_make_inode(dir->i_sb, task); |
@@ -2804,14 +2790,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir, | |||
2804 | d_add(dentry, inode); | 2790 | d_add(dentry, inode); |
2805 | /* Close the race of the process dying before we return the dentry */ | 2791 | /* Close the race of the process dying before we return the dentry */ |
2806 | if (pid_revalidate(dentry, 0)) | 2792 | if (pid_revalidate(dentry, 0)) |
2807 | error = NULL; | 2793 | return 0; |
2808 | out: | 2794 | out: |
2809 | return error; | 2795 | return -ENOENT; |
2810 | } | 2796 | } |
2811 | 2797 | ||
2812 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) | 2798 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
2813 | { | 2799 | { |
2814 | struct dentry *result = NULL; | 2800 | int result = 0; |
2815 | struct task_struct *task; | 2801 | struct task_struct *task; |
2816 | unsigned tgid; | 2802 | unsigned tgid; |
2817 | struct pid_namespace *ns; | 2803 | struct pid_namespace *ns; |
@@ -2832,7 +2818,7 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign | |||
2832 | result = proc_pid_instantiate(dir, dentry, task, NULL); | 2818 | result = proc_pid_instantiate(dir, dentry, task, NULL); |
2833 | put_task_struct(task); | 2819 | put_task_struct(task); |
2834 | out: | 2820 | out: |
2835 | return result; | 2821 | return ERR_PTR(result); |
2836 | } | 2822 | } |
2837 | 2823 | ||
2838 | /* | 2824 | /* |
@@ -2884,21 +2870,21 @@ retry: | |||
2884 | int proc_pid_readdir(struct file *file, struct dir_context *ctx) | 2870 | int proc_pid_readdir(struct file *file, struct dir_context *ctx) |
2885 | { | 2871 | { |
2886 | struct tgid_iter iter; | 2872 | struct tgid_iter iter; |
2887 | struct pid_namespace *ns; | 2873 | struct pid_namespace *ns = file->f_dentry->d_sb->s_fs_info; |
2888 | loff_t pos = ctx->pos; | 2874 | loff_t pos = ctx->pos; |
2889 | 2875 | ||
2890 | if (pos >= PID_MAX_LIMIT + TGID_OFFSET) | 2876 | if (pos >= PID_MAX_LIMIT + TGID_OFFSET) |
2891 | return 0; | 2877 | return 0; |
2892 | 2878 | ||
2893 | if (pos == TGID_OFFSET - 1) { | 2879 | if (pos == TGID_OFFSET - 1) { |
2894 | if (!proc_fill_cache(file, ctx, "self", 4, NULL, NULL, NULL)) | 2880 | struct inode *inode = ns->proc_self->d_inode; |
2881 | if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK)) | ||
2895 | return 0; | 2882 | return 0; |
2896 | iter.tgid = 0; | 2883 | iter.tgid = 0; |
2897 | } else { | 2884 | } else { |
2898 | iter.tgid = pos - TGID_OFFSET; | 2885 | iter.tgid = pos - TGID_OFFSET; |
2899 | } | 2886 | } |
2900 | iter.task = NULL; | 2887 | iter.task = NULL; |
2901 | ns = file->f_dentry->d_sb->s_fs_info; | ||
2902 | for (iter = next_tgid(ns, iter); | 2888 | for (iter = next_tgid(ns, iter); |
2903 | iter.task; | 2889 | iter.task; |
2904 | iter.tgid += 1, iter = next_tgid(ns, iter)) { | 2890 | iter.tgid += 1, iter = next_tgid(ns, iter)) { |
@@ -3027,10 +3013,9 @@ static const struct inode_operations proc_tid_base_inode_operations = { | |||
3027 | .setattr = proc_setattr, | 3013 | .setattr = proc_setattr, |
3028 | }; | 3014 | }; |
3029 | 3015 | ||
3030 | static struct dentry *proc_task_instantiate(struct inode *dir, | 3016 | static int proc_task_instantiate(struct inode *dir, |
3031 | struct dentry *dentry, struct task_struct *task, const void *ptr) | 3017 | struct dentry *dentry, struct task_struct *task, const void *ptr) |
3032 | { | 3018 | { |
3033 | struct dentry *error = ERR_PTR(-ENOENT); | ||
3034 | struct inode *inode; | 3019 | struct inode *inode; |
3035 | inode = proc_pid_make_inode(dir->i_sb, task); | 3020 | inode = proc_pid_make_inode(dir->i_sb, task); |
3036 | 3021 | ||
@@ -3049,14 +3034,14 @@ static struct dentry *proc_task_instantiate(struct inode *dir, | |||
3049 | d_add(dentry, inode); | 3034 | d_add(dentry, inode); |
3050 | /* Close the race of the process dying before we return the dentry */ | 3035 | /* Close the race of the process dying before we return the dentry */ |
3051 | if (pid_revalidate(dentry, 0)) | 3036 | if (pid_revalidate(dentry, 0)) |
3052 | error = NULL; | 3037 | return 0; |
3053 | out: | 3038 | out: |
3054 | return error; | 3039 | return -ENOENT; |
3055 | } | 3040 | } |
3056 | 3041 | ||
3057 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) | 3042 | static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) |
3058 | { | 3043 | { |
3059 | struct dentry *result = ERR_PTR(-ENOENT); | 3044 | int result = -ENOENT; |
3060 | struct task_struct *task; | 3045 | struct task_struct *task; |
3061 | struct task_struct *leader = get_proc_task(dir); | 3046 | struct task_struct *leader = get_proc_task(dir); |
3062 | unsigned tid; | 3047 | unsigned tid; |
@@ -3086,7 +3071,7 @@ out_drop_task: | |||
3086 | out: | 3071 | out: |
3087 | put_task_struct(leader); | 3072 | put_task_struct(leader); |
3088 | out_no_task: | 3073 | out_no_task: |
3089 | return result; | 3074 | return ERR_PTR(result); |
3090 | } | 3075 | } |
3091 | 3076 | ||
3092 | /* | 3077 | /* |