linux_dsm_epyc7002/drivers/crypto/qat
Tom Rix c06c76602e crypto: qat - fix double free in qat_uclo_create_batch_init_list
clang static analysis flags this error

qat_uclo.c:297:3: warning: Attempt to free released memory
  [unix.Malloc]
                kfree(*init_tab_base);
                ^~~~~~~~~~~~~~~~~~~~~

When input *init_tab_base is null, the function allocates memory for
the head of the list.  When there is problem allocating other list
elements the list is unwound and freed.  Then a check is made if the
list head was allocated and is also freed.

Keeping track of the what may need to be freed is the variable 'tail_old'.
The unwinding/freeing block is

	while (tail_old) {
		mem_init = tail_old->next;
		kfree(tail_old);
		tail_old = mem_init;
	}

The problem is that the first element of tail_old is also what was
allocated for the list head

		init_header = kzalloc(sizeof(*init_header), GFP_KERNEL);
		...
		*init_tab_base = init_header;
		flag = 1;
	}
	tail_old = init_header;

So *init_tab_base/init_header are freed twice.

There is another problem.
When the input *init_tab_base is non null the tail_old is calculated by
traveling down the list to first non null entry.

	tail_old = init_header;
	while (tail_old->next)
		tail_old = tail_old->next;

When the unwinding free happens, the last entry of the input list will
be freed.

So the freeing needs a general changed.
If locally allocated the first element of tail_old is freed, else it
is skipped.  As a bit of cleanup, reset *init_tab_base if it came in
as null.

Fixes: b4b7e67c91 ("crypto: qat - Intel(R) QAT ucode part of fw loader")
Cc: <stable@vger.kernel.org>
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2020-07-23 17:34:17 +10:00
..
qat_c3xxx crypto: qat - convert to SPDX License Identifiers 2020-06-18 17:19:44 +10:00
qat_c3xxxvf crypto: qat - convert to SPDX License Identifiers 2020-06-18 17:19:44 +10:00
qat_c62x crypto: qat - convert to SPDX License Identifiers 2020-06-18 17:19:44 +10:00
qat_c62xvf crypto: qat - convert to SPDX License Identifiers 2020-06-18 17:19:44 +10:00
qat_common crypto: qat - fix double free in qat_uclo_create_batch_init_list 2020-07-23 17:34:17 +10:00
qat_dh895xcc crypto: qat - replace user types with kernel u types 2020-06-18 17:26:41 +10:00
qat_dh895xccvf crypto: qat - convert to SPDX License Identifiers 2020-06-18 17:19:44 +10:00
Kconfig crypto: skcipher - rename the crypto_blkcipher module and kconfig option 2019-11-01 13:42:47 +08:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00