The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fs: crypto: keyinfo: Fix a possible null-pointer dereference in derive_key_aes()
@ 2019-07-24 10:02 Jia-Ju Bai
  2019-07-24 16:07 ` Eric Biggers
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2019-07-24 10:02 UTC (permalink / raw)
  To: tytso, jaegeuk, ebiggers; +Cc: linux-fscrypt, linux-kernel, Jia-Ju Bai

In derive_key_aes(), tfm is assigned to NULL on line 46, and then
crypto_free_skcipher(tfm) is executed.

crypto_free_skcipher(tfm)
    crypto_skcipher_tfm(tfm)
        return &tfm->base;

Thus, a possible null-pointer dereference may occur.

To fix this bug, tfm is checked before calling crypto_free_skcipher().

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 fs/crypto/keyinfo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c
index 207ebed918c1..b419720cac54 100644
--- a/fs/crypto/keyinfo.c
+++ b/fs/crypto/keyinfo.c
@@ -66,7 +66,8 @@ static int derive_key_aes(const u8 *master_key,
 	res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
 out:
 	skcipher_request_free(req);
-	crypto_free_skcipher(tfm);
+	if (tfm)
+		crypto_free_skcipher(tfm);
 	return res;
 }
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-25  3:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-24 10:02 [PATCH] fs: crypto: keyinfo: Fix a possible null-pointer dereference in derive_key_aes() Jia-Ju Bai
2019-07-24 16:07 ` Eric Biggers
2019-07-25  3:30   ` Jia-Ju Bai
2019-07-25  3:33     ` Jia-Ju Bai
2019-07-25  3:39       ` Eric Biggers
2019-07-25  3:52         ` Jia-Ju Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox