mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-16 04:04:06 +00:00
selinux: fix memleak in security_read_state_kernel()
[ Upstream commit 73de1befcc
]
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>
[PM: subject line tweak]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c2e08a2570
commit
9718a39fd8
1 changed files with 8 additions and 1 deletions
|
@ -4045,6 +4045,7 @@ int security_read_policy(struct selinux_state *state,
|
|||
int security_read_state_kernel(struct selinux_state *state,
|
||||
void **data, size_t *len)
|
||||
{
|
||||
int err;
|
||||
struct selinux_policy *policy;
|
||||
|
||||
policy = rcu_dereference_protected(
|
||||
|
@ -4057,5 +4058,11 @@ int security_read_state_kernel(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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue