* [PATCH] selinux: fix another double free
@ 2020-06-11 15:58 trix
2020-06-11 16:36 ` Stephen Smalley
2020-06-11 17:12 ` Ondrej Mosnacek
0 siblings, 2 replies; 3+ messages in thread
From: trix @ 2020-06-11 15:58 UTC (permalink / raw)
To: paul, stephen.smalley.work, eparis, omosnace, weiyongjun1
Cc: selinux, linux-kernel, Tom Rix
From: Tom Rix <trix@redhat.com>
Clang static analysis reports this double free error
security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
kfree(node->expr.nodes);
^~~~~~~~~~~~~~~~~~~~~~~
When cond_read_node fails, it calls cond_node_destroy which frees the
node but does not poison the entry in the node list. So when it
returns to its caller cond_read_list, cond_read_list deletes the
partial list. The latest entry in the list will be deleted twice.
So instead of freeing the node in cond_read_node, let list freeing in
code_read_list handle the freeing the problem node along with all of the the
earlier nodes.
Signed-off-by: Tom Rix <trix@redhat.com>
---
security/selinux/ss/conditional.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
index da94a1b4bfda..ffb31af22f4f 100644
--- a/security/selinux/ss/conditional.c
+++ b/security/selinux/ss/conditional.c
@@ -411,7 +411,6 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
goto err;
return 0;
err:
- cond_node_destroy(node);
return rc;
}
--
2.18.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selinux: fix another double free
2020-06-11 15:58 [PATCH] selinux: fix another double free trix
@ 2020-06-11 16:36 ` Stephen Smalley
2020-06-11 17:12 ` Ondrej Mosnacek
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Smalley @ 2020-06-11 16:36 UTC (permalink / raw)
To: trix
Cc: Paul Moore, Eric Paris, Ondrej Mosnacek, weiyongjun1,
SElinux list, linux-kernel
On Thu, Jun 11, 2020 at 11:58 AM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> Clang static analysis reports this double free error
>
> security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
> kfree(node->expr.nodes);
> ^~~~~~~~~~~~~~~~~~~~~~~
>
> When cond_read_node fails, it calls cond_node_destroy which frees the
> node but does not poison the entry in the node list. So when it
> returns to its caller cond_read_list, cond_read_list deletes the
> partial list. The latest entry in the list will be deleted twice.
>
> So instead of freeing the node in cond_read_node, let list freeing in
> code_read_list handle the freeing the problem node along with all of the the
> earlier nodes.
>
> Signed-off-by: Tom Rix <trix@redhat.com>
Looks like this was introduced by
60abd3181db29ea81742106cc0ac2e27fd05b418 ("selinux: convert cond_list
to array").
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selinux: fix another double free
2020-06-11 15:58 [PATCH] selinux: fix another double free trix
2020-06-11 16:36 ` Stephen Smalley
@ 2020-06-11 17:12 ` Ondrej Mosnacek
1 sibling, 0 replies; 3+ messages in thread
From: Ondrej Mosnacek @ 2020-06-11 17:12 UTC (permalink / raw)
To: Tom Rix
Cc: Paul Moore, Stephen Smalley, Eric Paris, Wei Yongjun,
SElinux list, Linux kernel mailing list
Hi Tom,
On Thu, Jun 11, 2020 at 5:58 PM <trix@redhat.com> wrote:
> From: Tom Rix <trix@redhat.com>
>
> Clang static analysis reports this double free error
>
> security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
> kfree(node->expr.nodes);
> ^~~~~~~~~~~~~~~~~~~~~~~
>
> When cond_read_node fails, it calls cond_node_destroy which frees the
> node but does not poison the entry in the node list. So when it
> returns to its caller cond_read_list, cond_read_list deletes the
> partial list. The latest entry in the list will be deleted twice.
>
> So instead of freeing the node in cond_read_node, let list freeing in
> code_read_list handle the freeing the problem node along with all of the the
There is an extra "the" before "freeing".
> earlier nodes.
>
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
> security/selinux/ss/conditional.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
> index da94a1b4bfda..ffb31af22f4f 100644
> --- a/security/selinux/ss/conditional.c
> +++ b/security/selinux/ss/conditional.c
> @@ -411,7 +411,6 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
> goto err;
> return 0;
> err:
> - cond_node_destroy(node);
> return rc;
Since there is now just "return rc" in the error path, can you please
replace all the gotos with plain return statements? And please also
add a Fixes: tag pointing to the commit that introduced the bug (see
Stephen's reply).
Thanks,
--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-11 17:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 15:58 [PATCH] selinux: fix another double free trix
2020-06-11 16:36 ` Stephen Smalley
2020-06-11 17:12 ` Ondrej Mosnacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).