Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2406140lqp; Sun, 24 Mar 2024 18:12:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUirS/2emT8ALGSdPWfLj02d25ATECFjSpr8eoWwW497ss68kbOKRZpRmQ/hv9GYYjwOi6BrWe7hm1vbUJJi6fIOVscKKS8mNyM0f8gPA== X-Google-Smtp-Source: AGHT+IEbov0FNQJWLE/V1zpe/BTteIDHUgMSosvMeQSkMDK6zYWdlv7+zBsLzpnuXSp2KkwwEURm X-Received: by 2002:a17:90a:d48d:b0:29b:af87:1e82 with SMTP id s13-20020a17090ad48d00b0029baf871e82mr3554872pju.48.1711329147317; Sun, 24 Mar 2024 18:12:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711329147; cv=pass; d=google.com; s=arc-20160816; b=r2pZpzvhNzOlUZ8BJ5eC/pooyhPsukInOvF5NOat6aZSYJ2qT6OUejeExaq11e31/I znEoToKsmGIdEg3ylAT7uav1+Yoix+XTY5THeekLubhSr3LN8BEVOR4jzBGRZqVsFtxq LNZGHf90gt95NZjana4XEEe8/NbxEaMXzJafmiQxZOWM5BA7lT4noCN5eJ6CDYXDpz2o rQ3qAa63ByafjXxne4uyoE2jl/cPprz5vjNz8x2VPo0WNGUlaYq1rfet+XHBClzpZChU rVN/uKMPcCLIodKMZWqWqG5nbIdHZq832AlwaE/22/rx8wun4iDt5B2wSrjx0Y5Go1US IYEg== 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=YJgHJ5uTiAFdywkViLVtB7GVA7msM4FQb7fep99UrRA=; fh=IaqzKSu4ou6PBBKnyE+AkTnjQ1g9cWu4GQQuCevsY8M=; b=CYCL4qexeJlCo7jI4mI6BvrdgYzcEHWrmiqnHKuBjy19CZJ4Zh/stiPEmAzPmwegGh WhVo5AND70RtIJuD2HVa+AfIU2IfSXEAmk2N6evH5hfs1w5QrxeuBxxqxaEOQ001in6V sHuohxAoeT3ysr11ZHk6kzPT4OMaQTYbEnWIUbyXdGL3AgMKBBp/qDRaTJyIjLgtJCRp Q+7nnwjj5Nm+GTRMKG8ebJVdMXrY4bzMUIrhWQOf0CojCgUiFXAXj0IvvDheXZ8UqPSc dkGHGl0KXcQpkyAmYnpW0ycEonlQA2zTSnQTnq55OdbU5QQ2SknXhQ1JEQF9m5vr6823 ki8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OTLuE3Ka; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113600-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id me4-20020a17090b17c400b0029c7463f85asi10885119pjb.148.2024.03.24.18.12.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:12:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OTLuE3Ka; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113600-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113600-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5B6B7285519 for ; Mon, 25 Mar 2024 01:12:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E3361CE983; Sun, 24 Mar 2024 22:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OTLuE3Ka" 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 109701CDE08; Sun, 24 Mar 2024 22:46:43 +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=1711320403; cv=none; b=FaNwle0dNAaRfVZDvTZaC/rydhLT1kViEZ/kqBATsKcAzXzZnh9BEeDFlbhrabZetN0DdauYGbaM9QgwI6udeuuy1RZdDp/EX/LMj4c7vqyaSgD2WGCpccQ/MNn/qdzu38n1EPAt2oevnmcR9URoDX9vKIFfnOL7/xzo/5+j2VI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320403; c=relaxed/simple; bh=tFj2kkXecT+l6596uU5LihaJJNQADvi51+t5Ax7Pvpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oSuXNJhfWauyAehyFgBrKszsw7w5WV10pvzq0/n/8jOUvRbi65K4SNs53zbVxK8oskmLKfHJJHdWDNlaOL6ibjJ47tFfMerJv4NNcg/5IRAcX4sZruWXB4W1zlK0IxOoY13LtslHhnlSwJGmop/shtI+Sk7LFHTnlS6RhVVdevY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OTLuE3Ka; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34677C43394; Sun, 24 Mar 2024 22:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320402; bh=tFj2kkXecT+l6596uU5LihaJJNQADvi51+t5Ax7Pvpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OTLuE3Ka2gh2LpDCcvzgKDroxUNmAhrk/M0YJSSPue1QTxaQxn1WRzbg57EWbMTkc KsRVpK0dJvPR5S4D5Co1kt3QmFvdJTRuxRD7bulaJ0UKJ33giU9pmfmW32MR8NQxaD GgdueC6Hr4O8S7PQX74Cwn3uw7xBZvfR4TDB6QGxjcg9CoVJjqryJE4k31E+fEMDJ+ tg8Ztjsi0I5N5g9u3YmdlzbZ0tpFjamFk25U25gGdH6GrpSypNDd4/PidamxTMlXeK R0YNtEQkJTZOhzlN1l2TMnlIaZCpOGmoXlqMXqamlPVrEnLbOPGJE8DV4ZdZTUziDf UOLlq/7/ji4XQ== 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.8 709/715] spi: spi-mt65xx: Fix NULL pointer access in interrupt handler Date: Sun, 24 Mar 2024 18:34:48 -0400 Message-ID: <20240324223455.1342824-710-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 8d5d170d49cc4..109dac2e69df2 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(host); - 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(host); -- 2.43.0