LSM: lift parsing LSM options into the caller of ->sb_kern_mount()
This paves the way for retaining the LSM options from a common filesystem mount context during a mount parameter parsing phase to be instituted prior to actual mount/reconfiguration actions. Reviewed-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
6466f3d193
commit
6be8750b4c
24
fs/super.c
24
fs/super.c
|
@ -1246,17 +1246,26 @@ mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
|
||||||
{
|
{
|
||||||
struct dentry *root;
|
struct dentry *root;
|
||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
char *secdata = NULL;
|
|
||||||
int error = -ENOMEM;
|
int error = -ENOMEM;
|
||||||
|
struct security_mnt_opts opts;
|
||||||
|
|
||||||
|
security_init_mnt_opts(&opts);
|
||||||
|
|
||||||
if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
|
if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
|
||||||
secdata = alloc_secdata();
|
char *secdata = alloc_secdata();
|
||||||
if (!secdata)
|
if (!secdata)
|
||||||
goto out;
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
error = security_sb_copy_data(data, secdata);
|
error = security_sb_copy_data(data, secdata);
|
||||||
|
if (error) {
|
||||||
|
free_secdata(secdata);
|
||||||
|
return ERR_PTR(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
error = security_sb_parse_opts_str(secdata, &opts);
|
||||||
|
free_secdata(secdata);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_free_secdata;
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
root = type->mount(type, flags, name, data);
|
root = type->mount(type, flags, name, data);
|
||||||
|
@ -1277,7 +1286,7 @@ mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
|
||||||
smp_wmb();
|
smp_wmb();
|
||||||
sb->s_flags |= SB_BORN;
|
sb->s_flags |= SB_BORN;
|
||||||
|
|
||||||
error = security_sb_kern_mount(sb, flags, secdata);
|
error = security_sb_kern_mount(sb, flags, &opts);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_sb;
|
goto out_sb;
|
||||||
|
|
||||||
|
@ -1291,14 +1300,13 @@ mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
|
||||||
"negative value (%lld)\n", type->name, sb->s_maxbytes);
|
"negative value (%lld)\n", type->name, sb->s_maxbytes);
|
||||||
|
|
||||||
up_write(&sb->s_umount);
|
up_write(&sb->s_umount);
|
||||||
free_secdata(secdata);
|
security_free_mnt_opts(&opts);
|
||||||
return root;
|
return root;
|
||||||
out_sb:
|
out_sb:
|
||||||
dput(root);
|
dput(root);
|
||||||
deactivate_locked_super(sb);
|
deactivate_locked_super(sb);
|
||||||
out_free_secdata:
|
out_free_secdata:
|
||||||
free_secdata(secdata);
|
security_free_mnt_opts(&opts);
|
||||||
out:
|
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1463,7 +1463,8 @@ union security_list_options {
|
||||||
void (*sb_free_security)(struct super_block *sb);
|
void (*sb_free_security)(struct super_block *sb);
|
||||||
int (*sb_copy_data)(char *orig, char *copy);
|
int (*sb_copy_data)(char *orig, char *copy);
|
||||||
int (*sb_remount)(struct super_block *sb, void *data);
|
int (*sb_remount)(struct super_block *sb, void *data);
|
||||||
int (*sb_kern_mount)(struct super_block *sb, int flags, void *data);
|
int (*sb_kern_mount)(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts);
|
||||||
int (*sb_show_options)(struct seq_file *m, struct super_block *sb);
|
int (*sb_show_options)(struct seq_file *m, struct super_block *sb);
|
||||||
int (*sb_statfs)(struct dentry *dentry);
|
int (*sb_statfs)(struct dentry *dentry);
|
||||||
int (*sb_mount)(const char *dev_name, const struct path *path,
|
int (*sb_mount)(const char *dev_name, const struct path *path,
|
||||||
|
|
|
@ -250,7 +250,8 @@ int security_sb_alloc(struct super_block *sb);
|
||||||
void security_sb_free(struct super_block *sb);
|
void security_sb_free(struct super_block *sb);
|
||||||
int security_sb_copy_data(char *orig, char *copy);
|
int security_sb_copy_data(char *orig, char *copy);
|
||||||
int security_sb_remount(struct super_block *sb, void *data);
|
int security_sb_remount(struct super_block *sb, void *data);
|
||||||
int security_sb_kern_mount(struct super_block *sb, int flags, void *data);
|
int security_sb_kern_mount(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts);
|
||||||
int security_sb_show_options(struct seq_file *m, struct super_block *sb);
|
int security_sb_show_options(struct seq_file *m, struct super_block *sb);
|
||||||
int security_sb_statfs(struct dentry *dentry);
|
int security_sb_statfs(struct dentry *dentry);
|
||||||
int security_sb_mount(const char *dev_name, const struct path *path,
|
int security_sb_mount(const char *dev_name, const struct path *path,
|
||||||
|
@ -565,7 +566,8 @@ static inline int security_sb_remount(struct super_block *sb, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
static inline int security_sb_kern_mount(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,9 +395,10 @@ int security_sb_remount(struct super_block *sb, void *data)
|
||||||
return call_int_hook(sb_remount, 0, sb, data);
|
return call_int_hook(sb_remount, 0, sb, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int security_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
int security_sb_kern_mount(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts)
|
||||||
{
|
{
|
||||||
return call_int_hook(sb_kern_mount, 0, sb, flags, data);
|
return call_int_hook(sb_kern_mount, 0, sb, flags, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
|
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
|
||||||
|
|
|
@ -2897,30 +2897,12 @@ out_bad_option:
|
||||||
goto out_free_opts;
|
goto out_free_opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
static int selinux_sb_kern_mount(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts)
|
||||||
{
|
{
|
||||||
char *options = data;
|
|
||||||
const struct cred *cred = current_cred();
|
const struct cred *cred = current_cred();
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
int rc = 0;
|
int rc = selinux_set_mnt_opts(sb, opts, 0, NULL);
|
||||||
struct security_mnt_opts opts;
|
|
||||||
|
|
||||||
security_init_mnt_opts(&opts);
|
|
||||||
|
|
||||||
if (!data)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
BUG_ON(sb->s_type->fs_flags & FS_BINARY_MOUNTDATA);
|
|
||||||
|
|
||||||
rc = selinux_parse_opts_str(options, &opts);
|
|
||||||
if (rc)
|
|
||||||
goto out_err;
|
|
||||||
|
|
||||||
out:
|
|
||||||
rc = selinux_set_mnt_opts(sb, &opts, 0, NULL);
|
|
||||||
|
|
||||||
out_err:
|
|
||||||
security_free_mnt_opts(&opts);
|
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
|
|
@ -859,27 +859,10 @@ static int smack_set_mnt_opts(struct super_block *sb,
|
||||||
*
|
*
|
||||||
* Returns 0 on success, an error code on failure
|
* Returns 0 on success, an error code on failure
|
||||||
*/
|
*/
|
||||||
static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
|
static int smack_sb_kern_mount(struct super_block *sb, int flags,
|
||||||
|
struct security_mnt_opts *opts)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
return smack_set_mnt_opts(sb, opts, 0, NULL);
|
||||||
char *options = data;
|
|
||||||
struct security_mnt_opts opts;
|
|
||||||
|
|
||||||
security_init_mnt_opts(&opts);
|
|
||||||
|
|
||||||
if (!options)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
rc = smack_parse_opts_str(options, &opts);
|
|
||||||
if (rc)
|
|
||||||
goto out_err;
|
|
||||||
|
|
||||||
out:
|
|
||||||
rc = smack_set_mnt_opts(sb, &opts, 0, NULL);
|
|
||||||
|
|
||||||
out_err:
|
|
||||||
security_free_mnt_opts(&opts);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue