linux/drivers/crypto
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
..
allwinner crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
amcc crypto: crypto4xx - use GFP_KERNEL for big allocations 2020-01-09 11:30:53 +08:00
amlogic crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
axis crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
bcm crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
caam crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
cavium crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
ccp crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
ccree crypto: ccree - remove unused field 2020-06-26 14:49:53 +10:00
chelsio crypto: chelsio - Fix some pr_xxx messages 2020-07-16 21:49:14 +10:00
hisilicon crypto: hisilicon/hpre - disable FLR triggered by hardware 2020-07-16 21:49:12 +10:00
inside-secure crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
marvell crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
mediatek crypto: mediatek - use AES library for GCM key derivation 2020-07-16 21:49:04 +10:00
nx crypto/nx: Remove 'pid' in vas_tx_win_attr struct 2020-04-20 16:53:14 +10:00
qat crypto: qat - fix double free in qat_uclo_create_batch_init_list 2020-07-23 17:34:17 +10:00
qce crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
rockchip crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN 2020-01-09 11:30:53 +08:00
stm32 crypto: stm32/crc32 - protect from concurrent accesses 2020-05-23 00:08:21 +10:00
ux500 crypto: ux500/hash - Add namespacing to hash_init() 2020-07-09 15:49:28 +10:00
virtio crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
vmx .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
xilinx crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
atmel-aes-regs.h
atmel-aes.c crypto: atmel-{aes,sha,tdes} - Retire crypto_platform_data 2020-01-22 16:21:09 +08:00
atmel-authenc.h crypto: remove propagation of CRYPTO_TFM_RES_* flags 2020-01-09 11:30:53 +08:00
atmel-ecc.c
atmel-i2c.c crypto: atmel-i2c - Fix wakeup fail 2020-03-20 14:36:51 +11:00
atmel-i2c.h
atmel-sha204a.c
atmel-sha-regs.h
atmel-sha.c crypto: lib/sha1 - remove unnecessary includes of linux/cryptohash.h 2020-05-08 15:32:17 +10:00
atmel-tdes-regs.h
atmel-tdes.c crypto: atmel-{aes,sha,tdes} - Retire crypto_platform_data 2020-01-22 16:21:09 +08:00
exynos-rng.c
geode-aes.c crypto: remove propagation of CRYPTO_TFM_RES_* flags 2020-01-09 11:30:53 +08:00
geode-aes.h
hifn_795x.c remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
img-hash.c crypto: img-hash - remove redundant initialization of variable err 2020-06-26 14:46:43 +10:00
ixp4xx_crypto.c crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
Kconfig crypto: sa2ul - Add crypto driver 2020-07-23 17:34:16 +10:00
Makefile crypto: sa2ul - Add crypto driver 2020-07-23 17:34:16 +10:00
mxs-dcp.c crypto: mxs-dcp - permit asynchronous skcipher as fallback 2020-07-16 21:49:03 +10:00
n2_asm.S
n2_core.c crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
n2_core.h
omap-aes-gcm.c crypto: omap-aes - avoid spamming console with self tests 2020-06-04 22:03:39 +10:00
omap-aes.c crypto: omap-aes - permit asynchronous skcipher as fallback 2020-07-16 21:49:02 +10:00
omap-aes.h crypto: omap-aes - permit asynchronous skcipher as fallback 2020-07-16 21:49:02 +10:00
omap-crypto.c crypto: omap-crypto - fix userspace copied buffer access 2020-06-04 22:03:40 +10:00
omap-crypto.h
omap-des.c crypto: omap-des - Fix sparse/compiler warnings 2020-06-26 14:46:42 +10:00
omap-sham.c crypto: omap-sham - Fix sparse/compiler warnings 2020-06-26 14:46:42 +10:00
padlock-aes.c crypto: Convert to new CPU match macros 2020-03-24 21:36:06 +01:00
padlock-sha.c crypto: Convert to new CPU match macros 2020-03-24 21:36:06 +01:00
picoxcell_crypto_regs.h
picoxcell_crypto.c crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
qcom-rng.c
s5p-sss.c crypto: s5p-sss - use crypto_shash_tfm_digest() 2020-05-08 15:32:14 +10:00
sa2ul.c crypto: sa2ul - add device links to child devices 2020-07-23 17:34:17 +10:00
sa2ul.h crypto: sa2ul - Add AEAD algorithm support 2020-07-23 17:34:17 +10:00
sahara.c crypto: sahara - permit asynchronous skcipher as fallback 2020-07-16 21:49:04 +10:00
talitos.c crypto: drivers - set the flag CRYPTO_ALG_ALLOCATES_MEMORY 2020-07-16 21:49:10 +10:00
talitos.h