Skip to content

Commit fec6375

Browse files
zhanggenexpcmoore
authored andcommitted
selinux: fix a missing-check bug in selinux_sb_eat_lsm_opts()
In selinux_sb_eat_lsm_opts(), 'arg' is allocated by kmemdup_nul(). It returns NULL when fails. So 'arg' should be checked. And 'mnt_opts' should be freed when error. Signed-off-by: Gen Zhang <[email protected]> Fixes: 99dbbb5 ("selinux: rewrite selinux_sb_eat_lsm_opts()") Cc: <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent e2e0e09 commit fec6375

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

security/selinux/hooks.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,10 +2625,11 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
26252625
char *from = options;
26262626
char *to = options;
26272627
bool first = true;
2628+
int rc;
26282629

26292630
while (1) {
26302631
int len = opt_len(from);
2631-
int token, rc;
2632+
int token;
26322633
char *arg = NULL;
26332634

26342635
token = match_opt_prefix(from, len, &arg);
@@ -2644,15 +2645,15 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
26442645
*q++ = c;
26452646
}
26462647
arg = kmemdup_nul(arg, q - arg, GFP_KERNEL);
2648+
if (!arg) {
2649+
rc = -ENOMEM;
2650+
goto free_opt;
2651+
}
26472652
}
26482653
rc = selinux_add_opt(token, arg, mnt_opts);
26492654
if (unlikely(rc)) {
26502655
kfree(arg);
2651-
if (*mnt_opts) {
2652-
selinux_free_mnt_opts(*mnt_opts);
2653-
*mnt_opts = NULL;
2654-
}
2655-
return rc;
2656+
goto free_opt;
26562657
}
26572658
} else {
26582659
if (!first) { // copy with preceding comma
@@ -2670,6 +2671,13 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts)
26702671
}
26712672
*to = '\0';
26722673
return 0;
2674+
2675+
free_opt:
2676+
if (*mnt_opts) {
2677+
selinux_free_mnt_opts(*mnt_opts);
2678+
*mnt_opts = NULL;
2679+
}
2680+
return rc;
26732681
}
26742682

26752683
static int selinux_sb_remount(struct super_block *sb, void *mnt_opts)

0 commit comments

Comments
 (0)