Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2328362ybb; Sun, 5 Apr 2020 04:51:49 -0700 (PDT) X-Google-Smtp-Source: APiQypIdLMv//0N5106JMG5Ja3s3Z1BZU9axMUn7jKLuHcwRI7Y/fU0IjCjbqGFd0s4OOA+yfY2H X-Received: by 2002:a9d:8d0:: with SMTP id 74mr13661497otf.39.1586087509435; Sun, 05 Apr 2020 04:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586087509; cv=none; d=google.com; s=arc-20160816; b=oEuScxbQ8GgeR0cAAmqj+awvvW16E4pnMfEPNxJici9p55NZ4HvXUEBXdzWHUnwej4 9GZah07IYgj1M1+2W2HVr0D/xjPNKd2g+yumKiJrX7O8ebVWQTvBy3KgW7rV2pQVqA74 3zNKZUEt8MlXLMms53v2RsP07DJyWLOwIfapR8CxuxUO4toS5pjSPtLwUZtjkpS9DMW1 +ZWBS/+SWX1bmizCCIXVR0sj/Qovwn86xoj6lLxxsZrEv230ZwjIDMv7bwtOa0KxxzU6 wXCdocKCtmZMNiefOihOuHnJguCTC+rp+MJjrF4DhaG7BbAUWSfeyFfklad+jVBXoELJ VhSA== 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=23jbhJBp4Ma8sr49EsmqXmItE/JKXNItMswjLpQCE/0=; b=DpK5pE6R8z7k6d9qEmBzpLQlgYDJsJnDCut6BlSx4khXwL9AsiNPJsFcddZIwIuLNP k6Db+zOqS2errOWYBF62CxzGDQ07TS2QgwoC5WddvgPNv5Ndf3vNEI3vR33sg0mgRJ1y vd19b6wS1+Y4gC4VQS4OcQhZgBm5fnNtjApE+GAD7e20BsSOhfOkECuxLmXuhPPFAUb1 eAK17xsLtulfO4T3HvqC/aEts2RGZ/n1LETRq0lwTGb3lCsgf7JjkBM4vxGFFKlyfu8x L25774InApIKeWLhwhdIWE7WDs1Aa0hI25rCafe2ZZ2Q2V3ZqDqB+MgImZk1rUeF+BhO 2hzQ== 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 r5si6123848otp.241.2020.04.05.04.51.38; Sun, 05 Apr 2020 04:51:49 -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 S1726574AbgDELur (ORCPT + 99 others); Sun, 5 Apr 2020 07:50:47 -0400 Received: from inva021.nxp.com ([92.121.34.21]:38628 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbgDELur (ORCPT ); Sun, 5 Apr 2020 07:50:47 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 9D49A200900; Sun, 5 Apr 2020 13:50:45 +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 90E292008E7; Sun, 5 Apr 2020 13:50:45 +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 3159920466; Sun, 5 Apr 2020 13:50:45 +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 3/4] crypto: caam - fix use-after-free KASAN issue for HASH algorithms Date: Sun, 5 Apr 2020 14:50:10 +0300 Message-Id: <1586087411-8505-4-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 ahash_done+0xdc/0x3b8 Read of size 1 at addr ffff000022e75510 by task swapper/0/0 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc1-00164-gcb59d59-dirty #20 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 ahash_done+0xdc/0x3b8 caam_jr_dequeue+0x390/0x608 tasklet_action_common.isra.13+0x1ec/0x230 Fixes: 21b014f038d3 ("crypto: caam - add crypto_engine support for HASH algorithms") Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamhash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 943bc02..3c63fe0 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -593,7 +593,6 @@ static inline void ahash_done_cpy(struct device *jrdev, u32 *desc, u32 err, ahash_unmap_ctx(jrdev, edesc, req, digestsize, dir); memcpy(req->result, state->caam_ctx, digestsize); - kfree(edesc); print_hex_dump_debug("ctx@"__stringify(__LINE__)": ", DUMP_PREFIX_ADDRESS, 16, 4, state->caam_ctx, @@ -607,6 +606,8 @@ static inline void ahash_done_cpy(struct device *jrdev, u32 *desc, u32 err, req->base.complete(&req->base, ecode); else crypto_finalize_hash_request(jrp->engine, req, ecode); + + kfree(edesc); } static void ahash_done(struct device *jrdev, u32 *desc, u32 err, @@ -640,7 +641,6 @@ static inline void ahash_done_switch(struct device *jrdev, u32 *desc, u32 err, ecode = caam_jr_strstatus(jrdev, err); ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len, dir); - kfree(edesc); scatterwalk_map_and_copy(state->buf, req->src, req->nbytes - state->next_buflen, @@ -668,6 +668,7 @@ static inline void ahash_done_switch(struct device *jrdev, u32 *desc, u32 err, else crypto_finalize_hash_request(jrp->engine, req, ecode); + kfree(edesc); } static void ahash_done_bi(struct device *jrdev, u32 *desc, u32 err, -- 2.1.0