From patchwork Mon Nov 6 06:21:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Longpeng (Mike, Cloud Infrastructure Service Product Dept.)" X-Patchwork-Id: 834461 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVjBr6vywz9s7m for ; Mon, 6 Nov 2017 17:21:56 +1100 (AEDT) Received: from localhost ([::1]:46641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBanC-0000cJ-Eb for incoming@patchwork.ozlabs.org; Mon, 06 Nov 2017 01:21:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBams-0000bu-Cx for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:21:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBamn-0002uF-LZ for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:21:34 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2275) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBamn-0002fk-8t for qemu-devel@nongnu.org; Mon, 06 Nov 2017 01:21:29 -0500 Received: from 172.30.72.58 (EHLO DGGEMS407-HUB.china.huawei.com) ([172.30.72.58]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DKL28774; Mon, 06 Nov 2017 14:21:22 +0800 (CST) Received: from localhost (10.177.246.209) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.361.1; Mon, 6 Nov 2017 14:21:13 +0800 From: "Longpeng(Mike)" To: , , Date: Mon, 6 Nov 2017 14:21:11 +0800 Message-ID: <1509949271-36280-1-git-send-email-longpeng2@huawei.com> X-Mailer: git-send-email 1.8.4.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.246.209] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0203.59FFFF63.003E, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f584b40ff917516236028fff4cb2c525 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH] crypto: afalg: fix a NULL pointer dereference X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: longpeng2@huawei.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Test-crypto-hash calls qcrypto_hash_bytesv/digest/base64 with errp=NULL, this will cause a NULL poniter deference 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 So we must check 'errp & *errp' before dereference. Signed-off-by: Longpeng(Mike) Reported-by: Paolo Bonzini Reviewed-by: Gonglei --- crypto/hash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/hash.c b/crypto/hash.c index ac59c63..c464c78 100644 --- a/crypto/hash.c +++ b/crypto/hash.c @@ -60,7 +60,9 @@ int qcrypto_hash_bytesv(QCryptoHashAlgorithm alg, * TODO: * Maybe we should treat some afalg errors as fatal */ - error_free(*errp); + if (errp && *errp) { + error_free(*errp); + } #endif return qcrypto_hash_lib_driver.hash_bytesv(alg, iov, niov,