Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp664069pxb; Thu, 24 Mar 2022 04:53:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaHqueuF6lyhKDZQFIdPnreZukC01ex9+YUa9IdEXDcXUW7GcFKsDm9ppm1M2cIHjKdqM2 X-Received: by 2002:a05:6402:3593:b0:419:7a2d:4b0b with SMTP id y19-20020a056402359300b004197a2d4b0bmr6119881edc.39.1648122791131; Thu, 24 Mar 2022 04:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648122791; cv=none; d=google.com; s=arc-20160816; b=lIGeff2i4sfOiZeivDg2jUtBiOaLtgTT+DUB2zM5QMvuZd/gW/ky58iXggrpDsp322 PQFKvM3x+/sJ+n9vp1v8sizytYyehW6Lmsu7ndcz/hdEXU2N+akFgw710jdE4w+voyJI RXytGobXUCxgkiDxFBrUythVgZN/OzylaL2uBxyZrXezYHVuTlPknf1AEGjCr6NADfS0 /0Ac2agL3Hxb5LAr0BKq533xtxhCUS/rYfvdmGsflWpAcxDvxRK0vA+b773k+J0OFTT3 tf/yXZz77lfv8gL7Md/gBWN0V0y/XRzbaWGBGuRexAPKctmUXLXVWZ9gn+1jO7Ugiz6s 4sWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=Fj18xbrLORt0+H0IrJpnPpEvXa/QkSFc+cbAzNAcUnk=; b=xf+znQp01Awi0Mq/XyQoUXwfezbH++xs9J00qn8ESiurLYfGFG0vI3Dt4Y9Lj01AsQ ++d9IiW+Be0ag8QWI5pS+97f69WDZfDMsNxIhjyN9ldhcvpkwma+a+YnlgY2YaGSQgI2 GmBhXiY46fIx3Pb/NSTfHeUgdQEecijW7em6LwJaG4LGkqzYbxUfHmENov7UeLurjASH UWpxCm6UPHmzFAonZjludHhgZvrhvYF2els/Qj6kyKr9GxzrPHzm8/XJxgFXF2guIorw hF4UDjCPHmeUAkZqYr68Iudo9DpjoL5pk4wLQXcdJX3f3RI47zVesnW9/H5RAwrCh9n1 uXgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Hw/rnSvs"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a170906a09800b006df76385ddcsi13750147ejy.636.2022.03.24.04.52.32; Thu, 24 Mar 2022 04:53:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Hw/rnSvs"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242175AbiCXJ4V (ORCPT + 99 others); Thu, 24 Mar 2022 05:56:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241065AbiCXJ4U (ORCPT ); Thu, 24 Mar 2022 05:56:20 -0400 X-Greylist: delayed 944 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 24 Mar 2022 02:54:48 PDT Received: from m12-11.163.com (m12-11.163.com [220.181.12.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 556BA5C863 for ; Thu, 24 Mar 2022 02:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Fj18xbrLORt0+H0IrJ pnPpEvXa/QkSFc+cbAzNAcUnk=; b=Hw/rnSvsruhki0fAY1KK6s/rTCVy9vOK1T L0Za/aUCSwA8zzg0Ub6iPBVuurlyFZQlRiOoFxioOCDj+FF0LWe/DIaBmiU4YO/D APfqWpnyEIgyXL9y9vwXJLUWrviXUyI5Szcj0PRg7CoKzxXZgR356Z2OU2Fe78GG TaSuRctMw= Received: from localhost (unknown [159.226.95.33]) by smtp7 (Coremail) with SMTP id C8CowAAHBI4GPDxit6YIEA--.9600S2; Thu, 24 Mar 2022 17:38:14 +0800 (CST) From: QintaoShen To: herbert@gondor.apana.org.au Cc: davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, QintaoShen Subject: [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array() Date: Thu, 24 Mar 2022 17:38:12 +0800 Message-Id: <1648114692-11175-1-git-send-email-unSimple1993@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: C8CowAAHBI4GPDxit6YIEA--.9600S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrZw1rZry5tr1rZw1kJFyfCrg_yoWfZwc_CF 18Wr97W34jv392yrsFq393XryYqr4fZ3s29a90yF13t345Z3yfW3WxWrZxAF43C3y8K3W8 C3WxCry2yr17XjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7VUUpRRPUUUUU== X-Originating-IP: [159.226.95.33] X-CM-SenderInfo: 5xqvxz5sohimizt6il2tof0z/1tbiNBvNH1aD-KvjPQABsg X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org As the potential failure of memory allocation, kmalloc_array() may return NULL and lead to NULL pointer dereference because of the usage of 'rctx->hw_context'. Therefore, it is better to check the return value of kmalloc_array(). Signed-off-by: QintaoShen --- drivers/crypto/stm32/stm32-hash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index d33006d..f1a1a13 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -970,7 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out) rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER, sizeof(u32), GFP_KERNEL); - + if (!rctx->hw_context) + return -ENOMEM; preg = rctx->hw_context; *preg++ = stm32_hash_read(hdev, HASH_IMR); -- 2.7.4