Skip to content

Commit 186edf7

Browse files
vbendelpcmoore
authored andcommitted
selinux: fix double free of cond_list on error paths
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: [email protected] Signed-off-by: Vratislav Bendel <[email protected]> [PM: fix line lengths in the description] Signed-off-by: Paul Moore <[email protected]>
1 parent e783362 commit 186edf7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

security/selinux/ss/conditional.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static void cond_list_destroy(struct policydb *p)
152152
for (i = 0; i < p->cond_list_len; i++)
153153
cond_node_destroy(&p->cond_list[i]);
154154
kfree(p->cond_list);
155+
p->cond_list = NULL;
156+
p->cond_list_len = 0;
155157
}
156158

157159
void cond_policydb_destroy(struct policydb *p)
@@ -441,7 +443,6 @@ int cond_read_list(struct policydb *p, void *fp)
441443
return 0;
442444
err:
443445
cond_list_destroy(p);
444-
p->cond_list = NULL;
445446
return rc;
446447
}
447448

0 commit comments

Comments
 (0)