Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2328524ybb; Sun, 5 Apr 2020 04:52:10 -0700 (PDT) X-Google-Smtp-Source: APiQypLV0JwyVZDfFazROoXWn+8fSTQfodAXfy1GyvhuSit5chZtR4pmnmO8ehrNNVY5N+nloG8s X-Received: by 2002:a9d:5187:: with SMTP id y7mr13390126otg.159.1586087529866; Sun, 05 Apr 2020 04:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586087529; cv=none; d=google.com; s=arc-20160816; b=DjfrJwhQthSIM/lkxa57XXqkVHu8M67/Bbp9PaLTXQuonTWM8/hDlgcA3/EsvG3lb5 cZKsyseYals9ReXyNhuC2jR3iv8zbyLfd67TL/w07bwp2RJ6QaXtBvQzfUnWONIeoe6x TyWK6+1SooRS6MY1zc/42xX6VrCeSCbzl/imYgg+dXtBFGjl9zzeCD4HJ+z3CvkDCrlS 6YmYt9yG71Z/2MadiAJ+u4omkkXhUb8ZTa+XB2NdrVKdJTIuqgKez+CTu2FbIuHcNffN M308uzNP4p05DW7++CaEpQcy91n+iYLzxx07if7rMgeKJ7bvL3vDm/7fjOixljF5y6Ja h+dQ== 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=U3anqOz9GlkVqAmpJpyLIQQ7/eK8OHNFQ3Ss4UJ19cQ=; b=eSza83yFe34ZB5ouplu1MOgqj9w2W9BmHC/DB9McexbDFaWsYK/uNMTYPCGVgCgSOR io1NpX8xJlEhOrizxIh8eXMaLAPjJwoI1ioHUyt+4XrREv3rKmoduKYGfYeW5a3v3+Id c7XtY6HX+gFHQDw9LXfXDrMMDrT537glyQjw7vBQMzv71Okt9YA4XbQgZxdt/rErhx2U +EhtqnrcFRIZcHZO4jxeDSZEePl8d5arX/rrN+Q6BFdZAiIYYmWmr3oH1XIFnmXU/mDS bWoB1lSITe1q0CwgWalYg9Rb89ZPs/myJGaNbOjxSl1nELTh3BiCDrrw9jPxA9OnK3Wc omvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 s63si6087103oig.69.2020.04.05.04.51.58; Sun, 05 Apr 2020 04:52:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1726779AbgDELux (ORCPT + 99 others); Sun, 5 Apr 2020 07:50:53 -0400 Received: from inva020.nxp.com ([92.121.34.13]:57866 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbgDELut (ORCPT ); Sun, 5 Apr 2020 07:50:49 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id CCBC61A08FF; Sun, 5 Apr 2020 13:50:47 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C06B71A08FE; Sun, 5 Apr 2020 13:50:47 +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 5AD8820466; Sun, 5 Apr 2020 13:50:47 +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 4/4] crypto: caam - fix use-after-free KASAN issue for RSA algorithms Date: Sun, 5 Apr 2020 14:50:11 +0300 Message-Id: <1586087411-8505-5-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Here's the KASAN report: BUG: KASAN: use-after-free in rsa_pub_done+0x70/0xe8 Read of size 1 at addr ffff00002267b614 by task swapper/0/0 CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.6.0-rc1-00165-ga85dda9-dirty #21 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 rsa_pub_done+0x70/0xe8 caam_jr_dequeue+0x390/0x608 tasklet_action_common.isra.13+0x1ec/0x230 ... Fixes: bf53795025a2 ("crypto: caam - add crypto_engine support for RSA algorithms") Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caampkc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 4fcae37..59cc7116 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -129,7 +129,6 @@ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context) rsa_pub_unmap(dev, edesc, req); rsa_io_unmap(dev, edesc, req); - kfree(edesc); /* * If no backlog flag, the completion of the request is done @@ -139,6 +138,8 @@ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context) akcipher_request_complete(req, ecode); else crypto_finalize_akcipher_request(jrp->engine, req, ecode); + + kfree(edesc); } static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err, @@ -170,7 +171,6 @@ static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err, } rsa_io_unmap(dev, edesc, req); - kfree(edesc); /* * If no backlog flag, the completion of the request is done @@ -180,6 +180,8 @@ static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err, akcipher_request_complete(req, ecode); else crypto_finalize_akcipher_request(jrp->engine, req, ecode); + + kfree(edesc); } /** -- 2.1.0