firmware: samsung: fix stale response flag in acpm_prepare_xfer()
Subsystems (2)
PATCH 1/1 firmware: samsung: fix stale response flag in acpm_prepare_xfer()
acpm_prepare_xfer() only ever set rx_data->response to true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causing acpm_get_rx() to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.
Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.
--- drivers/firmware/samsung/exynos-acpm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/samsung/exynos-acpm.c +1 -2
@@ -380,8 +380,7 @@ 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; + rx_data->response = !!xfer->rxd;/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */ set_bit (achan->seqnum -1 , achan->bitmap_seqnum);
Signature · 1 line
2.44.2
Tudor Ambarus
maintainerHi,
Thanks for the patch!
Quoted 9 lines · Titouan Ameline de Cadeville
acpm_prepare_xfer()only ever setrx_data->responseto true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causingacpm_get_rx()to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.
How did you find this?
Sashiko identified this too when reviewing the ACPM thermal patches. I sent some fixes last week, where this bug is squashed as well:
Thanks!
ta
Quoted 20 lines
Fixes a88927b534ba ("firmware: add Exynos ACPM protocol driver")Signed-off-by Titouan Ameline de Cadeville <[email protected]>--- drivers/firmware/samsung/exynos-acpm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firmware/samsung/exynos-acpm.c +1
-2@@ -380,8 +380,7 @@ 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; + rx_data->response = !!xfer->rxd;/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */ set_bit (achan->seqnum -1 , achan->bitmap_seqnum);
I was reading through the driver code and noticed that acpm_prepare_xfer() only enters the
if (xfer->rxd) branch to set response = true
with no corresponding else to reset it to false.
Since seqnum slots are recycled, I traced what happens when a slot previously used by a response-expecting transfer gets reused by a fire-and-forget one
-> the stale true remains and the wrong branch is taken in acpm_get_rx().
Quoted 48 lines · Tudor Ambarus
Hi,
Thanks for the patch!
Quoted 9 lines · Titouan Ameline de Cadeville
acpm_prepare_xfer()only ever setrx_data->responseto true, never false. A reused sequence number slot could therefore inherit a stale true from a previous transfer that expected a response, causingacpm_get_rx()to enter the response-copy path for a fire-and-forget transfer whose rxd is NULL.Unconditionally assign the correct boolean value so the slot is fully reset on every reuse.
How did you find this?
Sashiko identified this too when reviewing the ACPM thermal patches. I sent some fixes last week, where this bug is squashed as well:
Thanks!
taQuoted 20 lines
Fixes a88927b534ba ("firmware: add Exynos ACPM protocol driver")Signed-off-by Titouan Ameline de Cadeville <[email protected]>--- drivers/firmware/samsung/exynos-acpm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firmware/samsung/exynos-acpm.c +1
-2@@ -380,8 +380,7 @@ 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; + rx_data->response = !!xfer->rxd;/* Flag the index based on seqnum. (seqnum: 1~63, bitmap: 0~62) */ set_bit (achan->seqnum -1 , achan->bitmap_seqnum);
Krzysztof Kozlowski
maintainerQuoted 6 lines · Titouan Ameline
I was reading through the driver code and noticed that
acpm_prepare_xfer()only enters theif (
xfer->rxd) branch to set response = true
with no corresponding else to reset it to false.
Quoted 8 lines
Since seqnum slots are recycled, I traced what happens when a slot previously used by a response-expecting transfer gets reused by a fire-and-forget one
-> the stale true remains and the wrong branch is taken in
acpm_get_rx().Quoted 1 line · Tudor Ambarus
This seams to duplicate Tudor's earlier patches and his solution looks more complete, so I will take his work with Reported-by credits.
Best regards,
Krzysztof