Blame view
fs/proc_namespace.c
8.13 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
0226f4923 vfs: take /proc/*... |
2 3 4 5 6 7 8 9 10 11 12 13 |
/* * fs/proc_namespace.c - handling of /proc/<pid>/{mounts,mountinfo,mountstats} * * In fact, that's a piece of procfs; it's *almost* isolated from * the rest of fs/proc, but has rather close relationships with * fs/namespace.c, thus here instead of fs/proc * */ #include <linux/mnt_namespace.h> #include <linux/nsproxy.h> #include <linux/security.h> #include <linux/fs_struct.h> |
f719ff9bc sched/headers: Pr... |
14 |
#include <linux/sched/task.h> |
0226f4923 vfs: take /proc/*... |
15 16 17 18 |
#include "proc/internal.h" /* only for get_proc_task() in ->open() */ #include "pnode.h" #include "internal.h" |
076ccb76e fs: annotate ->po... |
19 |
static __poll_t mounts_poll(struct file *file, poll_table *wait) |
0226f4923 vfs: take /proc/*... |
20 |
{ |
ede1bf0dc fs: use seq_open_... |
21 22 |
struct seq_file *m = file->private_data; struct proc_mounts *p = m->private; |
0226f4923 vfs: take /proc/*... |
23 |
struct mnt_namespace *ns = p->ns; |
a9a08845e vfs: do bulk POLL... |
24 |
__poll_t res = EPOLLIN | EPOLLRDNORM; |
aab407fc5 don't bother with... |
25 |
int event; |
0226f4923 vfs: take /proc/*... |
26 27 |
poll_wait(file, &p->ns->poll, wait); |
6aa7de059 locking/atomics: ... |
28 |
event = READ_ONCE(ns->event); |
ede1bf0dc fs: use seq_open_... |
29 30 |
if (m->poll_event != event) { m->poll_event = event; |
a9a08845e vfs: do bulk POLL... |
31 |
res |= EPOLLERR | EPOLLPRI; |
0226f4923 vfs: take /proc/*... |
32 |
} |
0226f4923 vfs: take /proc/*... |
33 34 35 |
return res; } |
1e88c4201 proc: rename stru... |
36 |
struct proc_fs_opts { |
0226f4923 vfs: take /proc/*... |
37 38 39 40 41 42 |
int flag; const char *str; }; static int show_sb_opts(struct seq_file *m, struct super_block *sb) { |
1e88c4201 proc: rename stru... |
43 |
static const struct proc_fs_opts fs_opts[] = { |
1751e8a6c Rename superblock... |
44 45 46 47 |
{ SB_SYNCHRONOUS, ",sync" }, { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, |
0226f4923 vfs: take /proc/*... |
48 49 |
{ 0, NULL } }; |
1e88c4201 proc: rename stru... |
50 |
const struct proc_fs_opts *fs_infop; |
0226f4923 vfs: take /proc/*... |
51 |
|
1e88c4201 proc: rename stru... |
52 |
for (fs_infop = fs_opts; fs_infop->flag; fs_infop++) { |
0226f4923 vfs: take /proc/*... |
53 54 55 56 57 58 59 60 61 |
if (sb->s_flags & fs_infop->flag) seq_puts(m, fs_infop->str); } return security_sb_show_options(m, sb); } static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) { |
1e88c4201 proc: rename stru... |
62 |
static const struct proc_fs_opts mnt_opts[] = { |
0226f4923 vfs: take /proc/*... |
63 64 65 66 67 68 |
{ MNT_NOSUID, ",nosuid" }, { MNT_NODEV, ",nodev" }, { MNT_NOEXEC, ",noexec" }, { MNT_NOATIME, ",noatime" }, { MNT_NODIRATIME, ",nodiratime" }, { MNT_RELATIME, ",relatime" }, |
dab741e0e Add a "nosymfollo... |
69 |
{ MNT_NOSYMFOLLOW, ",nosymfollow" }, |
0226f4923 vfs: take /proc/*... |
70 71 |
{ 0, NULL } }; |
1e88c4201 proc: rename stru... |
72 |
const struct proc_fs_opts *fs_infop; |
0226f4923 vfs: take /proc/*... |
73 |
|
1e88c4201 proc: rename stru... |
74 |
for (fs_infop = mnt_opts; fs_infop->flag; fs_infop++) { |
0226f4923 vfs: take /proc/*... |
75 76 77 |
if (mnt->mnt_flags & fs_infop->flag) seq_puts(m, fs_infop->str); } |
9caccd415 fs: introduce MOU... |
78 |
|
b3679e8b5 fs: add is_idmapp... |
79 |
if (is_idmapped_mnt(mnt)) |
9caccd415 fs: introduce MOU... |
80 |
seq_puts(m, ",idmapped"); |
0226f4923 vfs: take /proc/*... |
81 82 83 84 85 86 87 88 89 90 91 |
} static inline void mangle(struct seq_file *m, const char *s) { seq_escape(m, s, " \t \\"); } static void show_type(struct seq_file *m, struct super_block *sb) { mangle(m, sb->s_type->name); |
c7eb68696 vfs: subtype hand... |
92 |
if (sb->s_subtype) { |
0226f4923 vfs: take /proc/*... |
93 94 95 96 97 98 99 |
seq_putc(m, '.'); mangle(m, sb->s_subtype); } } static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt) { |
ede1bf0dc fs: use seq_open_... |
100 |
struct proc_mounts *p = m->private; |
0226f4923 vfs: take /proc/*... |
101 |
struct mount *r = real_mount(mnt); |
0226f4923 vfs: take /proc/*... |
102 |
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; |
d861c630e vfs: switch ->sho... |
103 |
struct super_block *sb = mnt_path.dentry->d_sb; |
5d9f3c7b6 vfs: show_vfsmnt:... |
104 |
int err; |
0226f4923 vfs: take /proc/*... |
105 |
|
d861c630e vfs: switch ->sho... |
106 107 |
if (sb->s_op->show_devname) { err = sb->s_op->show_devname(m, mnt_path.dentry); |
0226f4923 vfs: take /proc/*... |
108 109 110 111 112 113 |
if (err) goto out; } else { mangle(m, r->mnt_devname ? r->mnt_devname : "none"); } seq_putc(m, ' '); |
9d4d65748 vfs: make mounts ... |
114 115 116 117 118 |
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */ err = seq_path_root(m, &mnt_path, &p->root, " \t \\"); if (err) goto out; |
0226f4923 vfs: take /proc/*... |
119 |
seq_putc(m, ' '); |
d861c630e vfs: switch ->sho... |
120 |
show_type(m, sb); |
0226f4923 vfs: take /proc/*... |
121 |
seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); |
d861c630e vfs: switch ->sho... |
122 |
err = show_sb_opts(m, sb); |
0226f4923 vfs: take /proc/*... |
123 124 125 |
if (err) goto out; show_mnt_opts(m, mnt); |
d861c630e vfs: switch ->sho... |
126 |
if (sb->s_op->show_options) |
34c80b1d9 vfs: switch ->sho... |
127 |
err = sb->s_op->show_options(m, mnt_path.dentry); |
0226f4923 vfs: take /proc/*... |
128 129 130 131 132 133 134 135 |
seq_puts(m, " 0 0 "); out: return err; } static int show_mountinfo(struct seq_file *m, struct vfsmount *mnt) { |
ede1bf0dc fs: use seq_open_... |
136 |
struct proc_mounts *p = m->private; |
0226f4923 vfs: take /proc/*... |
137 138 139 |
struct mount *r = real_mount(mnt); struct super_block *sb = mnt->mnt_sb; struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; |
6ce4bca0a vfs: show_mountin... |
140 |
int err; |
0226f4923 vfs: take /proc/*... |
141 142 143 |
seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id, MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
6ce4bca0a vfs: show_mountin... |
144 |
if (sb->s_op->show_path) { |
a6322de67 vfs: switch ->sho... |
145 |
err = sb->s_op->show_path(m, mnt->mnt_root); |
6ce4bca0a vfs: show_mountin... |
146 147 148 |
if (err) goto out; } else { |
0226f4923 vfs: take /proc/*... |
149 150 |
seq_dentry(m, mnt->mnt_root, " \t \\"); |
6ce4bca0a vfs: show_mountin... |
151 |
} |
0226f4923 vfs: take /proc/*... |
152 153 154 |
seq_putc(m, ' '); /* mountpoints outside of chroot jail will give SEQ_SKIP on this */ |
9ad4dc4f7 vfs: cleanup show... |
155 156 |
err = seq_path_root(m, &mnt_path, &p->root, " \t \\"); |
0226f4923 vfs: take /proc/*... |
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
if (err) goto out; seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); show_mnt_opts(m, mnt); /* Tagged fields ("foo:X" or "bar") */ if (IS_MNT_SHARED(r)) seq_printf(m, " shared:%i", r->mnt_group_id); if (IS_MNT_SLAVE(r)) { int master = r->mnt_master->mnt_group_id; int dom = get_dominating_id(r, &p->root); seq_printf(m, " master:%i", master); if (dom && dom != master) seq_printf(m, " propagate_from:%i", dom); } if (IS_MNT_UNBINDABLE(r)) seq_puts(m, " unbindable"); /* Filesystem specific data */ seq_puts(m, " - "); show_type(m, sb); seq_putc(m, ' '); |
6ce4bca0a vfs: show_mountin... |
180 |
if (sb->s_op->show_devname) { |
d861c630e vfs: switch ->sho... |
181 |
err = sb->s_op->show_devname(m, mnt->mnt_root); |
6ce4bca0a vfs: show_mountin... |
182 183 184 |
if (err) goto out; } else { |
0226f4923 vfs: take /proc/*... |
185 |
mangle(m, r->mnt_devname ? r->mnt_devname : "none"); |
6ce4bca0a vfs: show_mountin... |
186 |
} |
bc98a42c1 VFS: Convert sb->... |
187 |
seq_puts(m, sb_rdonly(sb) ? " ro" : " rw"); |
0226f4923 vfs: take /proc/*... |
188 189 190 191 |
err = show_sb_opts(m, sb); if (err) goto out; if (sb->s_op->show_options) |
34c80b1d9 vfs: switch ->sho... |
192 |
err = sb->s_op->show_options(m, mnt->mnt_root); |
0226f4923 vfs: take /proc/*... |
193 194 195 196 197 198 199 200 |
seq_putc(m, ' '); out: return err; } static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt) { |
ede1bf0dc fs: use seq_open_... |
201 |
struct proc_mounts *p = m->private; |
0226f4923 vfs: take /proc/*... |
202 203 |
struct mount *r = real_mount(mnt); struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; |
64132379d vfs: switch ->sho... |
204 |
struct super_block *sb = mnt_path.dentry->d_sb; |
b896fb35c vfs: show_vfsstat... |
205 |
int err; |
0226f4923 vfs: take /proc/*... |
206 207 |
/* device */ |
64132379d vfs: switch ->sho... |
208 |
if (sb->s_op->show_devname) { |
0226f4923 vfs: take /proc/*... |
209 |
seq_puts(m, "device "); |
d861c630e vfs: switch ->sho... |
210 |
err = sb->s_op->show_devname(m, mnt_path.dentry); |
5f8d498d4 vfs: show_vfsstat... |
211 212 |
if (err) goto out; |
0226f4923 vfs: take /proc/*... |
213 214 215 216 217 218 219 220 221 222 |
} else { if (r->mnt_devname) { seq_puts(m, "device "); mangle(m, r->mnt_devname); } else seq_puts(m, "no device"); } /* mount point */ seq_puts(m, " mounted on "); |
9d4d65748 vfs: make mounts ... |
223 224 225 226 227 |
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */ err = seq_path_root(m, &mnt_path, &p->root, " \t \\"); if (err) goto out; |
0226f4923 vfs: take /proc/*... |
228 229 230 231 |
seq_putc(m, ' '); /* file system type */ seq_puts(m, "with fstype "); |
64132379d vfs: switch ->sho... |
232 |
show_type(m, sb); |
0226f4923 vfs: take /proc/*... |
233 234 |
/* optional statistics */ |
64132379d vfs: switch ->sho... |
235 |
if (sb->s_op->show_stats) { |
0226f4923 vfs: take /proc/*... |
236 |
seq_putc(m, ' '); |
b896fb35c vfs: show_vfsstat... |
237 |
err = sb->s_op->show_stats(m, mnt_path.dentry); |
0226f4923 vfs: take /proc/*... |
238 239 240 241 |
} seq_putc(m, ' '); |
9d4d65748 vfs: make mounts ... |
242 |
out: |
0226f4923 vfs: take /proc/*... |
243 244 245 246 247 248 249 250 251 252 253 |
return err; } static int mounts_open_common(struct inode *inode, struct file *file, int (*show)(struct seq_file *, struct vfsmount *)) { struct task_struct *task = get_proc_task(inode); struct nsproxy *nsp; struct mnt_namespace *ns = NULL; struct path root; struct proc_mounts *p; |
ede1bf0dc fs: use seq_open_... |
254 |
struct seq_file *m; |
0226f4923 vfs: take /proc/*... |
255 256 257 258 |
int ret = -EINVAL; if (!task) goto err; |
728dba3a3 namespaces: Use t... |
259 260 |
task_lock(task); nsp = task->nsproxy; |
3d93116ce fs/proc_namespace... |
261 |
if (!nsp || !nsp->mnt_ns) { |
728dba3a3 namespaces: Use t... |
262 |
task_unlock(task); |
0226f4923 vfs: take /proc/*... |
263 264 265 266 |
put_task_struct(task); goto err; } ns = nsp->mnt_ns; |
0226f4923 vfs: take /proc/*... |
267 |
get_mnt_ns(ns); |
0226f4923 vfs: take /proc/*... |
268 269 270 271 272 273 274 275 276 |
if (!task->fs) { task_unlock(task); put_task_struct(task); ret = -ENOENT; goto err_put_ns; } get_fs_root(task->fs, &root); task_unlock(task); put_task_struct(task); |
ede1bf0dc fs: use seq_open_... |
277 278 |
ret = seq_open_private(file, &mounts_op, sizeof(struct proc_mounts)); if (ret) |
0226f4923 vfs: take /proc/*... |
279 |
goto err_put_path; |
ede1bf0dc fs: use seq_open_... |
280 281 |
m = file->private_data; m->poll_event = ns->event; |
0226f4923 vfs: take /proc/*... |
282 |
|
ede1bf0dc fs: use seq_open_... |
283 |
p = m->private; |
0226f4923 vfs: take /proc/*... |
284 285 |
p->ns = ns; p->root = root; |
0226f4923 vfs: take /proc/*... |
286 |
p->show = show; |
9f6c61f96 proc/mounts: add ... |
287 288 |
INIT_LIST_HEAD(&p->cursor.mnt_list); p->cursor.mnt.mnt_flags = MNT_CURSOR; |
0226f4923 vfs: take /proc/*... |
289 290 |
return 0; |
0226f4923 vfs: take /proc/*... |
291 292 293 294 295 296 297 298 299 300 |
err_put_path: path_put(&root); err_put_ns: put_mnt_ns(ns); err: return ret; } static int mounts_release(struct inode *inode, struct file *file) { |
ede1bf0dc fs: use seq_open_... |
301 302 |
struct seq_file *m = file->private_data; struct proc_mounts *p = m->private; |
0226f4923 vfs: take /proc/*... |
303 |
path_put(&p->root); |
9f6c61f96 proc/mounts: add ... |
304 |
mnt_cursor_del(p->ns, &p->cursor); |
0226f4923 vfs: take /proc/*... |
305 |
put_mnt_ns(p->ns); |
ede1bf0dc fs: use seq_open_... |
306 |
return seq_release_private(inode, file); |
0226f4923 vfs: take /proc/*... |
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
} static int mounts_open(struct inode *inode, struct file *file) { return mounts_open_common(inode, file, show_vfsmnt); } static int mountinfo_open(struct inode *inode, struct file *file) { return mounts_open_common(inode, file, show_mountinfo); } static int mountstats_open(struct inode *inode, struct file *file) { return mounts_open_common(inode, file, show_vfsstat); } const struct file_operations proc_mounts_operations = { .open = mounts_open, |
14e3e989f proc mountinfo: m... |
326 327 |
.read_iter = seq_read_iter, .splice_read = generic_file_splice_read, |
0226f4923 vfs: take /proc/*... |
328 329 330 331 332 333 334 |
.llseek = seq_lseek, .release = mounts_release, .poll = mounts_poll, }; const struct file_operations proc_mountinfo_operations = { .open = mountinfo_open, |
14e3e989f proc mountinfo: m... |
335 336 |
.read_iter = seq_read_iter, .splice_read = generic_file_splice_read, |
0226f4923 vfs: take /proc/*... |
337 338 339 340 341 342 343 |
.llseek = seq_lseek, .release = mounts_release, .poll = mounts_poll, }; const struct file_operations proc_mountstats_operations = { .open = mountstats_open, |
14e3e989f proc mountinfo: m... |
344 345 |
.read_iter = seq_read_iter, .splice_read = generic_file_splice_read, |
0226f4923 vfs: take /proc/*... |
346 347 348 |
.llseek = seq_lseek, .release = mounts_release, }; |