Skip to contentSkip to conversation

hw/gpio: npcm7xx: fixup out-of-bounds access

PATCH Applied Patrick Venture 3 participants 4 messages Feb 26, 2025 – Mar 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/gpio: npcm7xx: fixup out-of-bounds access

The reg isn't validated to be a possible register before it's dereferenced for one case. The mmio space registered for the gpio device is 4KiB but there aren't that many registers in the struct.

Google-Bug-Id: 397469048

Change-Id I2fb8d0d3d41422baab22e8fc7e9fadd0f2ee7068
---
 hw/gpio/npcm7xx_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/gpio/npcm7xx_gpio.c +1 -2
index 23e67424c9..2916056fae 100644
@@ -220,8 +220,6 @@ static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v,
         return;
     }
 
-    diff = s->regs[reg] ^ value;
-
     switch (reg) {
     case NPCM7XX_GPIO_TLOCK1:
     case NPCM7XX_GPIO_TLOCK2:
@@ -242,6 +240,7 @@ static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v,
     case NPCM7XX_GPIO_PU:
     case NPCM7XX_GPIO_PD:
     case NPCM7XX_GPIO_IEM:
+        diff = s->regs[reg] ^ value;
         s->regs[reg] = value;
         npcm7xx_gpio_update_pins(s, diff);
         break;
Signature · 1 line
2.48.1.658.g4767266eb4-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Patrick Venture

The reg isn't validated to be a possible register before it's dereferenced for one case. The mmio space registered for the gpio device is 4KiB but there aren't that many registers in the struct.

Google-Bug-Id: 397469048
Change-Id: I2fb8d0d3d41422baab22e8fc7e9fadd0f2ee7068

^ Both lines are irrelevant on mainstream git history, otherwise:

Fixes 526dbbe0874 ("hw/gpio: Add GPIO model for Nuvoton NPCM7xx")
Quoted 4 lines
---
  hw/gpio/npcm7xx_gpio.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
#2 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Patrick Venture

The reg isn't validated to be a possible register before it's dereferenced for one case. The mmio space registered for the gpio device is 4KiB but there aren't that many registers in the struct.

Google-Bug-Id: 397469048
Change-Id: I2fb8d0d3d41422baab22e8fc7e9fadd0f2ee7068

^ Both lines are irrelevant on mainstream git history, otherwise:

Thanks, sorry, I was in a hurry last night to send this out and forgot to strip them.

Quoted 12 lines
Fixes 526dbbe0874 ("hw/gpio: Add GPIO model for Nuvoton NPCM7xx")
Quoted 4 lines
---
  hw/gpio/npcm7xx_gpio.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
#3 lore raw
In reply to Patrick Venture
Quoted 9 lines · Patrick Venture

The reg isn't validated to be a possible register before it's dereferenced for one case. The mmio space registered for the gpio device is 4KiB but there aren't that many registers in the struct.

Google-Bug-Id: 397469048

Change-Id I2fb8d0d3d41422baab22e8fc7e9fadd0f2ee7068

Applied to target-arm.next (with commit message tweaks as per Philippe's email), thanks.

-- PMM