lkml.org 
[lkml]   [2022]   [Jun]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH -next] selinux: Fix memleak in security_read_policy
Date
In this function, it directly returns the result of __security_read_policy
without freeing the allocated memory in *data, cause memory leak issue,
so free the memory if __security_read_policy failed.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
security/selinux/ss/services.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 69b2734311a6..78afda6a36b8 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -4018,6 +4018,7 @@ static int __security_read_policy(struct selinux_policy *policy,
int security_read_policy(struct selinux_state *state,
void **data, size_t *len)
{
+ int err;
struct selinux_policy *policy;

policy = rcu_dereference_protected(
@@ -4030,7 +4031,13 @@ int security_read_policy(struct selinux_state *state,
if (!*data)
return -ENOMEM;

- return __security_read_policy(policy, *data, len);
+ err = __security_read_policy(policy, *data, len);
+ if (err) {
+ vfree(*data);
+ *data = NULL;
+ *len = 0;
+ }
+ return err;
}

/**
--
2.17.1
\
 
 \ /
  Last update: 2022-06-14 15:26    [W:0.048 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site