[SRU][F][PATCH 2/2] selinux: fix double free of cond_list on error paths

Koichiro Den koichiro.den at canonical.com
Mon Sep 9 02:03:29 UTC 2024


From: Vratislav Bendel <vbendel at 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.

Cc: stable at vger.kernel.org
Signed-off-by: Vratislav Bendel <vbendel at redhat.com>
[PM: fix line lengths in the description]
Signed-off-by: Paul Moore <paul at paul-moore.com>
(cherry picked from commit 186edf7e368c40d06cf727a1ad14698ea67b74ad)
CVE-2022-48740
Signed-off-by: Koichiro Den <koichiro.den at canonical.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 be1be450fc57..2b504c169cd9 100644
--- a/security/selinux/ss/conditional.c
+++ b/security/selinux/ss/conditional.c
@@ -158,6 +158,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)
@@ -472,7 +474,6 @@ int cond_read_list(struct policydb *p, void *fp)
 	return 0;
 err:
 	cond_list_destroy(p);
-	p->cond_list = NULL;
 	return rc;
 }
 
-- 
2.43.0




More information about the kernel-team mailing list