History

smack: get rid of match_token()

same issue as with selinux... [fix by Andrei Vagin folded in]

Al Viro committed 7 years ago

Commit c3300aa1 parent 55c0e5b1 file · +38 −18Browse files

Unified · Split

security/smack/smack_lsm.c+38−18
@@ -59,14 +59,31 @@ static LIST_HEAD(smk_ipv6_port_list); · 58 unmodified lines
59static struct kmem_cache *smack_inode_cache;59static struct kmem_cache *smack_inode_cache;
60int smack_enabled;60int smack_enabled;
61 61
62static const match_table_t smk_mount_tokens = {62#define A(s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s}
63 {Opt_fsdefault, SMK_FSDEFAULT "%s"},63static struct {
64 {Opt_fsfloor, SMK_FSFLOOR "%s"},64 const char *name;
65 {Opt_fshat, SMK_FSHAT "%s"},65 int len;
66 {Opt_fsroot, SMK_FSROOT "%s"},66 int opt;
67 {Opt_fstransmute, SMK_FSTRANS "%s"},67} smk_mount_opts[] = {
68 {Opt_error, NULL},68 A(fsdefault), A(fsfloor), A(fshat), A(fsroot), A(fstransmute)
69};69};
70#undef A
71
72static int match_opt_prefix(char *s, int l, char **arg)
73{
74 int i;
75
76 for (i = 0; i < ARRAY_SIZE(smk_mount_opts); i++) {
77 size_t len = smk_mount_opts[i].len;
78 if (len > l || memcmp(s, smk_mount_opts[i].name, len))
79 continue;
80 if (len == l || s[len] != '=')
81 continue;
82 *arg = s + len + 1;
83 return smk_mount_opts[i].opt;
84 }
85 return Opt_error;
86}
70 87
71#ifdef CONFIG_SECURITY_SMACK_BRINGUP88#ifdef CONFIG_SECURITY_SMACK_BRINGUP
72static char *smk_bu_mess[] = {89static char *smk_bu_mess[] = {
@@ -689,23 +706,23 @@ out_opt_err: · 616 unmodified lines
689static int smack_parse_opts_str(char *options,706static int smack_parse_opts_str(char *options,
690 void **mnt_opts)707 void **mnt_opts)
691{708{
692 char *p;709 char *from = options;
693 int rc = -ENOMEM;
694 int token;
695 710
696 if (!options)711 if (!options)
697 return 0;712 return 0;
698 713
699 while ((p = strsep(&options, ",")) != NULL) {714 while (1) {
700 substring_t args[MAX_OPT_ARGS];715 char *next = strchr(from, ',');
701 const char *arg;716 int token, len, rc;
702 717 char *arg = NULL;
703 if (!*p)
704 continue;
705 718
706 token = match_token(p, smk_mount_tokens, args);719 if (next)
720 len = next - from;
721 else
722 len = strlen(from);
707 723
708 arg = match_strdup(&args[0]);724 token = match_opt_prefix(from, len, &arg);
725 arg = kmemdup_nul(arg, from + len - arg, GFP_KERNEL);
709 rc = smack_add_opt(token, arg, mnt_opts);726 rc = smack_add_opt(token, arg, mnt_opts);
710 if (unlikely(rc)) {727 if (unlikely(rc)) {
711 kfree(arg);728 kfree(arg);
@@ -714,6 +731,9 @@ static int smack_parse_opts_str(char *options, · 2 unmodified lines
714 *mnt_opts = NULL;731 *mnt_opts = NULL;
715 return rc;732 return rc;
716 }733 }
734 if (!from[len])
735 break;
736 from += len + 1;
717 }737 }
718 return 0;738 return 0;
719}739}