Skip to content

Commit 505b050

Browse files
committed
Merge branch 'mount.part1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs mount API prep from Al Viro: "Mount API prereqs. Mostly that's LSM mount options cleanups. There are several minor fixes in there, but nothing earth-shattering (leaks on failure exits, mostly)" * 'mount.part1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (27 commits) mount_fs: suppress MAC on MS_SUBMOUNT as well as MS_KERNMOUNT smack: rewrite smack_sb_eat_lsm_opts() smack: get rid of match_token() smack: take the guts of smack_parse_opts_str() into a new helper LSM: new method: ->sb_add_mnt_opt() selinux: rewrite selinux_sb_eat_lsm_opts() selinux: regularize Opt_... names a bit selinux: switch away from match_token() selinux: new helper - selinux_add_opt() LSM: bury struct security_mnt_opts smack: switch to private smack_mnt_opts selinux: switch to private struct selinux_mnt_opts LSM: hide struct security_mnt_opts from any generic code selinux: kill selinux_sb_get_mnt_opts() LSM: turn sb_eat_lsm_opts() into a method nfs_remount(): don't leak, don't ignore LSM options quietly btrfs: sanitize security_mnt_opts use selinux; don't open-code a loop in sb_finish_set_opts() LSM: split ->sb_set_mnt_opts() out of ->sb_kern_mount() new helper: security_sb_eat_lsm_opts() ...
2 parents 9b286ef + 718c430 commit 505b050

28 files changed

Lines changed: 724 additions & 1040 deletions

File tree

‎arch/arc/kernel/setup.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/of_fdt.h>
2020
#include <linux/of.h>
2121
#include <linux/cache.h>
22+
#include <uapi/linux/mount.h>
2223
#include <asm/sections.h>
2324
#include <asm/arcregs.h>
2425
#include <asm/tlb.h>

‎arch/arm/kernel/atags_parse.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/root_dev.h>
2525
#include <linux/screen_info.h>
2626
#include <linux/memblock.h>
27+
#include <uapi/linux/mount.h>
2728

2829
#include <asm/setup.h>
2930
#include <asm/system_info.h>

‎arch/sh/kernel/setup.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/of.h>
3333
#include <linux/of_fdt.h>
3434
#include <linux/uaccess.h>
35+
#include <uapi/linux/mount.h>
3536
#include <asm/io.h>
3637
#include <asm/page.h>
3738
#include <asm/elf.h>

‎arch/sparc/kernel/setup_32.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/kdebug.h>
3535
#include <linux/export.h>
3636
#include <linux/start_kernel.h>
37+
#include <uapi/linux/mount.h>
3738

3839
#include <asm/io.h>
3940
#include <asm/processor.h>

‎arch/sparc/kernel/setup_64.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/module.h>
3434
#include <linux/start_kernel.h>
3535
#include <linux/memblock.h>
36+
#include <uapi/linux/mount.h>
3637

3738
#include <asm/io.h>
3839
#include <asm/processor.h>

‎arch/x86/kernel/setup.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/kvm_para.h>
5151
#include <linux/dma-contiguous.h>
5252
#include <xen/xen.h>
53+
#include <uapi/linux/mount.h>
5354

5455
#include <linux/errno.h>
5556
#include <linux/kernel.h>

‎drivers/base/devtmpfs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/sched.h>
2626
#include <linux/slab.h>
2727
#include <linux/kthread.h>
28+
#include <uapi/linux/mount.h>
2829
#include "base.h"
2930

3031
static struct task_struct *thread;

‎fs/btrfs/ctree.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,6 @@ struct btrfs_fs_info {
11441144
struct mutex unused_bg_unpin_mutex;
11451145
struct mutex delete_unused_bgs_mutex;
11461146

1147-
/* For btrfs to record security options */
1148-
struct security_mnt_opts security_opts;
1149-
11501147
/*
11511148
* Chunks that can't be freed yet (under a trim/discard operation)
11521149
* and will be latter freed. Protected by fs_info->chunk_mutex.
@@ -3021,7 +3018,6 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info)
30213018
kfree(fs_info->free_space_root);
30223019
kfree(fs_info->super_copy);
30233020
kfree(fs_info->super_for_commit);
3024-
security_free_mnt_opts(&fs_info->security_opts);
30253021
kvfree(fs_info);
30263022
}
30273023

‎fs/btrfs/super.c‎

Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,56 +1458,6 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
14581458
return root;
14591459
}
14601460

1461-
static int parse_security_options(char *orig_opts,
1462-
struct security_mnt_opts *sec_opts)
1463-
{
1464-
char *secdata = NULL;
1465-
int ret = 0;
1466-
1467-
secdata = alloc_secdata();
1468-
if (!secdata)
1469-
return -ENOMEM;
1470-
ret = security_sb_copy_data(orig_opts, secdata);
1471-
if (ret) {
1472-
free_secdata(secdata);
1473-
return ret;
1474-
}
1475-
ret = security_sb_parse_opts_str(secdata, sec_opts);
1476-
free_secdata(secdata);
1477-
return ret;
1478-
}
1479-
1480-
static int setup_security_options(struct btrfs_fs_info *fs_info,
1481-
struct super_block *sb,
1482-
struct security_mnt_opts *sec_opts)
1483-
{
1484-
int ret = 0;
1485-
1486-
/*
1487-
* Call security_sb_set_mnt_opts() to check whether new sec_opts
1488-
* is valid.
1489-
*/
1490-
ret = security_sb_set_mnt_opts(sb, sec_opts, 0, NULL);
1491-
if (ret)
1492-
return ret;
1493-
1494-
#ifdef CONFIG_SECURITY
1495-
if (!fs_info->security_opts.num_mnt_opts) {
1496-
/* first time security setup, copy sec_opts to fs_info */
1497-
memcpy(&fs_info->security_opts, sec_opts, sizeof(*sec_opts));
1498-
} else {
1499-
/*
1500-
* Since SELinux (the only one supporting security_mnt_opts)
1501-
* does NOT support changing context during remount/mount of
1502-
* the same sb, this must be the same or part of the same
1503-
* security options, just free it.
1504-
*/
1505-
security_free_mnt_opts(sec_opts);
1506-
}
1507-
#endif
1508-
return ret;
1509-
}
1510-
15111461
/*
15121462
* Find a superblock for the given device / mount point.
15131463
*
@@ -1522,16 +1472,15 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
15221472
struct btrfs_device *device = NULL;
15231473
struct btrfs_fs_devices *fs_devices = NULL;
15241474
struct btrfs_fs_info *fs_info = NULL;
1525-
struct security_mnt_opts new_sec_opts;
1475+
void *new_sec_opts = NULL;
15261476
fmode_t mode = FMODE_READ;
15271477
int error = 0;
15281478

15291479
if (!(flags & SB_RDONLY))
15301480
mode |= FMODE_WRITE;
15311481

1532-
security_init_mnt_opts(&new_sec_opts);
15331482
if (data) {
1534-
error = parse_security_options(data, &new_sec_opts);
1483+
error = security_sb_eat_lsm_opts(data, &new_sec_opts);
15351484
if (error)
15361485
return ERR_PTR(error);
15371486
}
@@ -1550,7 +1499,6 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
15501499

15511500
fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
15521501
fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL);
1553-
security_init_mnt_opts(&fs_info->security_opts);
15541502
if (!fs_info->super_copy || !fs_info->super_for_commit) {
15551503
error = -ENOMEM;
15561504
goto error_fs_info;
@@ -1601,16 +1549,12 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
16011549
btrfs_sb(s)->bdev_holder = fs_type;
16021550
error = btrfs_fill_super(s, fs_devices, data);
16031551
}
1552+
if (!error)
1553+
error = security_sb_set_mnt_opts(s, new_sec_opts, 0, NULL);
1554+
security_free_mnt_opts(&new_sec_opts);
16041555
if (error) {
16051556
deactivate_locked_super(s);
1606-
goto error_sec_opts;
1607-
}
1608-
1609-
fs_info = btrfs_sb(s);
1610-
error = setup_security_options(fs_info, s, &new_sec_opts);
1611-
if (error) {
1612-
deactivate_locked_super(s);
1613-
goto error_sec_opts;
1557+
return ERR_PTR(error);
16141558
}
16151559

16161560
return dget(s->s_root);
@@ -1779,18 +1723,14 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
17791723
btrfs_remount_prepare(fs_info);
17801724

17811725
if (data) {
1782-
struct security_mnt_opts new_sec_opts;
1726+
void *new_sec_opts = NULL;
17831727

1784-
security_init_mnt_opts(&new_sec_opts);
1785-
ret = parse_security_options(data, &new_sec_opts);
1728+
ret = security_sb_eat_lsm_opts(data, &new_sec_opts);
1729+
if (!ret)
1730+
ret = security_sb_remount(sb, new_sec_opts);
1731+
security_free_mnt_opts(&new_sec_opts);
17861732
if (ret)
17871733
goto restore;
1788-
ret = setup_security_options(fs_info, sb,
1789-
&new_sec_opts);
1790-
if (ret) {
1791-
security_free_mnt_opts(&new_sec_opts);
1792-
goto restore;
1793-
}
17941734
}
17951735

17961736
ret = btrfs_parse_options(fs_info, data, *flags);

‎fs/exofs/super.c‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,21 +705,18 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,
705705
/*
706706
* Read the superblock from the OSD and fill in the fields
707707
*/
708-
static int exofs_fill_super(struct super_block *sb, void *data, int silent)
708+
static int exofs_fill_super(struct super_block *sb,
709+
struct exofs_mountopt *opts,
710+
struct exofs_sb_info *sbi,
711+
int silent)
709712
{
710713
struct inode *root;
711-
struct exofs_mountopt *opts = data;
712-
struct exofs_sb_info *sbi; /*extended info */
713714
struct osd_dev *od; /* Master device */
714715
struct exofs_fscb fscb; /*on-disk superblock info */
715716
struct ore_comp comp;
716717
unsigned table_count;
717718
int ret;
718719

719-
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
720-
if (!sbi)
721-
return -ENOMEM;
722-
723720
/* use mount options to fill superblock */
724721
if (opts->is_osdname) {
725722
struct osd_dev_info odi = {.systemid_len = 0};
@@ -863,7 +860,9 @@ static struct dentry *exofs_mount(struct file_system_type *type,
863860
int flags, const char *dev_name,
864861
void *data)
865862
{
863+
struct super_block *s;
866864
struct exofs_mountopt opts;
865+
struct exofs_sb_info *sbi;
867866
int ret;
868867

869868
ret = parse_options(data, &opts);
@@ -872,9 +871,31 @@ static struct dentry *exofs_mount(struct file_system_type *type,
872871
return ERR_PTR(ret);
873872
}
874873

874+
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
875+
if (!sbi) {
876+
kfree(opts.dev_name);
877+
return ERR_PTR(-ENOMEM);
878+
}
879+
880+
s = sget(type, NULL, set_anon_super, flags, NULL);
881+
882+
if (IS_ERR(s)) {
883+
kfree(opts.dev_name);
884+
kfree(sbi);
885+
return ERR_CAST(s);
886+
}
887+
875888
if (!opts.dev_name)
876889
opts.dev_name = dev_name;
877-
return mount_nodev(type, flags, &opts, exofs_fill_super);
890+
891+
892+
ret = exofs_fill_super(s, &opts, sbi, flags & SB_SILENT ? 1 : 0);
893+
if (ret) {
894+
deactivate_locked_super(s);
895+
return ERR_PTR(ret);
896+
}
897+
s->s_flags |= SB_ACTIVE;
898+
return dget(s->s_root);
878899
}
879900

880901
/*

0 commit comments

Comments
 (0)