Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4601122pxj; Wed, 12 May 2021 09:02:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHKkBr13q/5dvoWNQNo4hTXuh8gW/qv3A4zYUXMURGNyVjsb1c+bdEExs0ebmjs7e8mqzT X-Received: by 2002:aca:df87:: with SMTP id w129mr26922035oig.128.1620835321922; Wed, 12 May 2021 09:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835321; cv=none; d=google.com; s=arc-20160816; b=wYv7BtXRsq2Knv/WUtA2xq6ZFBUMI6z6Mp0QFUQZMpcmu5WVIZ+5/ThTy4HpFzUp+2 RGcn5Dd+fdizk9zJbzBtHtDFUHYCDM5iRqDnoamSXoBhkaDr66tESzDxU1Y4xAgWEo+C jkx54BXz93kEaxbwAPjn9jjeTlTtv5Bbbdqt1uMEyIt9JzGsBs1Wx4KAwbU4/cyXS5zH pKcWlqBfLr0sStuMpNKZXfnL+fBmtoBq7tx5LHiuAyrWVVKvpMYefUJu7+YmyRuXuklA 6vRnElv63f83uRbn1m0/sPixIoRg8Qk1HZ4SDHNeTbBriEF5FVviNfba2COjqSZFUGgo 3DQQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FfqBcIUCcPP2QthFCLbUZerZPMezMwRWqOjA8VOijfI=; b=z3icuDZGd1Jia/Tpa5CHoRmCxsVz0M0xSX7VsxSJRFUyC0S2tdMjTe+Cikt0PREfPw BVb6hgpMgbJf/y4yIfW+Z/9pYdNbXT3ZvvWEAf9v/K+4C99OFoLl0om+5OSk9h0nVVWV 8O7ZjBJeeiV3VS002umXAUnIWOgkg+9FrVJGnbi0CKZuczUQggn/Wea6KXjaPNTkhvS2 Hzhpgr97XdkU/EWKmxN39DUIMREt3VX3hWAWP4QkLu+9R+Tr4CR+ZEiQMxiK2LYm4ztF RV8MDtSXN0mN6IRFpAsj8sAV4rJVshoZoFVuae7OLA3AAFFkKSs+z7PlUm+oa0C0QChm pbGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FVlKaX8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si265949ooo.64.2021.05.12.09.01.41; Wed, 12 May 2021 09:02:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FVlKaX8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236029AbhELQB6 (ORCPT + 99 others); Wed, 12 May 2021 12:01:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:38716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235492AbhELP2N (ORCPT ); Wed, 12 May 2021 11:28:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A58866195E; Wed, 12 May 2021 15:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832398; bh=s0g5S8odRju7kFcdBL7xfjSpY3t0m+/AzXi0YNquHg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FVlKaX8uasbHqHviAiVDAUnaqs+XwVeiAxrkX5QZzllVYVEplbM4Q2xDtND4OsnF/ NfNaUwxaRgsiKS23ZTFp/XdO17kavc4YF8zbFE2KhTKauQL8ibTpqj25zlH6L70PyU QrrFcuzLdkDODwTr3rV86bI/UxCGAlx8xJ+8AhJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quanyang Wang , Mark Brown , Sasha Levin Subject: [PATCH 5.10 264/530] spi: spi-zynqmp-gqspi: fix use-after-free in zynqmp_qspi_exec_op Date: Wed, 12 May 2021 16:46:14 +0200 Message-Id: <20210512144828.501430855@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang [ Upstream commit a2c5bedb2d55dd27c642c7b9fb6886d7ad7bdb58 ] When handling op->addr, it is using the buffer "tmpbuf" which has been freed. This will trigger a use-after-free KASAN warning. Let's use temporary variables to store op->addr.val and op->cmd.opcode to fix this issue. Fixes: 1c26372e5aa9 ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework") Signed-off-by: Quanyang Wang Link: https://lore.kernel.org/r/20210416004652.2975446-5-quanyang.wang@windriver.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynqmp-gqspi.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index d6ac8fe145a1..2a0be16b2eb0 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -926,8 +926,9 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, struct zynqmp_qspi *xqspi = spi_controller_get_devdata (mem->spi->master); int err = 0, i; - u8 *tmpbuf; u32 genfifoentry = 0; + u16 opcode = op->cmd.opcode; + u64 opaddr; dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n", op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth, @@ -940,14 +941,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, genfifoentry |= xqspi->genfifobus; if (op->cmd.opcode) { - tmpbuf = kzalloc(op->cmd.nbytes, GFP_KERNEL | GFP_DMA); - if (!tmpbuf) { - mutex_unlock(&xqspi->op_lock); - return -ENOMEM; - } - tmpbuf[0] = op->cmd.opcode; reinit_completion(&xqspi->data_completion); - xqspi->txbuf = tmpbuf; + xqspi->txbuf = &opcode; xqspi->rxbuf = NULL; xqspi->bytes_to_transfer = op->cmd.nbytes; xqspi->bytes_to_receive = 0; @@ -961,13 +956,12 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, if (!wait_for_completion_timeout (&xqspi->data_completion, msecs_to_jiffies(1000))) { err = -ETIMEDOUT; - kfree(tmpbuf); goto return_err; } - kfree(tmpbuf); } if (op->addr.nbytes) { + xqspi->txbuf = &opaddr; for (i = 0; i < op->addr.nbytes; i++) { *(((u8 *)xqspi->txbuf) + i) = op->addr.val >> (8 * (op->addr.nbytes - i - 1)); -- 2.30.2