selinux: fix double free of cond_list on error paths
PATCH v2 1/1 selinux: fix double free of cond_list on error paths
From: Vratislav Bendel <[email protected]>
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.
--- security/selinux/ss/conditional.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/selinux/ss/conditional.c +2 -1
@@ -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; }
Signature · 1 line
2.26.3
Paul Moore
maintainerQuoted 9 lines · On Wed, Feb 2, 2022 at 6:25 AM <[email protected]> wrote:
From: Vratislav Bendel <[email protected]>
On error path from
cond_read_list()andduplicate_policydb_cond_list()thecond_list_destroy()gets called a second time in caller functions, resulting in NULL pointer deref.
Fix this by resetting thecond_list_lento 0 incond_list_destroy(), making subsequent calls a noop.
Quoted 6 lines
Also consistently reset the
cond_listpointer to NULL after freeing.Signed-off-by Vratislav Bendel <[email protected]>--- 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.
Signature · 1 line
paul-moore.com