From f1710638edb2e98008c2a733ffda63ef32b50411 Mon Sep 17 00:00:00 2001 From: Longpeng Date: Tue, 7 Nov 2017 19:32:06 +0800 Subject: crypto: afalg: fix a NULL pointer dereference Test-crypto-hash calls qcrypto_hash_bytesv/digest/base64 with errp=NULL, this will cause a NULL pointer dereference if afalg_driver doesn't support requested algos: ret = qcrypto_hash_afalg_driver.hash_bytesv(alg, iov, niov, result, resultlen, errp); if (ret == 0) { return ret; } error_free(*errp); // <--- here Because the error message is thrown away immediately, we should just pass NULL to hash_bytesv(). There is also the same problem in afalg-backend cipher & hmac, let's fix them together. Reviewed-by: Eric Blake Reported-by: Paolo Bonzini Signed-off-by: Longpeng Signed-off-by: Daniel P. Berrange --- crypto/hash.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crypto/hash.c') diff --git a/crypto/hash.c b/crypto/hash.c index ac59c63d5f..8dab25d9ea 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -48,19 +48,16 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, { #ifdef CONFIG_AF_ALG int ret; - + /* + * TODO: + * Maybe we should treat some afalg errors as fatal + */ ret = qcrypto_hash_afalg_driver.hash_bytesv(alg, iov, niov, result, resultlen, - errp); + NULL); if (ret == 0) { return ret; } - - /* - * TODO: - * Maybe we should treat some afalg errors as fatal - */ - error_free(*errp); #endif return qcrypto_hash_lib_driver.hash_bytesv(alg, iov, niov, -- cgit 1.4.1