Commit 12085b14 authored by Al Viro's avatar Al Viro

smack: switch to private smack_mnt_opts

Reviewed-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent bd323655
...@@ -567,16 +567,18 @@ static void smack_sb_free_security(struct super_block *sb) ...@@ -567,16 +567,18 @@ static void smack_sb_free_security(struct super_block *sb)
sb->s_security = NULL; sb->s_security = NULL;
} }
struct smack_mnt_opts {
const char *fsdefault, *fsfloor, *fshat, *fsroot, *fstransmute;
};
static void smack_free_mnt_opts(void *mnt_opts) static void smack_free_mnt_opts(void *mnt_opts)
{ {
struct security_mnt_opts *opts = mnt_opts; struct smack_mnt_opts *opts = mnt_opts;
int i; kfree(opts->fsdefault);
kfree(opts->fsfloor);
if (opts->mnt_opts) kfree(opts->fshat);
for (i = 0; i < opts->num_mnt_opts; i++) kfree(opts->fsroot);
kfree(opts->mnt_opts[i]); kfree(opts->fstransmute);
kfree(opts->mnt_opts);
kfree(opts->mnt_opts_flags);
kfree(opts); kfree(opts);
} }
...@@ -639,28 +641,14 @@ static int smack_sb_copy_data(char *orig, char *smackopts) ...@@ -639,28 +641,14 @@ static int smack_sb_copy_data(char *orig, char *smackopts)
static int smack_parse_opts_str(char *options, static int smack_parse_opts_str(char *options,
void **mnt_opts) void **mnt_opts)
{ {
struct security_mnt_opts *opts = *mnt_opts; struct smack_mnt_opts *opts = *mnt_opts;
char *p; char *p;
char *fsdefault = NULL;
char *fsfloor = NULL;
char *fshat = NULL;
char *fsroot = NULL;
char *fstransmute = NULL;
int rc = -ENOMEM; int rc = -ENOMEM;
int num_mnt_opts = 0;
int token; int token;
if (!options) if (!options)
return 0; return 0;
if (!opts) {
opts = kzalloc(sizeof(struct security_mnt_opts), GFP_KERNEL);
*mnt_opts = opts;
if (!opts)
return -ENOMEM;
}
opts->num_mnt_opts = 0;
while ((p = strsep(&options, ",")) != NULL) { while ((p = strsep(&options, ",")) != NULL) {
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
...@@ -669,40 +657,46 @@ static int smack_parse_opts_str(char *options, ...@@ -669,40 +657,46 @@ static int smack_parse_opts_str(char *options,
token = match_token(p, smk_mount_tokens, args); token = match_token(p, smk_mount_tokens, args);
if (!opts) {
opts = kzalloc(sizeof(struct smack_mnt_opts), GFP_KERNEL);
if (!opts)
return -ENOMEM;
}
switch (token) { switch (token) {
case Opt_fsdefault: case Opt_fsdefault:
if (fsdefault) if (opts->fsdefault)
goto out_opt_err; goto out_opt_err;
fsdefault = match_strdup(&args[0]); opts->fsdefault = match_strdup(&args[0]);
if (!fsdefault) if (!opts->fsdefault)
goto out_err; goto out_err;
break; break;
case Opt_fsfloor: case Opt_fsfloor:
if (fsfloor) if (opts->fsfloor)
goto out_opt_err; goto out_opt_err;
fsfloor = match_strdup(&args[0]); opts->fsfloor = match_strdup(&args[0]);
if (!fsfloor) if (!opts->fsfloor)
goto out_err; goto out_err;
break; break;
case Opt_fshat: case Opt_fshat:
if (fshat) if (opts->fshat)
goto out_opt_err; goto out_opt_err;
fshat = match_strdup(&args[0]); opts->fshat = match_strdup(&args[0]);
if (!fshat) if (!opts->fshat)
goto out_err; goto out_err;
break; break;
case Opt_fsroot: case Opt_fsroot:
if (fsroot) if (opts->fsroot)
goto out_opt_err; goto out_opt_err;
fsroot = match_strdup(&args[0]); opts->fsroot = match_strdup(&args[0]);
if (!fsroot) if (!opts->fsroot)
goto out_err; goto out_err;
break; break;
case Opt_fstransmute: case Opt_fstransmute:
if (fstransmute) if (opts->fstransmute)
goto out_opt_err; goto out_opt_err;
fstransmute = match_strdup(&args[0]); opts->fstransmute = match_strdup(&args[0]);
if (!fstransmute) if (!opts->fstransmute)
goto out_err; goto out_err;
break; break;
default: default:
...@@ -711,38 +705,7 @@ static int smack_parse_opts_str(char *options, ...@@ -711,38 +705,7 @@ static int smack_parse_opts_str(char *options,
goto out_err; goto out_err;
} }
} }
*mnt_opts = opts;
opts->mnt_opts = kcalloc(NUM_SMK_MNT_OPTS, sizeof(char *), GFP_KERNEL);
if (!opts->mnt_opts)
goto out_err;
opts->mnt_opts_flags = kcalloc(NUM_SMK_MNT_OPTS, sizeof(int),
GFP_KERNEL);
if (!opts->mnt_opts_flags)
goto out_err;
if (fsdefault) {
opts->mnt_opts[num_mnt_opts] = fsdefault;
opts->mnt_opts_flags[num_mnt_opts++] = FSDEFAULT_MNT;
}
if (fsfloor) {
opts->mnt_opts[num_mnt_opts] = fsfloor;
opts->mnt_opts_flags[num_mnt_opts++] = FSFLOOR_MNT;
}
if (fshat) {
opts->mnt_opts[num_mnt_opts] = fshat;
opts->mnt_opts_flags[num_mnt_opts++] = FSHAT_MNT;
}
if (fsroot) {
opts->mnt_opts[num_mnt_opts] = fsroot;
opts->mnt_opts_flags[num_mnt_opts++] = FSROOT_MNT;
}
if (fstransmute) {
opts->mnt_opts[num_mnt_opts] = fstransmute;
opts->mnt_opts_flags[num_mnt_opts++] = FSTRANS_MNT;
}
opts->num_mnt_opts = num_mnt_opts;
return 0; return 0;
out_opt_err: out_opt_err:
...@@ -750,12 +713,8 @@ static int smack_parse_opts_str(char *options, ...@@ -750,12 +713,8 @@ static int smack_parse_opts_str(char *options,
pr_warn("Smack: duplicate mount options\n"); pr_warn("Smack: duplicate mount options\n");
out_err: out_err:
kfree(fsdefault); if (opts)
kfree(fsfloor); smack_free_mnt_opts(opts);
kfree(fshat);
kfree(fsroot);
kfree(fstransmute);
security_free_mnt_opts(mnt_opts);
return rc; return rc;
} }
...@@ -795,10 +754,8 @@ static int smack_set_mnt_opts(struct super_block *sb, ...@@ -795,10 +754,8 @@ static int smack_set_mnt_opts(struct super_block *sb,
struct superblock_smack *sp = sb->s_security; struct superblock_smack *sp = sb->s_security;
struct inode_smack *isp; struct inode_smack *isp;
struct smack_known *skp; struct smack_known *skp;
int i; struct smack_mnt_opts *opts = mnt_opts;
struct security_mnt_opts *opts = mnt_opts; bool transmute = false;
int num_opts = opts ? opts->num_mnt_opts : 0;
int transmute = 0;
if (sp->smk_flags & SMK_SB_INITIALIZED) if (sp->smk_flags & SMK_SB_INITIALIZED)
return 0; return 0;
...@@ -807,7 +764,7 @@ static int smack_set_mnt_opts(struct super_block *sb, ...@@ -807,7 +764,7 @@ static int smack_set_mnt_opts(struct super_block *sb,
/* /*
* Unprivileged mounts don't get to specify Smack values. * Unprivileged mounts don't get to specify Smack values.
*/ */
if (num_opts) if (opts)
return -EPERM; return -EPERM;
/* /*
* Unprivileged mounts get root and default from the caller. * Unprivileged mounts get root and default from the caller.
...@@ -823,48 +780,44 @@ static int smack_set_mnt_opts(struct super_block *sb, ...@@ -823,48 +780,44 @@ static int smack_set_mnt_opts(struct super_block *sb,
if (sb->s_user_ns != &init_user_ns && if (sb->s_user_ns != &init_user_ns &&
sb->s_magic != SYSFS_MAGIC && sb->s_magic != TMPFS_MAGIC && sb->s_magic != SYSFS_MAGIC && sb->s_magic != TMPFS_MAGIC &&
sb->s_magic != RAMFS_MAGIC) { sb->s_magic != RAMFS_MAGIC) {
transmute = 1; transmute = true;
sp->smk_flags |= SMK_SB_UNTRUSTED; sp->smk_flags |= SMK_SB_UNTRUSTED;
} }
} }
sp->smk_flags |= SMK_SB_INITIALIZED; sp->smk_flags |= SMK_SB_INITIALIZED;
for (i = 0; i < num_opts; i++) { if (opts) {
switch (opts->mnt_opts_flags[i]) { if (opts->fsdefault) {
case FSDEFAULT_MNT: skp = smk_import_entry(opts->fsdefault, 0);
skp = smk_import_entry(opts->mnt_opts[i], 0);
if (IS_ERR(skp)) if (IS_ERR(skp))
return PTR_ERR(skp); return PTR_ERR(skp);
sp->smk_default = skp; sp->smk_default = skp;
break; }
case FSFLOOR_MNT: if (opts->fsfloor) {
skp = smk_import_entry(opts->mnt_opts[i], 0); skp = smk_import_entry(opts->fsfloor, 0);
if (IS_ERR(skp)) if (IS_ERR(skp))
return PTR_ERR(skp); return PTR_ERR(skp);
sp->smk_floor = skp; sp->smk_floor = skp;
break; }
case FSHAT_MNT: if (opts->fshat) {
skp = smk_import_entry(opts->mnt_opts[i], 0); skp = smk_import_entry(opts->fshat, 0);
if (IS_ERR(skp)) if (IS_ERR(skp))
return PTR_ERR(skp); return PTR_ERR(skp);
sp->smk_hat = skp; sp->smk_hat = skp;
break; }
case FSROOT_MNT: if (opts->fsroot) {
skp = smk_import_entry(opts->mnt_opts[i], 0); skp = smk_import_entry(opts->fsroot, 0);
if (IS_ERR(skp)) if (IS_ERR(skp))
return PTR_ERR(skp); return PTR_ERR(skp);
sp->smk_root = skp; sp->smk_root = skp;
break; }
case FSTRANS_MNT: if (opts->fstransmute) {
skp = smk_import_entry(opts->mnt_opts[i], 0); skp = smk_import_entry(opts->fstransmute, 0);
if (IS_ERR(skp)) if (IS_ERR(skp))
return PTR_ERR(skp); return PTR_ERR(skp);
sp->smk_root = skp; sp->smk_root = skp;
transmute = 1; transmute = true;
break;
default:
break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment