diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-05-03 09:00:33 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-05-26 14:20:28 -0400 |
commit | 988363864132f86d5722dddd7f765080ef271519 (patch) | |
tree | 49407857425a7b83629bd51efde388448bbd24c7 | |
parent | 1ae9bd8b7e4912b238a14adc7c559a7ecbb9c062 (diff) |
don't bother with tid_fd_revalidate() in lookups
what we want it for is actually updating inode metadata;
take _that_ into a separate helper and use it.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/proc/fd.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/fs/proc/fd.c b/fs/proc/fd.c index d38845ecc408..f5de22a9e9e0 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c | |||
@@ -98,12 +98,27 @@ static bool tid_fd_mode(struct task_struct *task, unsigned fd, fmode_t *mode) | |||
98 | return !!file; | 98 | return !!file; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void tid_fd_update_inode(struct task_struct *task, struct inode *inode, | ||
102 | fmode_t f_mode) | ||
103 | { | ||
104 | task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid); | ||
105 | |||
106 | if (S_ISLNK(inode->i_mode)) { | ||
107 | unsigned i_mode = S_IFLNK; | ||
108 | if (f_mode & FMODE_READ) | ||
109 | i_mode |= S_IRUSR | S_IXUSR; | ||
110 | if (f_mode & FMODE_WRITE) | ||
111 | i_mode |= S_IWUSR | S_IXUSR; | ||
112 | inode->i_mode = i_mode; | ||
113 | } | ||
114 | security_task_to_inode(task, inode); | ||
115 | } | ||
116 | |||
101 | static int tid_fd_revalidate(struct dentry *dentry, unsigned int flags) | 117 | static int tid_fd_revalidate(struct dentry *dentry, unsigned int flags) |
102 | { | 118 | { |
103 | struct task_struct *task; | 119 | struct task_struct *task; |
104 | struct inode *inode; | 120 | struct inode *inode; |
105 | unsigned int fd; | 121 | unsigned int fd; |
106 | fmode_t f_mode; | ||
107 | 122 | ||
108 | if (flags & LOOKUP_RCU) | 123 | if (flags & LOOKUP_RCU) |
109 | return -ECHILD; | 124 | return -ECHILD; |
@@ -113,18 +128,9 @@ static int tid_fd_revalidate(struct dentry *dentry, unsigned int flags) | |||
113 | fd = proc_fd(inode); | 128 | fd = proc_fd(inode); |
114 | 129 | ||
115 | if (task) { | 130 | if (task) { |
131 | fmode_t f_mode; | ||
116 | if (tid_fd_mode(task, fd, &f_mode)) { | 132 | if (tid_fd_mode(task, fd, &f_mode)) { |
117 | task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid); | 133 | tid_fd_update_inode(task, inode, f_mode); |
118 | |||
119 | if (S_ISLNK(inode->i_mode)) { | ||
120 | unsigned i_mode = S_IFLNK; | ||
121 | if (f_mode & FMODE_READ) | ||
122 | i_mode |= S_IRUSR | S_IXUSR; | ||
123 | if (f_mode & FMODE_WRITE) | ||
124 | i_mode |= S_IWUSR | S_IXUSR; | ||
125 | inode->i_mode = i_mode; | ||
126 | } | ||
127 | security_task_to_inode(task, inode); | ||
128 | put_task_struct(task); | 134 | put_task_struct(task); |
129 | return 1; | 135 | return 1; |
130 | } | 136 | } |
@@ -168,34 +174,35 @@ static int proc_fd_link(struct dentry *dentry, struct path *path) | |||
168 | return ret; | 174 | return ret; |
169 | } | 175 | } |
170 | 176 | ||
177 | struct fd_data { | ||
178 | fmode_t mode; | ||
179 | unsigned fd; | ||
180 | }; | ||
181 | |||
171 | static int | 182 | static int |
172 | proc_fd_instantiate(struct inode *dir, struct dentry *dentry, | 183 | proc_fd_instantiate(struct inode *dir, struct dentry *dentry, |
173 | struct task_struct *task, const void *ptr) | 184 | struct task_struct *task, const void *ptr) |
174 | { | 185 | { |
175 | unsigned fd = (unsigned long)ptr; | 186 | const struct fd_data *data = ptr; |
176 | struct proc_inode *ei; | 187 | struct proc_inode *ei; |
177 | struct inode *inode; | 188 | struct inode *inode; |
178 | 189 | ||
179 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFLNK); | 190 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFLNK); |
180 | if (!inode) | 191 | if (!inode) |
181 | goto out; | 192 | return -ENOENT; |
182 | 193 | ||
183 | ei = PROC_I(inode); | 194 | ei = PROC_I(inode); |
184 | ei->fd = fd; | 195 | ei->fd = data->fd; |
185 | 196 | ||
186 | inode->i_op = &proc_pid_link_inode_operations; | 197 | inode->i_op = &proc_pid_link_inode_operations; |
187 | inode->i_size = 64; | 198 | inode->i_size = 64; |
188 | 199 | ||
189 | ei->op.proc_get_link = proc_fd_link; | 200 | ei->op.proc_get_link = proc_fd_link; |
201 | tid_fd_update_inode(task, inode, data->mode); | ||
190 | 202 | ||
191 | d_set_d_op(dentry, &tid_fd_dentry_operations); | 203 | d_set_d_op(dentry, &tid_fd_dentry_operations); |
192 | d_add(dentry, inode); | 204 | d_add(dentry, inode); |
193 | 205 | return 0; | |
194 | /* Close the race of the process dying before we return the dentry */ | ||
195 | if (tid_fd_revalidate(dentry, 0)) | ||
196 | return 0; | ||
197 | out: | ||
198 | return -ENOENT; | ||
199 | } | 206 | } |
200 | 207 | ||
201 | static struct dentry *proc_lookupfd_common(struct inode *dir, | 208 | static struct dentry *proc_lookupfd_common(struct inode *dir, |
@@ -204,17 +211,16 @@ static struct dentry *proc_lookupfd_common(struct inode *dir, | |||
204 | { | 211 | { |
205 | struct task_struct *task = get_proc_task(dir); | 212 | struct task_struct *task = get_proc_task(dir); |
206 | int result = -ENOENT; | 213 | int result = -ENOENT; |
207 | unsigned fd = name_to_int(&dentry->d_name); | 214 | struct fd_data data = {.fd = name_to_int(&dentry->d_name)}; |
208 | fmode_t f_mode; | ||
209 | 215 | ||
210 | if (!task) | 216 | if (!task) |
211 | goto out_no_task; | 217 | goto out_no_task; |
212 | if (fd == ~0U) | 218 | if (data.fd == ~0U) |
213 | goto out; | 219 | goto out; |
214 | if (!tid_fd_mode(task, fd, &f_mode)) | 220 | if (!tid_fd_mode(task, data.fd, &data.mode)) |
215 | goto out; | 221 | goto out; |
216 | 222 | ||
217 | result = instantiate(dir, dentry, task, (void *)(unsigned long)fd); | 223 | result = instantiate(dir, dentry, task, &data); |
218 | out: | 224 | out: |
219 | put_task_struct(task); | 225 | put_task_struct(task); |
220 | out_no_task: | 226 | out_no_task: |
@@ -241,17 +247,22 @@ static int proc_readfd_common(struct file *file, struct dir_context *ctx, | |||
241 | for (fd = ctx->pos - 2; | 247 | for (fd = ctx->pos - 2; |
242 | fd < files_fdtable(files)->max_fds; | 248 | fd < files_fdtable(files)->max_fds; |
243 | fd++, ctx->pos++) { | 249 | fd++, ctx->pos++) { |
250 | struct file *f; | ||
251 | struct fd_data data; | ||
244 | char name[10 + 1]; | 252 | char name[10 + 1]; |
245 | int len; | 253 | int len; |
246 | 254 | ||
247 | if (!fcheck_files(files, fd)) | 255 | f = fcheck_files(files, fd); |
256 | if (!f) | ||
248 | continue; | 257 | continue; |
258 | data.mode = f->f_mode; | ||
249 | rcu_read_unlock(); | 259 | rcu_read_unlock(); |
260 | data.fd = fd; | ||
250 | 261 | ||
251 | len = snprintf(name, sizeof(name), "%u", fd); | 262 | len = snprintf(name, sizeof(name), "%u", fd); |
252 | if (!proc_fill_cache(file, ctx, | 263 | if (!proc_fill_cache(file, ctx, |
253 | name, len, instantiate, p, | 264 | name, len, instantiate, p, |
254 | (void *)(unsigned long)fd)) | 265 | &data)) |
255 | goto out_fd_loop; | 266 | goto out_fd_loop; |
256 | cond_resched(); | 267 | cond_resched(); |
257 | rcu_read_lock(); | 268 | rcu_read_lock(); |
@@ -313,27 +324,23 @@ static int | |||
313 | proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry, | 324 | proc_fdinfo_instantiate(struct inode *dir, struct dentry *dentry, |
314 | struct task_struct *task, const void *ptr) | 325 | struct task_struct *task, const void *ptr) |
315 | { | 326 | { |
316 | unsigned fd = (unsigned long)ptr; | 327 | const struct fd_data *data = ptr; |
317 | struct proc_inode *ei; | 328 | struct proc_inode *ei; |
318 | struct inode *inode; | 329 | struct inode *inode; |
319 | 330 | ||
320 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFREG | S_IRUSR); | 331 | inode = proc_pid_make_inode(dir->i_sb, task, S_IFREG | S_IRUSR); |
321 | if (!inode) | 332 | if (!inode) |
322 | goto out; | 333 | return -ENOENT; |
323 | 334 | ||
324 | ei = PROC_I(inode); | 335 | ei = PROC_I(inode); |
325 | ei->fd = fd; | 336 | ei->fd = data->fd; |
326 | 337 | ||
327 | inode->i_fop = &proc_fdinfo_file_operations; | 338 | inode->i_fop = &proc_fdinfo_file_operations; |
339 | tid_fd_update_inode(task, inode, 0); | ||
328 | 340 | ||
329 | d_set_d_op(dentry, &tid_fd_dentry_operations); | 341 | d_set_d_op(dentry, &tid_fd_dentry_operations); |
330 | d_add(dentry, inode); | 342 | d_add(dentry, inode); |
331 | 343 | return 0; | |
332 | /* Close the race of the process dying before we return the dentry */ | ||
333 | if (tid_fd_revalidate(dentry, 0)) | ||
334 | return 0; | ||
335 | out: | ||
336 | return -ENOENT; | ||
337 | } | 344 | } |
338 | 345 | ||
339 | static struct dentry * | 346 | static struct dentry * |