diff options
author | Paul Moore <paul@paul-moore.com> | 2017-06-07 16:48:19 -0400 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2017-06-13 03:34:22 -0400 |
commit | 023f108dcc187e34ef864bf10ed966cf25e14e2a (patch) | |
tree | 6617c918c09d44b648db90e921844c9604de66f5 /security/selinux/hooks.c | |
parent | 63f700aab4c11d46626de3cd051dae56cf7e9056 (diff) |
selinux: fix double free in selinux_parse_opts_str()
This patch is based on a discussion generated by an earlier patch
from Tetsuo Handa:
* https://marc.info/?t=149035659300001&r=1&w=2
The double free problem involves the mnt_opts field of the
security_mnt_opts struct, selinux_parse_opts_str() frees the memory
on error, but doesn't set the field to NULL so if the caller later
attempts to call security_free_mnt_opts() we trigger the problem.
In order to play it safe we change selinux_parse_opts_str() to call
security_free_mnt_opts() on error instead of free'ing the memory
directly. This should ensure that everything is handled correctly,
regardless of what the caller may do.
Fixes: e0007529893c1c06 ("LSM/SELinux: Interfaces to allow FS to control mount options")
Cc: stable@vger.kernel.org
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e67a526d1f30..819fd6858b49 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -1106,10 +1106,8 @@ static int selinux_parse_opts_str(char *options, | |||
1106 | 1106 | ||
1107 | opts->mnt_opts_flags = kcalloc(NUM_SEL_MNT_OPTS, sizeof(int), | 1107 | opts->mnt_opts_flags = kcalloc(NUM_SEL_MNT_OPTS, sizeof(int), |
1108 | GFP_KERNEL); | 1108 | GFP_KERNEL); |
1109 | if (!opts->mnt_opts_flags) { | 1109 | if (!opts->mnt_opts_flags) |
1110 | kfree(opts->mnt_opts); | ||
1111 | goto out_err; | 1110 | goto out_err; |
1112 | } | ||
1113 | 1111 | ||
1114 | if (fscontext) { | 1112 | if (fscontext) { |
1115 | opts->mnt_opts[num_mnt_opts] = fscontext; | 1113 | opts->mnt_opts[num_mnt_opts] = fscontext; |
@@ -1132,6 +1130,7 @@ static int selinux_parse_opts_str(char *options, | |||
1132 | return 0; | 1130 | return 0; |
1133 | 1131 | ||
1134 | out_err: | 1132 | out_err: |
1133 | security_free_mnt_opts(opts); | ||
1135 | kfree(context); | 1134 | kfree(context); |
1136 | kfree(defcontext); | 1135 | kfree(defcontext); |
1137 | kfree(fscontext); | 1136 | kfree(fscontext); |