Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp403288pxm; Wed, 2 Mar 2022 18:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6E1x1aPB81NmaSfTGhEhe92rN9ytsgS4Udb0KuU2Kg3O+/pG+3h8g8QBRgF1x+LyNXtp7 X-Received: by 2002:a17:902:eb90:b0:150:172c:328d with SMTP id q16-20020a170902eb9000b00150172c328dmr33417694plg.76.1646274564539; Wed, 02 Mar 2022 18:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646274564; cv=none; d=google.com; s=arc-20160816; b=SqcWkhVvWo2X5rdxTJwTZGRfBzXRBEwbrwyT8qTRc0aixjMvmGkh/QpsjdaSaoBMEl UYrcylH2uSuAei5V0rGItO7enGUobTKvYrnqmaFMza3gJ51PWHRjkt6fjBOF0ahEz+BO WYUJ9nWaYrBEkojkD9X4VGsnmZZALOWFtT4nxZTB4MJoOojGB/OgsLl3TZa1xlCRO0uS 2JWxMWY1XCWibJgyXyS1hOpxusOu+2VvdazHeM9zaDO6cYyMNEQaLG32kEOfmkmvKVWs SrrCaR6Fs5W/jYsy0THgfXMlZHLPaarrWMP6/1BZgTZYPe8uPHCoUFLJDc9o/LNb4Fjq euzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=FMC3BThJay6ZyQySWuF7Ne1eBs8L9p34i4Q8u9HO1qM=; b=0fD/aQHT1YNCvoHp31QB8FSrzW5hoGCnXxa3mRFcWG/5otlUOpgdSrJZVstBJY00P1 JHuC6G0PNZVglLTil4puJIxH08BJ4lki0/ylV6d7O/OLpfZlf4CdKXG2okA6AfK/QzzK POofn88glbKHFj3S2C+Izt6NonGHy1w/KPjwtxOak+f4vnhJzQwu36O4YFDUhlMZagif BWW28BAIRUKJWfZhQVQ08yTWrfCgsvCA5NaF+3LYAW4cAu8P4qsMipV9eFi7ZlTTIKAN gkWYS6wX+dBpu/BfsjIWVJSAdhizDvzCjKm2MCVr7fEXN/wjNoCESWucNQQyOESMCJ+a zN0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="jo/2WOUe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i9-20020a17090a650900b001b9bdb0bf67si635205pjj.43.2022.03.02.18.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 18:29:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="jo/2WOUe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 337683B294; Wed, 2 Mar 2022 18:24:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231699AbiCCCZX (ORCPT + 99 others); Wed, 2 Mar 2022 21:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbiCCCZW (ORCPT ); Wed, 2 Mar 2022 21:25:22 -0500 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CF0222510 for ; Wed, 2 Mar 2022 18:24:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=FMC3B ThJay6ZyQySWuF7Ne1eBs8L9p34i4Q8u9HO1qM=; b=jo/2WOUeGtDJgPO95RWaY WR3aOnzsvYhdX6oLdLEJSATDcJBuaKzwxU28Ugxd0O42Fm4KGzJlbasH2mShXWXE DsYHf4iSFiZ+sk65jG5fbJHHvjaFHG5qFcOiiaZUGhSFdRCoz6tXrPKrb1ZihVZS gx+V3ywL7X3w02IuHu7YEc= Received: from localhost.localdomain (unknown [218.106.182.227]) by smtp4 (Coremail) with SMTP id HNxpCgDnb5qrJiBiPWY2Ew--.7370S4; Thu, 03 Mar 2022 10:23:51 +0800 (CST) From: Jianglei Nie To: gilad@benyossef.com, herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] crypto: ccree: Fix use after free in cc_cipher_exit() Date: Thu, 3 Mar 2022 10:23:37 +0800 Message-Id: <20220303022337.460971-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgDnb5qrJiBiPWY2Ew--.7370S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jr17WFWkKr4DKrWUtF13urg_yoWfurX_u3 4xGa4xJryUAryagw4UAw4rurWFkasavrZ5Wr4xtrWUWFyUZrn3uF1xArn7AryUZr45XFn7 GF48Kw1rur1DWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRE2YLPUUUUU== X-Originating-IP: [218.106.182.227] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiMh64jFWBxmyVCQABs7 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kfree_sensitive(ctx_p->user.key) will free the ctx_p->user.key. But ctx_p->user.key is still used in the next line, which will lead to a use after free. We can call kfree_sensitive() after dev_dbg() to avoid the uaf. Signed-off-by: Jianglei Nie --- drivers/crypto/ccree/cc_cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 78833491f534..309da6334a0a 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -257,8 +257,8 @@ static void cc_cipher_exit(struct crypto_tfm *tfm) &ctx_p->user.key_dma_addr); /* Free key buffer in context */ - kfree_sensitive(ctx_p->user.key); dev_dbg(dev, "Free key buffer in context. key=@%p\n", ctx_p->user.key); + kfree_sensitive(ctx_p->user.key); } struct tdes_keys { -- 2.25.1