target/s390x: Fix wrong address handling in address loops
The loop increments addr by the element stride (+= 4) before calling wrap_address, but then overwrites the loop addr with the wrapped value. On the next iteration the stride is applied to the wrapped address of the previous element, not to the original unwrapped address. This results in every element after the first is read from a wrong (wrapped) address. Fixes: 9f17bfdab4 ("target/s390x: support SHA-512 extensions") Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Message-ID: <20260706094317.17032-2-freude@linux.ibm.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Harald Freudenberger committed
Jul 6, 2026 at 11:42 UTC
fbd0f95225871f3b8f775c1874004a2b5195f1a8
1 file changed
+4
-8
target/s390x/tcg/crypto_helper.c
+4
-8
@@ -126,8 +126,7 @@ static void sha512_read_icv(CPUS390XState *env, const int mmu_idx,
126
const MemOpIdx oi = make_memop_idx(MO_BE | MO_64 | MO_UNALN, mmu_idx);
127
128
for (int i = 0; i < 8; i++, addr += 8) {
129
- addr = wrap_address(env, addr);
130
- a[i] = cpu_ldq_mmu(env, addr, oi, ra);
129
+ a[i] = cpu_ldq_mmu(env, wrap_address(env, addr), oi, ra);
130
}
131
}
132
@@ -137,8 +136,7 @@ static void sha512_write_ocv(CPUS390XState *env, const int mmu_idx,
136
const MemOpIdx oi = make_memop_idx(MO_BE | MO_64 | MO_UNALN, mmu_idx);
137
138
for (int i = 0; i < 8; i++, addr += 8) {
140
- addr = wrap_address(env, addr);
141
- cpu_stq_mmu(env, addr, a[i], oi, ra);
139
+ cpu_stq_mmu(env, wrap_address(env, addr), a[i], oi, ra);
140
}
141
}
142
@@ -148,8 +146,7 @@ static void sha512_read_block(CPUS390XState *env, const int mmu_idx,
146
const MemOpIdx oi = make_memop_idx(MO_BE | MO_64 | MO_UNALN, mmu_idx);
147
148
for (int i = 0; i < 16; i++, addr += 8) {
151
- addr = wrap_address(env, addr);
152
- a[i] = cpu_ldq_mmu(env, addr, oi, ra);
149
+ a[i] = cpu_ldq_mmu(env, wrap_address(env, addr), oi, ra);
150
}
151
}
152
@@ -159,8 +156,7 @@ static void sha512_read_mbl_be64(CPUS390XState *env, const int mmu_idx,
156
const MemOpIdx oi = make_memop_idx(MO_8, mmu_idx);
157
158
for (int i = 0; i < 16; i++, addr += 1) {
162
- addr = wrap_address(env, addr);
163
- a[i] = cpu_ldb_mmu(env, addr, oi, ra);
159
+ a[i] = cpu_ldb_mmu(env, wrap_address(env, addr), oi, ra);
160
}
161
}
162