From patchwork Fri Feb 24 21:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 13149866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 217FCC636D7 for ; Thu, 23 Feb 2023 05:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=oX/U8359A57LwCg4Vk1G+g3u/9/3Z9HAgmWJ+SugNwQ=; b=ebsLWGIW2ZCuDW ATa3R4C5HkpaLBckszM5MlEcUVmNRLdN53a+hjBA80UQp+FdinnNcXQSngrq4cUQtx0NR5CscixRp xzXvpReFuKD55krc3g5Pp4GYem4o1hUS6CONLsn3Wf7cTpJMXIjSUrqSWYLl7+5m4CaXSlp92vroh XPkmsqeJyw/Szhqf77lcHICK77jxofsgJbhTtO3m3kaaQth2kmbL1ngNukkseOwlw5iZ9kDV7jvRa AaZT0tgCtlolXbC3hZ7KoV2n3HIQPxkr8x5ARMO6u3uPcTta4w/tRh75+MmkJMFSmXzbw0E9E3Zqb U9HMcZsrM3M+O9Z+mrDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV40j-00F8s0-5D; Thu, 23 Feb 2023 05:19:17 +0000 Received: from [42.101.60.237] (helo=mail.nfschina.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV40e-00F8pl-Hg for linux-arm-kernel@lists.infradead.org; Thu, 23 Feb 2023 05:19:14 +0000 Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 5896C1A00A14; Thu, 23 Feb 2023 13:19:44 +0800 (CST) X-Virus-Scanned: amavisd-new at nfschina.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yXrtiH0GntNQ; Thu, 23 Feb 2023 13:19:40 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 10B9E1A0092F; Thu, 23 Feb 2023 13:19:40 +0800 (CST) From: Li kunyu To: herbert@gondor.apana.org.au, davem@davemloft.net, mcoquelin.stm32@gmail.com Cc: linux-crypto@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] stm32: stm32-hash: Add kmalloc_array allocation check Date: Sat, 25 Feb 2023 05:50:19 +0800 Message-Id: <20230224215019.3687-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230222_211912_812561_0B2E6402 X-CRM114-Status: UNSURE ( 7.39 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If rctx->hw_context allocation of the context pointer failed. Returning -ENOMEM and assigning NULL to the out pointer should improve the robustness of the function. Signed-off-by: Li kunyu --- drivers/crypto/stm32/stm32-hash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index d33006d43f76..18e79f62be96 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -970,6 +970,10 @@ 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 == NULL) { + out = NULL; + return -ENOMEM; + } preg = rctx->hw_context;