From patchwork Tue Nov 2 16:47:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Toromanoff X-Patchwork-Id: 12599353 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDF8CC433EF for ; Tue, 2 Nov 2021 16:51:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8669160EB8 for ; Tue, 2 Nov 2021 16:51:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8669160EB8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=slGAwYk5CO8GRTWi3h2FPJ6eOIRYCnnlv4VWft1kv88=; b=SfpsPx0+/MmRGw a47ohKUCcIIEziofFSGUvdEyFNydX1p9D8MhlJN4wTtnIIhX/+JH2V2RQQVcmfGR812xyHj2jp6+2 50X9hZO154FfcfOOynZpZO+K8NA0Pq7x4RO+t23P4mLoJS6IRb+PDa56Ob4N/yPvMy0TMkK9scr1+ S5Tleas2q49NxuIvC8y1fwmy0Z0dLZ9A4vH8r+Thra4jO6QEiBs8HFuo6DUUuJOHRXmZ7QgdTuC00 6NgMDrVpGgKQYhA57mQZKz8c/q9TDPyAfKuFdFO0btiS8IV4PWIKF7c+B/ojFop5T+CHC8jwSUT/Y UL51ThGQskwSHqbNNKgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhwy9-002MXi-S7; Tue, 02 Nov 2021 16:49:06 +0000 Received: from mx07-00178001.pphosted.com ([185.132.182.106]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhwxm-002MNq-QY for linux-arm-kernel@lists.infradead.org; Tue, 02 Nov 2021 16:48:44 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1A2ExLrA015345; Tue, 2 Nov 2021 17:48:33 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=c3P0JBoOld0KDv09Q6IshVxFhYKHwNh/H1gEQQ26NpQ=; b=Axp26peVCEns6xCoBpdD1pmfYJufYz5n2RH3VKsPIeJYLS2E821pczRI2oue5Tsbu2U0 N1RQjAsGcowdAc/4Qh1Vi5ofoawMV4SO5LqwHKHJRrOC4cZcLgspkCHeFXMKCDC9NdK3 SO/EMokVCLI62hBgWOMoU2KNaCdyHpNOue8cASmo+ztkFeZmc4Ydf0oq38QhRDfyZwDv JScWD0mUkxDFlcMEIpq45ZVmEB9moSGEKXRio+NndKjAsqbd93QNKk2EsCR/8xrf7HYd epOsFKbgRx+B5eOhA6ZxxyvwzANPj4EWfYeQjKootGUHe3qvZJAAxrt1jzG4FvXaXAl2 DA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3c2yg3kuam-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Nov 2021 17:48:33 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 916D4100034; Tue, 2 Nov 2021 17:48:32 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 88EB323B83F; Tue, 2 Nov 2021 17:48:32 +0100 (CET) Received: from localhost (10.75.127.45) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 2 Nov 2021 17:48:32 +0100 From: Nicolas Toromanoff To: Herbert Xu , "David S . Miller" , Maxime Coquelin , Alexandre Torgue CC: Marek Vasut , Nicolas Toromanoff , Ard Biesheuvel , , , , Subject: [PATCH v2 4/8] crypto: stm32/cryp - fix race condition in crypto_engine requests Date: Tue, 2 Nov 2021 17:47:25 +0100 Message-ID: <20211102164729.9957-5-nicolas.toromanoff@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211102164729.9957-1-nicolas.toromanoff@foss.st.com> References: <20211102164729.9957-1-nicolas.toromanoff@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-02_08,2021-11-02_01,2020-04-07_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211102_094843_211233_C569A69A X-CRM114-Status: GOOD ( 16.93 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Erase key after finalizing request. The key was reseted to 0 before the crypto_finalize_.*_request() call, in some running path a pending call could run with a key={ 0 }. Fixes: 9e054ec21ef8 ("crypto: stm32 - Support for STM32 CRYP crypto module") Signed-off-by: Nicolas Toromanoff --- drivers/crypto/stm32/stm32-cryp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index 9d6ccf1eb4ce..c0903025a4cc 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -666,6 +666,8 @@ static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err) free_pages((unsigned long)buf_out, pages); } + memset(cryp->ctx->key, 0, sizeof(cryp->ctx->key)); + pm_runtime_mark_last_busy(cryp->dev); pm_runtime_put_autosuspend(cryp->dev); @@ -674,8 +676,6 @@ static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err) else crypto_finalize_skcipher_request(cryp->engine, cryp->req, err); - - memset(cryp->ctx->key, 0, cryp->ctx->keylen); } static int stm32_cryp_cpu_start(struct stm32_cryp *cryp)