Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2328036ybb; Sun, 5 Apr 2020 04:51:10 -0700 (PDT) X-Google-Smtp-Source: APiQypK4kL793TSKsHfTRNuQuul0NA1MezNfelwrDROEh6NJbClqqwGeZLT4Ggun9oEtK8+j0g6Q X-Received: by 2002:a9d:ef8:: with SMTP id 111mr8772183otj.94.1586087470425; Sun, 05 Apr 2020 04:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586087470; cv=none; d=google.com; s=arc-20160816; b=py8Pl/8lb2XnwVIPQXquF0ADilmNnBg8zF6UHf3punP/cW0+TDMbDQea0Dg0CejhIf 5sNUX6dtOzABct41Wnq3XuZz6/NtAhSZgCMXjFoGYcruMFgNeH5J/hOgOtsAEQzZc/KY pN6gDDMrTPeVA7BpZIro8TV8m1xaLESixJ+9cVKK7fctBxqKaG/AD/z7DA6c4LNOqZCT fpP3gtXmI4ZlxqeUuDVUkkfQGteOH/xZUhkoWdA2TRhv7BfVybdMJcBcC7kPHHD+gwXt SNe1jvSvul5B63FFGtGUDtUEB/ewrMIcrcJejFGTVsV7iSnS4ll1G86jkCNu9lu5g8UO E9Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HVuT0Fwc69aBAssLa2lJ11+LypiWoXvXAGN+A3IZQj4=; b=oP2dPeHYAmRVEWNv0hiCNlPKfh+PvD8wIa1PMTf918yiLDxA0rDKMNcxCCtwrjbj1e H2vD6go0YfCHUgdNx7nkyd5vNpoAVSO231g1MmfTcOh7ARLj377x41etOExJ68r9FuUb JNMC/m8r3fJh0RnrYS2K3zSqciEdXGtjAwWkrgzuegmVkmPzQp4Gx8SAYSvmGjDAR9z4 BxsQVdvaEpm7gCktW3lh2FTLEp9AALDTjyCFMQ7Ovj0gLWe2gE3bhx+yARiOLnSiDtII LkgO+QyWlss5HLaB7fBxfwyCnISTlvHSwo9v061swRxKa6YEtdWeV6NmxeLKKjgsd6gP kOZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i17si6705653oto.278.2020.04.05.04.50.52; Sun, 05 Apr 2020 04:51:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726696AbgDELul (ORCPT + 99 others); Sun, 5 Apr 2020 07:50:41 -0400 Received: from inva021.nxp.com ([92.121.34.21]:38552 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726575AbgDELul (ORCPT ); Sun, 5 Apr 2020 07:50:41 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 20CA92008F5; Sun, 5 Apr 2020 13:50:39 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 142012008F4; Sun, 5 Apr 2020 13:50:39 +0200 (CEST) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id A249120466; Sun, 5 Apr 2020 13:50:38 +0200 (CEST) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , Silvano Di Ninno , Franck Lenormand , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [PATCH 1/4] crypto: caam - fix use-after-free KASAN issue for SKCIPHER algorithms Date: Sun, 5 Apr 2020 14:50:08 +0300 Message-Id: <1586087411-8505-2-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1586087411-8505-1-git-send-email-iuliana.prodan@nxp.com> References: <1586087411-8505-1-git-send-email-iuliana.prodan@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Here's the KASAN report: BUG: KASAN: use-after-free in skcipher_crypt_done+0xe8/0x1a8 Read of size 1 at addr ffff00002304001c by task swapper/0/0 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc1-00162-gfcb90d5 #9 Hardware name: LS1046A RDB Board (DT) Call trace: dump_backtrace+0x0/0x260 show_stack+0x14/0x20 dump_stack+0xe8/0x144 print_address_description.isra.11+0x64/0x348 __kasan_report+0x11c/0x230 kasan_report+0xc/0x18 __asan_load1+0x5c/0x68 skcipher_crypt_done+0xe8/0x1a8 caam_jr_dequeue+0x390/0x608 tasklet_action_common.isra.13+0x1ec/0x230 ... Fixes: ee38767f152a ("crypto: caam - support crypto_engine framework for SKCIPHER algorithms") Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index b7bb7c3..5538539 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -1022,8 +1022,6 @@ static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err, DUMP_PREFIX_ADDRESS, 16, 4, req->dst, edesc->dst_nents > 1 ? 100 : req->cryptlen, 1); - kfree(edesc); - /* * If no backlog flag, the completion of the request is done * by CAAM, not crypto engine. @@ -1032,6 +1030,8 @@ static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err, skcipher_request_complete(req, ecode); else crypto_finalize_skcipher_request(jrp->engine, req, ecode); + + kfree(edesc); } /* -- 2.1.0