Skip to contentSkip to conversation

target/arm: Fix arithmetic underflow in SETM instruction

PATCH Applied Ido Plat 4 participants 4 messages Oct 25, 2024 – Oct 28, 2024

lore
Share & tools
lore

Ido Plat

author
#0 lore raw

PATCH 1/1 target/arm: Fix arithmetic underflow in SETM instruction

Pass the stage size to step function callback,
otherwise do_setm would hang when size is larger then page size because stage size would underflow. This fix changes do_setm to be more inline with do_setp.

Fixes 0e92818887dee ("target/arm: Implement the SET* instructions")
---
 target/arm/tcg/helper-a64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/helper-a64.c +1 -1
index 56b431faf5..8f42a28d07 100644
@@ -1348,7 +1348,7 @@ static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
     /* Do the actual memset: we leave the last partial page to SETE */
     stagesetsize = setsize & TARGET_PAGE_MASK;
     while (stagesetsize > 0) {
-        step = stepfn(env, toaddr, setsize, data, memidx, &mtedesc, ra);
+        step = stepfn(env, toaddr, stagesetsize, data, memidx, &mtedesc, ra);
         toaddr += step;
         setsize -= step;
         stagesetsize -= step;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Ido Plat

Pass the stage size to step function callback,
otherwise do_setm would hang when size is larger then page size because stage size would underflow. This fix changes do_setm to be more inline with do_setp.

Fixes 0e92818887dee ("target/arm: Implement the SET* instructions")
---
  target/arm/tcg/helper-a64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Fixes 0e92818887d ("target/arm: Implement the SET* instructions")

r~

#2 lore raw
In reply to Ido Plat
Quoted 15 lines · Ido Plat

Pass the stage size to step function callback,
otherwise do_setm would hang when size is larger then page size because stage size would underflow. This fix changes do_setm to be more inline with do_setp.

Fixes 0e92818887dee ("target/arm: Implement the SET* instructions")
---
  target/arm/tcg/helper-a64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/helper-a64.c +0 -0
index 56b431faf5..8f42a28d07 100644

target/arm/tcg/helper-a64.c static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc, · line 1354

Quoted 8 lines
target/arm/tcg/helper-a64.c +1 -1
@@ -1348,7 +1348,7 @@ static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
      /* Do the actual memset: we leave the last partial page to SETE */
      stagesetsize = setsize & TARGET_PAGE_MASK;
      while (stagesetsize > 0) {
-        step = stepfn(env, toaddr, setsize, data, memidx, &mtedesc, ra);
+        step = stepfn(env, toaddr, stagesetsize, data, memidx, &mtedesc, ra);
          toaddr += step;
          setsize -= step;
          stagesetsize -= step;

This also seems to be:

(Cc'ed now, there's no need to add it again).

Please let me know if it shouldn't.

Thanks,

/mjt

#3 lore raw
Quoted 27 lines · Michael Tokarev
Quoted 15 lines · Ido Plat

Pass the stage size to step function callback,
otherwise do_setm would hang when size is larger then page size because stage size would underflow. This fix changes do_setm to be more inline with do_setp.

Fixes 0e92818887dee ("target/arm: Implement the SET* instructions")
---
  target/arm/tcg/helper-a64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/helper-a64.c +0 -0
index 56b431faf5..8f42a28d07 100644

target/arm/tcg/helper-a64.c static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc, · line 1354

Quoted 8 lines
target/arm/tcg/helper-a64.c +1 -1
@@ -1348,7 +1348,7 @@ static void do_setm(CPUARMState *env, uint32_t syndrome, uint32_t mtedesc,
      /* Do the actual memset: we leave the last partial page to SETE */
      stagesetsize = setsize & TARGET_PAGE_MASK;
      while (stagesetsize > 0) {
-        step = stepfn(env, toaddr, setsize, data, memidx, &mtedesc, ra);
+        step = stepfn(env, toaddr, stagesetsize, data, memidx, &mtedesc, ra);
          toaddr += step;
          setsize -= step;
          stagesetsize -= step;

This also seems to be:

Quoted 5 lines

(Cc'ed now, there's no need to add it again).

Please let me know if it shouldn't.

Yes, I think it's stable material.

Applied to target-arm.next, thanks.

-- PMM