Skip to content

Commit ff36fe2

Browse files
committed
LSM: Pass -o remount options to the LSM
The VFS mount code passes the mount options to the LSM. The LSM will remove options it understands from the data and the VFS will then pass the remaining options onto the underlying filesystem. This is how options like the SELinux context= work. The problem comes in that -o remount never calls into LSM code. So if you include an LSM specific option it will get passed to the filesystem and will cause the remount to fail. An example of where this is a problem is the 'seclabel' option. The SELinux LSM hook will print this word in /proc/mounts if the filesystem is being labeled using xattrs. If you pass this word on mount it will be silently stripped and ignored. But if you pass this word on remount the LSM never gets called and it will be passed to the FS. The FS doesn't know what seclabel means and thus should fail the mount. For example an ext3 fs mounted over loop # mount -o loop /tmp/fs /mnt/tmp # cat /proc/mounts | grep /mnt/tmp /dev/loop0 /mnt/tmp ext3 rw,seclabel,relatime,errors=continue,barrier=0,data=ordered 0 0 # mount -o remount /mnt/tmp mount: /mnt/tmp not mounted already, or bad option # dmesg EXT3-fs (loop0): error: unrecognized mount option "seclabel" or missing value This patch passes the remount mount options to an new LSM hook. Signed-off-by: Eric Paris <eparis@redhat.com> Reviewed-by: James Morris <jmorris@namei.org>
1 parent 2ad18bd commit ff36fe2

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎fs/namespace.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,10 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
18001800
if (path->dentry != path->mnt->mnt_root)
18011801
return -EINVAL;
18021802

1803+
err = security_sb_remount(sb, data);
1804+
if (err)
1805+
return err;
1806+
18031807
down_write(&sb->s_umount);
18041808
if (flags & MS_BIND)
18051809
err = change_mount_flags(path->mnt, flags);

‎include/linux/security.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
268268
* @orig the original mount data copied from userspace.
269269
* @copy copied data which will be passed to the security module.
270270
* Returns 0 if the copy was successful.
271+
* @sb_remount:
272+
* Extracts security system specifc mount options and verifys no changes
273+
* are being made to those options.
274+
* @sb superblock being remounted
275+
* @data contains the filesystem-specific data.
276+
* Return 0 if permission is granted.
271277
* @sb_umount:
272278
* Check permission before the @mnt file system is unmounted.
273279
* @mnt contains the mounted file system.
@@ -1394,6 +1400,7 @@ struct security_operations {
13941400
int (*sb_alloc_security) (struct super_block *sb);
13951401
void (*sb_free_security) (struct super_block *sb);
13961402
int (*sb_copy_data) (char *orig, char *copy);
1403+
int (*sb_remount) (struct super_block *sb, void *data);
13971404
int (*sb_kern_mount) (struct super_block *sb, int flags, void *data);
13981405
int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
13991406
int (*sb_statfs) (struct dentry *dentry);
@@ -1676,6 +1683,7 @@ int security_bprm_secureexec(struct linux_binprm *bprm);
16761683
int security_sb_alloc(struct super_block *sb);
16771684
void security_sb_free(struct super_block *sb);
16781685
int security_sb_copy_data(char *orig, char *copy);
1686+
int security_sb_remount(struct super_block *sb, void *data);
16791687
int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
16801688
int security_sb_show_options(struct seq_file *m, struct super_block *sb);
16811689
int security_sb_statfs(struct dentry *dentry);
@@ -1955,6 +1963,11 @@ static inline int security_sb_copy_data(char *orig, char *copy)
19551963
return 0;
19561964
}
19571965

1966+
static inline int security_sb_remount(struct super_block *sb, void *data)
1967+
{
1968+
return 0;
1969+
}
1970+
19581971
static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
19591972
{
19601973
return 0;

‎security/capability.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ static int cap_sb_copy_data(char *orig, char *copy)
5454
return 0;
5555
}
5656

57+
static int cap_sb_remount(struct super_block *sb, void *data)
58+
{
59+
return 0;
60+
}
61+
5762
static int cap_sb_kern_mount(struct super_block *sb, int flags, void *data)
5863
{
5964
return 0;
@@ -887,6 +892,7 @@ void __init security_fixup_ops(struct security_operations *ops)
887892
set_to_cap_if_null(ops, sb_alloc_security);
888893
set_to_cap_if_null(ops, sb_free_security);
889894
set_to_cap_if_null(ops, sb_copy_data);
895+
set_to_cap_if_null(ops, sb_remount);
890896
set_to_cap_if_null(ops, sb_kern_mount);
891897
set_to_cap_if_null(ops, sb_show_options);
892898
set_to_cap_if_null(ops, sb_statfs);

‎security/security.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ int security_sb_copy_data(char *orig, char *copy)
267267
}
268268
EXPORT_SYMBOL(security_sb_copy_data);
269269

270+
int security_sb_remount(struct super_block *sb, void *data)
271+
{
272+
return security_ops->sb_remount(sb, data);
273+
}
274+
270275
int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
271276
{
272277
return security_ops->sb_kern_mount(sb, flags, data);

0 commit comments

Comments
 (0)