Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55c0e5bd authored by Al Viro's avatar Al Viro
Browse files

smack: take the guts of smack_parse_opts_str() into a new helper



smack_add_opt() adds an already matched option to growing smack_mnt_options

Reviewed-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 757cbe59
Loading
Loading
Loading
Loading
+57 −57
Original line number Diff line number Diff line
@@ -629,94 +629,94 @@ static int smack_sb_copy_data(char *orig, char *smackopts)
	return 0;
}

/**
 * smack_parse_opts_str - parse Smack specific mount options
 * @options: mount options string
 * @opts: where to store converted mount opts
 *
 * Returns 0 on success or -ENOMEM on error.
 *
 * converts Smack specific mount options to generic security option format
 */
static int smack_parse_opts_str(char *options,
		void **mnt_opts)
static int smack_add_opt(int token, const char *s, void **mnt_opts)
{
	struct smack_mnt_opts *opts = *mnt_opts;
	char *p;
	int rc = -ENOMEM;
	int token;

	if (!options)
		return 0;

	while ((p = strsep(&options, ",")) != NULL) {
		substring_t args[MAX_OPT_ARGS];

		if (!*p)
			continue;

		token = match_token(p, smk_mount_tokens, args);

	if (!opts) {
		opts = kzalloc(sizeof(struct smack_mnt_opts), GFP_KERNEL);
		if (!opts)
			return -ENOMEM;
		*mnt_opts = opts;
	}

	if (!s)
		return -ENOMEM;

	switch (token) {
	case Opt_fsdefault:
		if (opts->fsdefault)
			goto out_opt_err;
			opts->fsdefault = match_strdup(&args[0]);
			if (!opts->fsdefault)
				goto out_err;
		opts->fsdefault = s;
		break;
	case Opt_fsfloor:
		if (opts->fsfloor)
			goto out_opt_err;
			opts->fsfloor = match_strdup(&args[0]);
			if (!opts->fsfloor)
				goto out_err;
		opts->fsfloor = s;
		break;
	case Opt_fshat:
		if (opts->fshat)
			goto out_opt_err;
			opts->fshat = match_strdup(&args[0]);
			if (!opts->fshat)
				goto out_err;
		opts->fshat = s;
		break;
	case Opt_fsroot:
		if (opts->fsroot)
			goto out_opt_err;
			opts->fsroot = match_strdup(&args[0]);
			if (!opts->fsroot)
				goto out_err;
		opts->fsroot = s;
		break;
	case Opt_fstransmute:
		if (opts->fstransmute)
			goto out_opt_err;
			opts->fstransmute = match_strdup(&args[0]);
			if (!opts->fstransmute)
				goto out_err;
		opts->fstransmute = s;
		break;
		default:
			rc = -EINVAL;
			pr_warn("Smack:  unknown mount option\n");
			goto out_err;
		}
	}
	*mnt_opts = opts;
	return 0;

out_opt_err:
	rc = -EINVAL;
	pr_warn("Smack: duplicate mount options\n");
	return -EINVAL;
}

out_err:
	if (opts)
		smack_free_mnt_opts(opts);
/**
 * smack_parse_opts_str - parse Smack specific mount options
 * @options: mount options string
 * @opts: where to store converted mount opts
 *
 * Returns 0 on success or -ENOMEM on error.
 *
 * converts Smack specific mount options to generic security option format
 */
static int smack_parse_opts_str(char *options,
		void **mnt_opts)
{
	char *p;
	int rc = -ENOMEM;
	int token;

	if (!options)
		return 0;

	while ((p = strsep(&options, ",")) != NULL) {
		substring_t args[MAX_OPT_ARGS];
		const char *arg;

		if (!*p)
			continue;

		token = match_token(p, smk_mount_tokens, args);

		arg = match_strdup(&args[0]);
		rc = smack_add_opt(token, arg, mnt_opts);
		if (unlikely(rc)) {
			kfree(arg);
			if (*mnt_opts)
				smack_free_mnt_opts(*mnt_opts);
			*mnt_opts = NULL;
			return rc;
		}
	}
	return 0;
}

static int smack_sb_eat_lsm_opts(char *options, void **mnt_opts)
{