Skip to content

Commit

Permalink
selinux: fix double free of cond_list on error paths
Browse files Browse the repository at this point in the history
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: Vratislav Bendel <vbendel@redhat.com>
[PM: fix line lengths in the description]
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Vratislav Bendel authored and Paul Moore committed Feb 2, 2022
1 parent e783362 commit 186edf7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion security/selinux/ss/conditional.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 186edf7

Please sign in to comment.