Commit 186edf7e authored by Vratislav Bendel's avatar Vratislav Bendel Committed by Paul Moore

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: stable@vger.kernel.org
Signed-off-by: default avatarVratislav Bendel <vbendel@redhat.com>
[PM: fix line lengths in the description]
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent e783362e
...@@ -152,6 +152,8 @@ static void cond_list_destroy(struct policydb *p) ...@@ -152,6 +152,8 @@ static void cond_list_destroy(struct policydb *p)
for (i = 0; i < p->cond_list_len; i++) for (i = 0; i < p->cond_list_len; i++)
cond_node_destroy(&p->cond_list[i]); cond_node_destroy(&p->cond_list[i]);
kfree(p->cond_list); kfree(p->cond_list);
p->cond_list = NULL;
p->cond_list_len = 0;
} }
void cond_policydb_destroy(struct policydb *p) void cond_policydb_destroy(struct policydb *p)
...@@ -441,7 +443,6 @@ int cond_read_list(struct policydb *p, void *fp) ...@@ -441,7 +443,6 @@ int cond_read_list(struct policydb *p, void *fp)
return 0; return 0;
err: err:
cond_list_destroy(p); cond_list_destroy(p);
p->cond_list = NULL;
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment