From mboxrd@z Thu Jan 1 00:00:00 1970 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 169DA19C554; Mon, 23 Jun 2025 21:27:52 +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=1750714072; cv=none; b=IgCtva/iV8xWsyUAL4e9+lmPtQMBUd1O0NvKXqBjNpePllPXS24lO9r/9NhtrRP25ikjuSB+vF4ziH//zNZN4/N+HGb7xwh7eTRTFDvjF7WNkRT1FeXtVvMwfEqzgPHxngOQpLEqvxjr0mtbQaIPTCvy6DP15hofdykeoSIK0ro= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750714072; c=relaxed/simple; bh=f03Jf5491enVbopMQvuF3HdsRtJmDI3G8STHsWJk6tU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/aSffYn+ESxcUz7L9n/ws2aiwj+sUtpLRLdHW0A2BtaQBiznKBRu2SBnl9BXLIBqS5r86HVQg9O2ZDWU8N7xsCulU9wsKmIwIyiyG1ylUTKyL41ddvlhbe1sMk7ecd5/jrsIAC5dU8v0zROVUujQRMC8Fapbcy//KD1eUQ9Kok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uN5dEWwS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="uN5dEWwS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A170FC4CEEA; Mon, 23 Jun 2025 21:27:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750714072; bh=f03Jf5491enVbopMQvuF3HdsRtJmDI3G8STHsWJk6tU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uN5dEWwS1TfPAnKYhSl1EgdqsJvxIEQ+dHoQXl/XyIKP86noqwYtVYk0cmu2mOZIX Cn+fYhynVhrACIm92mtkxhBCT270tObq5qc0yG7DvH5nZDUqnxLgVp7jlOu1wVA/6Z 7sIB6MPQAUAPL8BorQjOfuGtX5E5Bc4K9mUQUeR0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Youssef Samir , Sumit Kumar , Jeff Hugo , Krishna Chaitanya Chundru , Manivannan Sadhasivam Subject: [PATCH 6.12 079/414] bus: mhi: ep: Update read pointer only after buffer is written Date: Mon, 23 Jun 2025 15:03:36 +0200 Message-ID: <20250623130644.057671600@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130642.015559452@linuxfoundation.org> References: <20250623130642.015559452@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sumit Kumar commit 6f18d174b73d0ceeaa341f46c0986436b3aefc9a upstream. Inside mhi_ep_ring_add_element, the read pointer (rd_offset) is updated before the buffer is written, potentially causing race conditions where the host sees an updated read pointer before the buffer is actually written. Updating rd_offset prematurely can lead to the host accessing an uninitialized or incomplete element, resulting in data corruption. Invoke the buffer write before updating rd_offset to ensure the element is fully written before signaling its availability. Fixes: bbdcba57a1a2 ("bus: mhi: ep: Add support for ring management") cc: stable@vger.kernel.org Co-developed-by: Youssef Samir Signed-off-by: Youssef Samir Signed-off-by: Sumit Kumar Reviewed-by: Jeff Hugo Reviewed-by: Krishna Chaitanya Chundru Reviewed-by: Manivannan Sadhasivam Link: https://patch.msgid.link/20250409-rp_fix-v1-1-8cf1fa22ed28@quicinc.com Signed-off-by: Manivannan Sadhasivam Signed-off-by: Greg Kroah-Hartman --- drivers/bus/mhi/ep/ring.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/drivers/bus/mhi/ep/ring.c +++ b/drivers/bus/mhi/ep/ring.c @@ -131,19 +131,23 @@ int mhi_ep_ring_add_element(struct mhi_e } old_offset = ring->rd_offset; - mhi_ep_ring_inc_index(ring); dev_dbg(dev, "Adding an element to ring at offset (%zu)\n", ring->rd_offset); + buf_info.host_addr = ring->rbase + (old_offset * sizeof(*el)); + buf_info.dev_addr = el; + buf_info.size = sizeof(*el); + + ret = mhi_cntrl->write_sync(mhi_cntrl, &buf_info); + if (ret) + return ret; + + mhi_ep_ring_inc_index(ring); /* Update rp in ring context */ rp = cpu_to_le64(ring->rd_offset * sizeof(*el) + ring->rbase); memcpy_toio((void __iomem *) &ring->ring_ctx->generic.rp, &rp, sizeof(u64)); - buf_info.host_addr = ring->rbase + (old_offset * sizeof(*el)); - buf_info.dev_addr = el; - buf_info.size = sizeof(*el); - - return mhi_cntrl->write_sync(mhi_cntrl, &buf_info); + return ret; } void mhi_ep_ring_init(struct mhi_ep_ring *ring, enum mhi_ep_ring_type type, u32 id)