Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: qce - revert "use __free() for a buffer that's always freed"

Commit ce8fd0500b74 ("crypto: qce - use __free() for a buffer that's
always freed") introduced a buggy use of __free(), which clang
rightfully points out:

drivers/crypto/qce/sha.c:365:3: error: cannot jump from this goto statement to its label
365 | goto err_free_ahash;
| ^
drivers/crypto/qce/sha.c:373:6: note: jump bypasses initialization of variable with __attribute__((cleanup))
373 | u8 *buf __free(kfree) = kzalloc(keylen + QCE_MAX_ALIGN_SIZE,
| ^

Jumping over a variable declared with the cleanup attribute does not
prevent the cleanup function from running; instead, the cleanup function
is called with an uninitialized value.

Moving the declaration back to the top function with __free() and a NULL
initialization would resolve the bug but that is really not much
different from the original code. Since the function is so simple and
there is no functional reason to use __free() here, just revert the
original change to resolve the issue.

Fixes: ce8fd0500b74 ("crypto: qce - use __free() for a buffer that's always freed")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/CA+G9fYtpAwXa5mUQ5O7vDLK2xN4t-kJoxgUe1ZFRT=AGqmLSRA@mail.gmail.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Nathan Chancellor and committed by
Herbert Xu
7b6092ee 472a9890

+3 -3
+3 -3
drivers/crypto/qce/sha.c
··· 3 3 * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. 4 4 */ 5 5 6 - #include <linux/cleanup.h> 7 6 #include <linux/device.h> 8 7 #include <linux/dma-mapping.h> 9 8 #include <linux/interrupt.h> ··· 336 337 struct scatterlist sg; 337 338 unsigned int blocksize; 338 339 struct crypto_ahash *ahash_tfm; 340 + u8 *buf; 339 341 int ret; 340 342 const char *alg_name; 341 343 ··· 370 370 crypto_req_done, &wait); 371 371 crypto_ahash_clear_flags(ahash_tfm, ~0); 372 372 373 - u8 *buf __free(kfree) = kzalloc(keylen + QCE_MAX_ALIGN_SIZE, 374 - GFP_KERNEL); 373 + buf = kzalloc(keylen + QCE_MAX_ALIGN_SIZE, GFP_KERNEL); 375 374 if (!buf) { 376 375 ret = -ENOMEM; 377 376 goto err_free_req; ··· 382 383 383 384 ret = crypto_wait_req(crypto_ahash_digest(req), &wait); 384 385 386 + kfree(buf); 385 387 err_free_req: 386 388 ahash_request_free(req); 387 389 err_free_ahash: