mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] selinux: fix double free of cond_list on error paths
@ 2022-02-02 11:25 vbendel
  2022-02-02 16:04 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: vbendel @ 2022-02-02 11:25 UTC (permalink / raw)
  To: paul, stephen.smalley.work, eparis
  Cc: omosnace, selinux, linux-kernel, Vratislav Bendel

From: Vratislav Bendel <vbendel@redhat.com>

On error path from cond_read_list() and duplicate_policydb_cond_list()
the cond_list_destroy() gets called a second time in caller functions,
resulting in NULL pointer deref.
Fix this by resetting the cond_list_len to 0 in cond_list_destroy(),
making subsequent calls a noop.

Also consistently reset the cond_list pointer to NULL after freeing.

Signed-off-by: Vratislav Bendel <vbendel@redhat.com>
---
 security/selinux/ss/conditional.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
index 2ec6e5cd25d9..feb206f3acb4 100644
--- a/security/selinux/ss/conditional.c
+++ b/security/selinux/ss/conditional.c
@@ -152,6 +152,8 @@ static void cond_list_destroy(struct policydb *p)
 	for (i = 0; i < p->cond_list_len; i++)
 		cond_node_destroy(&p->cond_list[i]);
 	kfree(p->cond_list);
+	p->cond_list = NULL;
+	p->cond_list_len = 0;
 }
 
 void cond_policydb_destroy(struct policydb *p)
@@ -441,7 +443,6 @@ int cond_read_list(struct policydb *p, void *fp)
 	return 0;
 err:
 	cond_list_destroy(p);
-	p->cond_list = NULL;
 	return rc;
 }
 
-- 
2.26.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] selinux: fix double free of cond_list on error paths
  2022-02-02 11:25 [PATCH v2] selinux: fix double free of cond_list on error paths vbendel
@ 2022-02-02 16:04 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2022-02-02 16:04 UTC (permalink / raw)
  To: vbendel; +Cc: stephen.smalley.work, eparis, omosnace, selinux, linux-kernel

On Wed, Feb 2, 2022 at 6:25 AM <vbendel@redhat.com> wrote:
>
> From: Vratislav Bendel <vbendel@redhat.com>
>
> On error path from cond_read_list() and duplicate_policydb_cond_list()
> the cond_list_destroy() gets called a second time in caller functions,
> resulting in NULL pointer deref.
> Fix this by resetting the cond_list_len to 0 in cond_list_destroy(),
> making subsequent calls a noop.
>
> Also consistently reset the cond_list pointer to NULL after freeing.
>
> Signed-off-by: Vratislav Bendel <vbendel@redhat.com>
> ---
>  security/selinux/ss/conditional.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

I just merged this into selinux/stable-5.17 and I'll plan on sending
this up to Linus tomorrow, thanks Vratislav.

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-02 16:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 11:25 [PATCH v2] selinux: fix double free of cond_list on error paths vbendel
2022-02-02 16:04 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®