Skip to content

Commit 73de1be

Browse files
Xiu Jianfengpcmoore
authored andcommitted
selinux: fix memleak in security_read_state_kernel()
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 <[email protected]> [PM: subject line tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent 8d6d51e commit 73de1be

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

security/selinux/ss/services.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4048,6 +4048,7 @@ int security_read_policy(struct selinux_state *state,
40484048
int security_read_state_kernel(struct selinux_state *state,
40494049
void **data, size_t *len)
40504050
{
4051+
int err;
40514052
struct selinux_policy *policy;
40524053

40534054
policy = rcu_dereference_protected(
@@ -4060,5 +4061,11 @@ int security_read_state_kernel(struct selinux_state *state,
40604061
if (!*data)
40614062
return -ENOMEM;
40624063

4063-
return __security_read_policy(policy, *data, len);
4064+
err = __security_read_policy(policy, *data, len);
4065+
if (err) {
4066+
vfree(*data);
4067+
*data = NULL;
4068+
*len = 0;
4069+
}
4070+
return err;
40644071
}

0 commit comments

Comments
 (0)