kernel_optimize_test/security/selinux/ss
Tom Rix aa449a7965 selinux: fix a double free in cond_read_node()/cond_read_list()
Clang static analysis reports this double free error

security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
        kfree(node->expr.nodes);
        ^~~~~~~~~~~~~~~~~~~~~~~

When cond_read_node fails, it calls cond_node_destroy which frees the
node but does not poison the entry in the node list.  So when it
returns to its caller cond_read_list, cond_read_list deletes the
partial list.  The latest entry in the list will be deleted twice.

So instead of freeing the node in cond_read_node, let list freeing in
code_read_list handle the freeing the problem node along with all of the
earlier nodes.

Because cond_read_node no longer does any error handling, the goto's
the error case are redundant.  Instead just return the error code.

Cc: stable@vger.kernel.org
Fixes: 60abd3181d ("selinux: convert cond_list to array")
Signed-off-by: Tom Rix <trix@redhat.com>
Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
[PM: subject line tweaks]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2020-06-16 20:25:19 -04:00
..
avtab.c selinux: avtab_init() and cond_policydb_init() return void 2020-03-05 14:55:43 -05:00
avtab.h selinux: avtab_init() and cond_policydb_init() return void 2020-03-05 14:55:43 -05:00
conditional.c selinux: fix a double free in cond_read_node()/cond_read_list() 2020-06-16 20:25:19 -04:00
conditional.h selinux: avtab_init() and cond_policydb_init() return void 2020-03-05 14:55:43 -05:00
constraint.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
context.c selinux: hash context structure directly 2020-04-17 16:04:34 -04:00
context.h selinux: move context hashing under sidtab 2020-04-17 16:04:38 -04:00
ebitmap.c selinux: hash context structure directly 2020-04-17 16:04:34 -04:00
ebitmap.h selinux: hash context structure directly 2020-04-17 16:04:34 -04:00
hashtab.c selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
hashtab.h selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
mls_types.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mls.c selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
mls.h selinux: hash context structure directly 2020-04-17 16:04:34 -04:00
policydb.c selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
policydb.h selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
services.c selinux: fix double free 2020-06-10 22:10:35 -04:00
services.h selinux: hash context structure directly 2020-04-17 16:04:34 -04:00
sidtab.c selinux: move context hashing under sidtab 2020-04-17 16:04:38 -04:00
sidtab.h selinux: move context hashing under sidtab 2020-04-17 16:04:38 -04:00
symtab.c selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00
symtab.h selinux: do not allocate hashtabs dynamically 2020-05-01 16:34:57 -04:00