mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: do not write past the end of an array
@ 2021-09-18 13:40 Martin Kaiser
  2021-09-18 14:26 ` Michael Straube
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Kaiser @ 2021-09-18 13:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, linux-staging,
	linux-kernel, Martin Kaiser

Commit f7b687d6b67e ("staging: r8188eu: remove NumTotalRFPath from struct
hal_data_8188e") removed a for loop around a block of code that is executed
only once when i == 0. However, without the for loop, i will never be set
to 0 before the code block is executed. i remains at 2, which is the final
value after the previous loop. This results in a write past the end of the
powerlevel and MCSBase arrays.

[   28.480809] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: rtl8188e_PHY_RF6052SetOFDMTxPower+0x124/0x128 [r8188eu]
[   28.493752] ---[ end Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: rtl8188e_PHY_RF6052SetOFDMTxPower+0x124/0x128 [r8188eu] ]---

Fix this by replacing i with 0 in the code block that used to be the body of
the loop. While at it, remove the powerlevel array that was just holding a
temporary value.

Tested with Edimax EW-7811Un V2 on an ARM32 embedded system.

Fixes: f7b687d6b67e ("staging: r8188eu: remove NumTotalRFPath from struct hal_data_8188e")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/hal/rtl8188e_rf6052.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_rf6052.c b/drivers/staging/r8188eu/hal/rtl8188e_rf6052.c
index 2f16c0966973..b334864feffd 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_rf6052.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_rf6052.c
@@ -227,7 +227,7 @@ static void getpowerbase88e(struct adapter *Adapter, u8 *pPowerLevelOFDM,
 {
 	struct hal_data_8188e *pHalData = GET_HAL_DATA(Adapter);
 	u32 powerBase0, powerBase1;
-	u8 i, powerlevel[2];
+	u8 i;
 
 	for (i = 0; i < 2; i++) {
 		powerBase0 = pPowerLevelOFDM[i];
@@ -238,12 +238,11 @@ static void getpowerbase88e(struct adapter *Adapter, u8 *pPowerLevelOFDM,
 
 	/* Check HT20 to HT40 diff */
 	if (pHalData->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
-		powerlevel[i] = pPowerLevelBW20[i];
+		powerBase1 = pPowerLevelBW20[0];
 	else
-		powerlevel[i] = pPowerLevelBW40[i];
-	powerBase1 = powerlevel[i];
+		powerBase1 = pPowerLevelBW40[0];
 	powerBase1 = (powerBase1 << 24) | (powerBase1 << 16) | (powerBase1 << 8) | powerBase1;
-	*(MCSBase + i) = powerBase1;
+	*MCSBase = powerBase1;
 }
 
 static void get_rx_power_val_by_reg(struct adapter *Adapter, u8 Channel,
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: r8188eu: do not write past the end of an array
  2021-09-18 13:40 [PATCH] staging: r8188eu: do not write past the end of an array Martin Kaiser
@ 2021-09-18 14:26 ` Michael Straube
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Straube @ 2021-09-18 14:26 UTC (permalink / raw)
  To: Martin Kaiser, Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, linux-staging, linux-kernel

On 9/18/21 15:40, Martin Kaiser wrote:
> Commit f7b687d6b67e ("staging: r8188eu: remove NumTotalRFPath from struct
> hal_data_8188e") removed a for loop around a block of code that is executed
> only once when i == 0. However, without the for loop, i will never be set
> to 0 before the code block is executed. i remains at 2, which is the final
> value after the previous loop. This results in a write past the end of the
> powerlevel and MCSBase arrays.
> 
> [   28.480809] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: rtl8188e_PHY_RF6052SetOFDMTxPower+0x124/0x128 [r8188eu]
> [   28.493752] ---[ end Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: rtl8188e_PHY_RF6052SetOFDMTxPower+0x124/0x128 [r8188eu] ]---
> 
> Fix this by replacing i with 0 in the code block that used to be the body of
> the loop. While at it, remove the powerlevel array that was just holding a
> temporary value.
> 

Oh, I missed that.
Many thanks for fixing this, Martin. Looks good to me.

Acked-by: Michael Straube <straube.linux@gmail.com>

Thanks,
Michael

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-18 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 13:40 [PATCH] staging: r8188eu: do not write past the end of an array Martin Kaiser
2021-09-18 14:26 ` Michael Straube

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome