BACKPORT: LSM: split ->sb_set_mnt_opts() out of ->sb_kern_mount()

... leaving the "is it kernel-internal" logics in the caller.

Reviewed-by: David Howells <dhowells@redhat.com>
Change-Id: I6edb516330dbff370507f0f6d7d1b4d7884d5246
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro
2018-12-05 11:58:35 -05:00
committed by bengris32
parent 8b243794a9
commit 402401ec58
6 changed files with 13 additions and 33 deletions

View File

@@ -1276,10 +1276,16 @@ mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
smp_wmb();
sb->s_flags |= SB_BORN;
error = security_sb_kern_mount(sb, flags, &opts);
error = security_sb_set_mnt_opts(sb, &opts, 0, NULL);
if (error)
goto out_sb;
if (!(flags & MS_KERNMOUNT)) {
error = security_sb_kern_mount(sb);
if (error)
goto out_sb;
}
/*
* filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
* but s_maxbytes was an unsigned long long for many releases. Throw

View File

@@ -57,7 +57,7 @@ LSM_HOOK(int, 0, sb_alloc_security, struct super_block *sb)
LSM_HOOK(void, LSM_RET_VOID, sb_free_security, struct super_block *sb)
LSM_HOOK(int, 0, sb_copy_data, char *orig, char *copy)
LSM_HOOK(int, 0, sb_remount, struct super_block *sb, struct security_mnt_opts *opts)
LSM_HOOK(int, 0, sb_kern_mount, struct super_block *sb, int flags, struct security_mnt_opts *opts)
LSM_HOOK(int, 0, sb_kern_mount, struct super_block *sb)
LSM_HOOK(int, 0, sb_show_options, struct seq_file *m, struct super_block *sb)
LSM_HOOK(int, 0, sb_statfs, struct dentry *dentry)
LSM_HOOK(int, 0, sb_mount, const char *dev_name, const struct path *path,

View File

@@ -284,8 +284,7 @@ int security_sb_alloc(struct super_block *sb);
void security_sb_free(struct super_block *sb);
int security_sb_eat_lsm_opts(char *options, struct security_mnt_opts *opts);
int security_sb_remount(struct super_block *sb, struct security_mnt_opts *opts);
int security_sb_kern_mount(struct super_block *sb, int flags,
struct security_mnt_opts *opts);
int security_sb_kern_mount(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_mount(const char *dev_name, const struct path *path,
@@ -609,8 +608,7 @@ static inline int security_sb_remount(struct super_block *sb,
return 0;
}
static inline int security_sb_kern_mount(struct super_block *sb, int flags,
struct security_mnt_opts *opts)
static inline int security_sb_kern_mount(struct super_block *sb)
{
return 0;
}

View File

@@ -816,10 +816,9 @@ int security_sb_remount(struct super_block *sb,
}
EXPORT_SYMBOL(security_sb_remount);
int security_sb_kern_mount(struct super_block *sb, int flags,
struct security_mnt_opts *opts)
int security_sb_kern_mount(struct super_block *sb)
{
return call_int_hook(sb_kern_mount, 0, sb, flags, opts);
return call_int_hook(sb_kern_mount, 0, sb);
}
int security_sb_show_options(struct seq_file *m, struct super_block *sb)

View File

@@ -2830,18 +2830,10 @@ out_bad_option:
return -EINVAL;
}
static int selinux_sb_kern_mount(struct super_block *sb, int flags,
struct security_mnt_opts *opts)
static int selinux_sb_kern_mount(struct super_block *sb)
{
const struct cred *cred = current_cred();
struct common_audit_data ad;
int rc = selinux_set_mnt_opts(sb, opts, 0, NULL);
if (rc)
return rc;
/* Allow all mounts performed by the kernel */
if (flags & (MS_KERNMOUNT | MS_SUBMOUNT))
return 0;
ad.type = LSM_AUDIT_DATA_DENTRY;
ad.u.dentry = sb->s_root;

View File

@@ -837,20 +837,6 @@ static int smack_set_mnt_opts(struct super_block *sb,
return 0;
}
/**
* smack_sb_kern_mount - Smack specific mount processing
* @sb: the file system superblock
* @flags: the mount flags
* @data: the smack mount options
*
* Returns 0 on success, an error code on failure
*/
static int smack_sb_kern_mount(struct super_block *sb, int flags,
struct security_mnt_opts *opts)
{
return smack_set_mnt_opts(sb, opts, 0, NULL);
}
/**
* smack_sb_statfs - Smack check on statfs
* @dentry: identifies the file system in question
@@ -4618,7 +4604,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
LSM_HOOK_INIT(sb_alloc_security, smack_sb_alloc_security),
LSM_HOOK_INIT(sb_free_security, smack_sb_free_security),
LSM_HOOK_INIT(sb_copy_data, smack_sb_copy_data),
LSM_HOOK_INIT(sb_kern_mount, smack_sb_kern_mount),
LSM_HOOK_INIT(sb_statfs, smack_sb_statfs),
LSM_HOOK_INIT(sb_set_mnt_opts, smack_set_mnt_opts),
LSM_HOOK_INIT(sb_parse_opts_str, smack_parse_opts_str),