selinux: fix double free of cond_list on error paths
authorVratislav Bendel <vbendel@redhat.com>
Wed, 2 Feb 2022 11:25:11 +0000 (12:25 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Feb 2022 17:30:34 +0000 (18:30 +0100)
commitf446089a268c8fc6908488e991d28a9b936293db
tree9fed7bdebd435da9d52c90239bb83766c09e8247
parent12a0a56cbae34596d3cc771d461e73ec95606e91
selinux: fix double free of cond_list on error paths

commit 186edf7e368c40d06cf727a1ad14698ea67b74ad upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/selinux/ss/conditional.c