Skip to content

Commit e2e0e09

Browse files
zhanggenexpcmoore
authored andcommitted
selinux: fix a missing-check bug in selinux_add_mnt_opt( )
In selinux_add_mnt_opt(), 'val' is allocated by kmemdup_nul(). It returns NULL when fails. So 'val' should be checked. And 'mnt_opts' should be freed when error. Signed-off-by: Gen Zhang <[email protected]> Fixes: 757cbe5 ("LSM: new method: ->sb_add_mnt_opt()") Cc: <[email protected]> [PM: fixed some indenting problems] Signed-off-by: Paul Moore <[email protected]>
1 parent aff7ed4 commit e2e0e09

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

security/selinux/hooks.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,15 +1052,24 @@ static int selinux_add_mnt_opt(const char *option, const char *val, int len,
10521052
if (token == Opt_error)
10531053
return -EINVAL;
10541054

1055-
if (token != Opt_seclabel)
1055+
if (token != Opt_seclabel) {
10561056
val = kmemdup_nul(val, len, GFP_KERNEL);
1057+
if (!val) {
1058+
rc = -ENOMEM;
1059+
goto free_opt;
1060+
}
1061+
}
10571062
rc = selinux_add_opt(token, val, mnt_opts);
10581063
if (unlikely(rc)) {
10591064
kfree(val);
1060-
if (*mnt_opts) {
1061-
selinux_free_mnt_opts(*mnt_opts);
1062-
*mnt_opts = NULL;
1063-
}
1065+
goto free_opt;
1066+
}
1067+
return rc;
1068+
1069+
free_opt:
1070+
if (*mnt_opts) {
1071+
selinux_free_mnt_opts(*mnt_opts);
1072+
*mnt_opts = NULL;
10641073
}
10651074
return rc;
10661075
}

0 commit comments

Comments
 (0)