Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2492853lqp; Sun, 24 Mar 2024 23:27:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVFk6gD6Lojg4AgspvEMXz13B/uVFOYYxiLb604Hk7+7/W93rC1w24Z9WqUy+gKi7RCZdI3CIGJN9fzhTsTL7oUf5nolCBUJ4FTcS6SQ== X-Google-Smtp-Source: AGHT+IFZcVKptKh+Dc9bKkHqipLsFfhML/DuHyOFk8uqCU+WLA8mGSS0+LKwqXAWsNtCabXML18d X-Received: by 2002:a05:622a:54c:b0:431:119:1161 with SMTP id m12-20020a05622a054c00b0043101191161mr9681207qtx.5.1711348041831; Sun, 24 Mar 2024 23:27:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711348041; cv=pass; d=google.com; s=arc-20160816; b=cP9EGXHNfHgqJdk3ZwLr1BK1k2/1XADTcrak4smP76yXkJSvNNhn3ZYSKjpy1zzAsp FmPrkr8/xH2wcRAW5AtFHY836MAyMaxiVp7VLhkBksCOs0003Or7go+ZXPlO3w0xCdVP ady2y1GoGV+Befxr+qn9tnW4mdZZBZTHl0XYSCLHoOyrScwVMtn3PRntmFGqzG9Ui8Gl ez5VIIRLYBFY18fXNBExWlLO2HrwVlyAYCjb5j4fis4kQlJHcCT7ZaVdQnfs06NvSCDJ ICYXG+wVGPGWbTTK+y9nGPA2aTXbG3pNxiLZn1gU/Z1ssXzXN52+Ya/I2+0PphVNPYTP Xo4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=l75BM9g7EN4z0dUS/0J/12NjT/GqsP1rCJWkkntAG/I=; fh=IaqzKSu4ou6PBBKnyE+AkTnjQ1g9cWu4GQQuCevsY8M=; b=h7Qw2Tjq4G2qDO3ZQiH5bf6JtFUx5F0Wbxqlx3bZ89YfBKL/g4Mpm7K9sBpZoAIdIJ 7BcaHlNQyFshEZPHc8XtO7/okXRx1PBakSSz7wvompBFprRrUJhtYmPSH55dFDuEqpAi CE11I/ES7Yww6M/D/5/O5535b20iBNgyxKTcYp+zmoxQ3U3vnsFSyo/k+nHpSBjLq7AE i9JOsDBDHqtlcophfCkXY8V92O0lH5r9wXfnmJ5XAXO76bg4yABCZ38FpeLIoI8WrEPU GLYU+a05gM9audYkfVeG3J/PdnDg8oVc5nmjy4k+YAKoQgztrCAOYmiQ71gotvMGd3ax qtpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qj0ylCAm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w8-20020ac87e88000000b004314823f9dbsi3485126qtj.609.2024.03.24.23.27.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qj0ylCAm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7F8511C2C883 for ; Mon, 25 Mar 2024 06:27:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0B3518E0D0; Mon, 25 Mar 2024 00:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qj0ylCAm" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 147FA200A29; Sun, 24 Mar 2024 23:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322363; cv=none; b=tyQQwjJf9nLaWJ1oZv1JFCyrx3K0N5iGB2I4mq06/eYN910vD+w1uj/Nfp1qSu4Je4KKhs+r2MX1+J7Bf1lLOrsNDyYzRHBw5xJ1XGCbkffy3ey5gZkAvomVBEfZyDtA3Q7cxEvTw/mYQ0lROYac6WezWfuSniiuHlJLBsJbbTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322363; c=relaxed/simple; bh=ykALujLRTqqbeejv91g3Jd3N33arhpi/XGGNBZIyF6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3cmBHMGvHc3rQ1qgrxcWN8l1ubhq7m4f9Peeq0q31gPSAnBCKRscL1rK7VWGpO7jEtUKZ7gETIgWH5TmsyF52vdUp2ZtSb0ZytuAC7BeKUxchU5LSYeVxKSkjokk6hfjSy/rZWfx9RlE5DnT+Eo9a87v+t7njblWoJ1lqr/MB0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qj0ylCAm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 379D2C433C7; Sun, 24 Mar 2024 23:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322361; bh=ykALujLRTqqbeejv91g3Jd3N33arhpi/XGGNBZIyF6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qj0ylCAmVHMneoQT5yma8K6cTJtWo/zWbn/EmhKCDYoE3RAgfzthbU48WYQtjyphk 37HcKAU/od3mO6NhrpZ22TcFbHIRpPgNMKkfD4K9ZJM6bcvCNhGO91vjU8bc4qMk7Z pHh04hepidbxW63JQVjo7G3bwtDU0F29Xy6FM7EvvBmoMvszbzjlAxXVpI84gq3/NV aGKqd4pvqDEz8QXvUfev2FGVxqiUz5egwjy6yA1OYkbH/4ZcJh6NgMXVyJ2Wha0UVQ I/hBt0hbVRk4xJFqq2KgCvukJYTqeKKowsFY0GvTu5HpWyVvhUy8GxC9uD17vEQBgP AIpVOMSzwbNJg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Fei Shao , AngeloGioacchino Del Regno , Mark Brown , Sasha Levin Subject: [PATCH 6.1 444/451] spi: spi-mt65xx: Fix NULL pointer access in interrupt handler Date: Sun, 24 Mar 2024 19:12:00 -0400 Message-ID: <20240324231207.1351418-445-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Fei Shao [ Upstream commit a20ad45008a7c82f1184dc6dee280096009ece55 ] The TX buffer in spi_transfer can be a NULL pointer, so the interrupt handler may end up writing to the invalid memory and cause crashes. Add a check to trans->tx_buf before using it. Fixes: 1ce24864bff4 ("spi: mediatek: Only do dma for 4-byte aligned buffers") Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno Link: https://msgid.link/r/20240321070942.1587146-2-fshao@chromium.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-mt65xx.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 6e95efb50acbc..f9ec8742917a6 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -787,17 +787,19 @@ static irqreturn_t mtk_spi_interrupt(int irq, void *dev_id) mdata->xfer_len = min(MTK_SPI_MAX_FIFO_SIZE, len); mtk_spi_setup_packet(master); - cnt = mdata->xfer_len / 4; - iowrite32_rep(mdata->base + SPI_TX_DATA_REG, - trans->tx_buf + mdata->num_xfered, cnt); + if (trans->tx_buf) { + cnt = mdata->xfer_len / 4; + iowrite32_rep(mdata->base + SPI_TX_DATA_REG, + trans->tx_buf + mdata->num_xfered, cnt); - remainder = mdata->xfer_len % 4; - if (remainder > 0) { - reg_val = 0; - memcpy(®_val, - trans->tx_buf + (cnt * 4) + mdata->num_xfered, - remainder); - writel(reg_val, mdata->base + SPI_TX_DATA_REG); + remainder = mdata->xfer_len % 4; + if (remainder > 0) { + reg_val = 0; + memcpy(®_val, + trans->tx_buf + (cnt * 4) + mdata->num_xfered, + remainder); + writel(reg_val, mdata->base + SPI_TX_DATA_REG); + } } mtk_spi_enable_transfer(master); -- 2.43.0