Skip to content

Commit cbd76ed

Browse files
committed
Merge tag 'pull-18-rc1-work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull mount handling updates from Al Viro: "Cleanups (and one fix) around struct mount handling. The fix is usermode_driver.c one - once you've done kern_mount(), you must kern_unmount(); simple mntput() will end up with a leak. Several failure exits in there messed up that way... In practice you won't hit those particular failure exits without fault injection, though" * tag 'pull-18-rc1-work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: move mount-related externs from fs.h to mount.h blob_to_mnt(): kern_unmount() is needed to undo kern_mount() m->mnt_root->d_inode->i_sb is a weird way to spell m->mnt_sb... linux/mount.h: trim includes uninline may_mount() and don't opencode it in fspick(2)/fsopen(2)
2 parents dbe0ee4 + 70f8d9c commit cbd76ed

File tree

9 files changed

+27
-30
lines changed

9 files changed

+27
-30
lines changed

arch/alpha/kernel/osf_sys.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/types.h>
3737
#include <linux/ipc.h>
3838
#include <linux/namei.h>
39+
#include <linux/mount.h>
3940
#include <linux/uio.h>
4041
#include <linux/vfs.h>
4142
#include <linux/rcupdate.h>

fs/fsopen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags)
119119
const char *fs_name;
120120
int ret;
121121

122-
if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
122+
if (!may_mount())
123123
return -EPERM;
124124

125125
if (flags & ~FSOPEN_CLOEXEC)
@@ -162,7 +162,7 @@ SYSCALL_DEFINE3(fspick, int, dfd, const char __user *, path, unsigned int, flags
162162
unsigned int lookup_flags;
163163
int ret;
164164

165-
if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
165+
if (!may_mount())
166166
return -EPERM;
167167

168168
if ((flags & ~(FSPICK_CLOEXEC |

fs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern int __mnt_want_write_file(struct file *);
8484
extern void __mnt_drop_write_file(struct file *);
8585

8686
extern void dissolve_on_fput(struct vfsmount *);
87+
extern bool may_mount(void);
8788

8889
int path_mount(const char *dev_name, struct path *path,
8990
const char *type_page, unsigned long flags, void *data_page);

fs/namespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ void __detach_mounts(struct dentry *dentry)
17601760
/*
17611761
* Is the caller allowed to modify his namespace?
17621762
*/
1763-
static inline bool may_mount(void)
1763+
bool may_mount(void)
17641764
{
17651765
return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
17661766
}

fs/nfs/nfs4file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static struct file *__nfs42_ssc_open(struct vfsmount *ss_mnt,
328328
char *read_name = NULL;
329329
int len, status = 0;
330330

331-
server = NFS_SERVER(ss_mnt->mnt_root->d_inode);
331+
server = NFS_SB(ss_mnt->mnt_sb);
332332

333333
if (!fattr)
334334
return ERR_PTR(-ENOMEM);
@@ -346,7 +346,7 @@ static struct file *__nfs42_ssc_open(struct vfsmount *ss_mnt,
346346
goto out;
347347
snprintf(read_name, len, SSC_READ_NAME_BODY, read_name_gen++);
348348

349-
r_ino = nfs_fhget(ss_mnt->mnt_root->d_inode->i_sb, src_fh, fattr);
349+
r_ino = nfs_fhget(ss_mnt->mnt_sb, src_fh, fattr);
350350
if (IS_ERR(r_ino)) {
351351
res = ERR_CAST(r_ino);
352352
goto out_free_name;

include/linux/fs.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,22 +2469,11 @@ struct super_block *sget(struct file_system_type *type,
24692469

24702470
extern int register_filesystem(struct file_system_type *);
24712471
extern int unregister_filesystem(struct file_system_type *);
2472-
extern struct vfsmount *kern_mount(struct file_system_type *);
2473-
extern void kern_unmount(struct vfsmount *mnt);
2474-
extern int may_umount_tree(struct vfsmount *);
2475-
extern int may_umount(struct vfsmount *);
2476-
extern long do_mount(const char *, const char __user *,
2477-
const char *, unsigned long, void *);
2478-
extern struct vfsmount *collect_mounts(const struct path *);
2479-
extern void drop_collected_mounts(struct vfsmount *);
2480-
extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
2481-
struct vfsmount *);
24822472
extern int vfs_statfs(const struct path *, struct kstatfs *);
24832473
extern int user_statfs(const char __user *, struct kstatfs *);
24842474
extern int fd_statfs(int, struct kstatfs *);
24852475
extern int freeze_super(struct super_block *super);
24862476
extern int thaw_super(struct super_block *super);
2487-
extern bool our_mnt(struct vfsmount *mnt);
24882477
extern __printf(2, 3)
24892478
int super_setup_bdi_name(struct super_block *sb, char *fmt, ...);
24902479
extern int super_setup_bdi(struct super_block *sb);

include/linux/mount.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
#define _LINUX_MOUNT_H
1212

1313
#include <linux/types.h>
14-
#include <linux/list.h>
15-
#include <linux/nodemask.h>
16-
#include <linux/spinlock.h>
17-
#include <linux/seqlock.h>
18-
#include <linux/atomic.h>
14+
#include <asm/barrier.h>
1915

2016
struct super_block;
21-
struct vfsmount;
2217
struct dentry;
23-
struct mnt_namespace;
18+
struct user_namespace;
19+
struct file_system_type;
2420
struct fs_context;
21+
struct file;
22+
struct path;
2523

2624
#define MNT_NOSUID 0x01
2725
#define MNT_NODEV 0x02
@@ -81,9 +79,6 @@ static inline struct user_namespace *mnt_user_ns(const struct vfsmount *mnt)
8179
return smp_load_acquire(&mnt->mnt_userns);
8280
}
8381

84-
struct file; /* forward dec */
85-
struct path;
86-
8782
extern int mnt_want_write(struct vfsmount *mnt);
8883
extern int mnt_want_write_file(struct file *file);
8984
extern void mnt_drop_write(struct vfsmount *mnt);
@@ -94,12 +89,10 @@ extern struct vfsmount *mnt_clone_internal(const struct path *path);
9489
extern bool __mnt_is_readonly(struct vfsmount *mnt);
9590
extern bool mnt_may_suid(struct vfsmount *mnt);
9691

97-
struct path;
9892
extern struct vfsmount *clone_private_mount(const struct path *path);
9993
extern int __mnt_want_write(struct vfsmount *);
10094
extern void __mnt_drop_write(struct vfsmount *);
10195

102-
struct file_system_type;
10396
extern struct vfsmount *fc_mount(struct fs_context *fc);
10497
extern struct vfsmount *vfs_create_mount(struct fs_context *fc);
10598
extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
@@ -115,6 +108,18 @@ extern void mark_mounts_for_expiry(struct list_head *mounts);
115108
extern dev_t name_to_dev_t(const char *name);
116109
extern bool path_is_mountpoint(const struct path *path);
117110

111+
extern bool our_mnt(struct vfsmount *mnt);
112+
113+
extern struct vfsmount *kern_mount(struct file_system_type *);
114+
extern void kern_unmount(struct vfsmount *mnt);
115+
extern int may_umount_tree(struct vfsmount *);
116+
extern int may_umount(struct vfsmount *);
117+
extern long do_mount(const char *, const char __user *,
118+
const char *, unsigned long, void *);
119+
extern struct vfsmount *collect_mounts(const struct path *);
120+
extern void drop_collected_mounts(struct vfsmount *);
121+
extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
122+
struct vfsmount *);
118123
extern void kern_unmount_array(struct vfsmount *mnt[], unsigned int num);
119124

120125
#endif /* _LINUX_MOUNT_H */

kernel/usermode_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static struct vfsmount *blob_to_mnt(const void *data, size_t len, const char *na
2828

2929
file = file_open_root_mnt(mnt, name, O_CREAT | O_WRONLY, 0700);
3030
if (IS_ERR(file)) {
31-
mntput(mnt);
31+
kern_unmount(mnt);
3232
return ERR_CAST(file);
3333
}
3434

@@ -38,7 +38,7 @@ static struct vfsmount *blob_to_mnt(const void *data, size_t len, const char *na
3838
if (err >= 0)
3939
err = -ENOMEM;
4040
filp_close(file, NULL);
41-
mntput(mnt);
41+
kern_unmount(mnt);
4242
return ERR_PTR(err);
4343
}
4444

security/smack/smackfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/ctype.h>
2424
#include <linux/audit.h>
2525
#include <linux/magic.h>
26+
#include <linux/mount.h>
2627
#include <linux/fs_context.h>
2728
#include "smack.h"
2829

0 commit comments

Comments
 (0)