FAILED: patch "[PATCH] firmware: samsung: acpm: Fix cross-thread RX length" failed to apply to 6.18-stable tree
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x f133bd4b5daf71bccdde0ad1a4f47fac76a6bfb1
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026061526-attention-sedative-060d@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From f133bd4b5daf71bccdde0ad1a4f47fac76a6bfb1 Mon Sep 17 00:00:00 2001
From: Tudor Ambarus <[email protected]>
Date: Tue, 5 May 2026 13:12:58 +0000
Subject: [PATCH] firmware: samsung: acpm: Fix cross-thread RX length
corruption
Sashiko identified a cross-thread RX length corruption bug when reviewing the thermal addition to ACPM [1].
When multiple threads concurrently send IPC requests, the ACPM polling mechanism can encounter responses belonging to other threads. To drain the queue, the driver saves these concurrent responses into an internal cache (rx_data->cmd) to be retrieved later by the owning thread.
Previously, the driver incorrectly used xfer->rxcnt (the expected receive length of the *current* polling thread) when copying data for *other* threads into this cache. If the threads expected responses of different lengths, this resulted in buffer underflows (leading to reads of uninitialized memory) or potential buffer overflows.
Fix this by replacing the boolean response flag in struct acpm_rx_data with rxcnt, caching the exact expected receive length for each specific transaction during transfer preparation. Use this cached length when saving concurrent responses.
Consequently, ensure that xfer->rxcnt is explicitly zeroed in driver helpers (e.g., acpm_dvfs_set_xfer) for fire-and-forget messages to prevent uninitialized stack garbage from being interpreted as a massive expected receive length.
drivers/firmware/samsung/exynos-acpm-dvfs.c +3 -0
@@ -31,6 +31,9 @@ static void acpm_dvfs_set_xfer(struct acpm_xfer *xfer, u32 *cmd, size_t cmdlen,if (response) { xfer->rxcnt = cmdlen; xfer->rxd = cmd; + }else { + xfer->rxcnt =0 ; + xfer->rxd =NULL ; } }
drivers/firmware/samsung/exynos-acpm.c +8 -7
@@ -104,12 +104,12 @@ struct acpm_queue {* * @cmd: pointer to where the data shall be saved. * @n_cmd: number of 32-bit commands. -* @response: true if the client expects the RX data. +* @rxcnt: expected length of the response in 32-bit words. */ struct acpm_rx_data {u32 *cmd;size_t n_cmd; -bool response; +size_t rxcnt; };#define ACPM_SEQNUM_MAX 64
@@ -199,7 +199,7 @@ static void acpm_get_saved_rx(struct acpm_chan *achan,const struct acpm_rx_data *rx_data = &achan->rx_data[tx_seqnum -1 ];u32 rx_seqnum; -if (!rx_data->response) +if (!rx_data->rxcnt)return ; rx_seqnum =FIELD_GET (ACPM_PROTOCOL_SEQNUM , rx_data->cmd[0 ]);
@@ -256,7 +256,7 @@ static int acpm_get_rx(struct acpm_chan *achan, const struct acpm_xfer *xfer) seqnum = rx_seqnum -1 ; rx_data = &achan->rx_data[seqnum]; -if (rx_data->response) { +if (rx_data->rxcnt) {if (rx_seqnum == tx_seqnum) {__ioread32_copy (xfer->rxd, addr, xfer->rxcnt); rx_set = true;
@@ -268,7 +268,8 @@ static int acpm_get_rx(struct acpm_chan *achan, const struct acpm_xfer *xfer)* clear yet the bitmap. It will be cleared * after the response is copied to the request. */ -__ioread32_copy (rx_data->cmd, addr, xfer->rxcnt); +__ioread32_copy (rx_data->cmd, addr, + rx_data->rxcnt); } }else {clear_bit (seqnum, achan->bitmap_seqnum);
@@ -380,8 +381,8 @@ static void acpm_prepare_xfer(struct acpm_chan *achan,/* Clear data for upcoming responses */ rx_data = &achan->rx_data[achan->seqnum -1 ];memset (rx_data->cmd,0 ,sizeof (*rx_data->cmd) * rx_data->n_cmd); -if (xfer->rxd) - rx_data->response = true; +/* zero means no response expected */ + rx_data->rxcnt = xfer->rxcnt;/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */ set_bit (achan->seqnum -1 , achan->bitmap_seqnum);
Sasha Levin
maintainerPATCH 1/1 firmware: samsung: acpm: Fix cross-thread RX length corruption
From: Tudor Ambarus <[email protected]>
[ Upstream commit f133bd4b5daf71bccdde0ad1a4f47fac76a6bfb1 ]
Sashiko identified a cross-thread RX length corruption bug when reviewing the thermal addition to ACPM [1].
When multiple threads concurrently send IPC requests, the ACPM polling mechanism can encounter responses belonging to other threads. To drain the queue, the driver saves these concurrent responses into an internal cache (rx_data->cmd) to be retrieved later by the owning thread.
Previously, the driver incorrectly used xfer->rxcnt (the expected receive length of the *current* polling thread) when copying data for *other* threads into this cache. If the threads expected responses of different lengths, this resulted in buffer underflows (leading to reads of uninitialized memory) or potential buffer overflows.
Fix this by replacing the boolean response flag in struct acpm_rx_data with rxcnt, caching the exact expected receive length for each specific transaction during transfer preparation. Use this cached length when saving concurrent responses.
Consequently, ensure that xfer->rxcnt is explicitly zeroed in driver helpers (e.g., acpm_dvfs_set_xfer) for fire-and-forget messages to prevent uninitialized stack garbage from being interpreted as a massive expected receive length.
--- drivers/firmware/samsung/exynos-acpm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/firmware/samsung/exynos-acpm.c +7 -7
@@ -103,12 +103,12 @@ struct acpm_queue {* * @cmd: pointer to where the data shall be saved. * @n_cmd: number of 32-bit commands. -* @response: true if the client expects the RX data. +* @rxcnt: expected length of the response in 32-bit words. */ struct acpm_rx_data {u32 *cmd;size_t n_cmd; -bool response; +size_t rxcnt; };#define ACPM_SEQNUM_MAX 64
@@ -196,7 +196,7 @@ static void acpm_get_saved_rx(struct acpm_chan *achan,const struct acpm_rx_data *rx_data = &achan->rx_data[tx_seqnum -1 ];u32 rx_seqnum; -if (!rx_data->response) +if (!rx_data->rxcnt)return ; rx_seqnum =FIELD_GET (ACPM_PROTOCOL_SEQNUM , rx_data->cmd[0 ]);
@@ -253,7 +253,7 @@ static int acpm_get_rx(struct acpm_chan *achan, const struct acpm_xfer *xfer) seqnum = rx_seqnum -1 ; rx_data = &achan->rx_data[seqnum]; -if (rx_data->response) { +if (rx_data->rxcnt) {if (rx_seqnum == tx_seqnum) {__ioread32_copy (xfer->rxd, addr, xfer->rxlen /4 );
@@ -267,7 +267,7 @@ static int acpm_get_rx(struct acpm_chan *achan, const struct acpm_xfer *xfer)* after the response is copied to the request. */ __ioread32_copy (rx_data->cmd, addr, - xfer->rxlen /4 ); + rx_data->rxcnt); } }else {clear_bit (seqnum, achan->bitmap_seqnum);
@@ -379,8 +379,8 @@ static void acpm_prepare_xfer(struct acpm_chan *achan,/* Clear data for upcoming responses */ rx_data = &achan->rx_data[achan->seqnum -1 ];memset (rx_data->cmd,0 ,sizeof (*rx_data->cmd) * rx_data->n_cmd); -if (xfer->rxd) - rx_data->response = true; +/* zero means no response expected */ + rx_data->rxcnt = xfer->rxlen /4 ;/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */ set_bit (achan->seqnum -1 , achan->bitmap_seqnum);
Signature · 1 line
2.53.0