lkml.org 
[lkml]   [2021]   [Dec]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] security/selinux: fix potential memleak
Date
This patch try to fix potential memleak in function
selinux_fs_context_dup`s error branch.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
security/selinux/hooks.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 62d30c0a30c2..36d7fc373839 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2856,24 +2856,38 @@ static int selinux_fs_context_dup(struct fs_context *fc,
if (src->fscontext) {
opts->fscontext = kstrdup(src->fscontext, GFP_KERNEL);
if (!opts->fscontext)
- return -ENOMEM;
+ goto err_fscontext;
}
if (src->context) {
opts->context = kstrdup(src->context, GFP_KERNEL);
if (!opts->context)
- return -ENOMEM;
+ goto err_context;
}
if (src->rootcontext) {
opts->rootcontext = kstrdup(src->rootcontext, GFP_KERNEL);
if (!opts->rootcontext)
- return -ENOMEM;
+ goto err_rootcontext;
}
if (src->defcontext) {
opts->defcontext = kstrdup(src->defcontext, GFP_KERNEL);
if (!opts->defcontext)
- return -ENOMEM;
+ goto err_defcontext;
}
return 0;
+
+err_defcontext:
+ if (src->rootcontext)
+ kfree(opts->rootcontext);
+err_rootcontext:
+ if (src->context)
+ kfree(opts->context);
+err_context:
+ if (src->fscontext)
+ kfree(opts->fscontext);
+err_fscontext:
+ kfree(fc->security);
+
+ return -ENOMEM;
}

static const struct fs_parameter_spec selinux_fs_parameters[] = {
--
2.33.1
\
 
 \ /
  Last update: 2021-12-02 04:36    [W:0.053 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site