* [PATCH 0/4] TriCore bugfixes
@ 2023-06-12 11:32 Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 1/4] target/tricore: Fix out-of-bounds index in imask instruction Bastian Koppelmann
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Bastian Koppelmann @ 2023-06-12 11:32 UTC (permalink / raw)
To: qemu-devel; +Cc: kbastian
Hi,
this series fixes a bunch of TriCore issues on the bugtracker.
Cheers,
Bastian
Bastian Koppelmann (3):
target/tricore: Correctly fix saving PSW.CDE to CSA on call
target/tricore: Add CHECK_REG_PAIR() for insn accessing 64 bit regs
target/tricore: Fix helper_ret() not correctly restoring PSW
Siqi Chen (1):
target/tricore: Fix out-of-bounds index in imask instruction
target/tricore/op_helper.c | 15 ++++++++++-----
target/tricore/translate.c | 12 ++++++++++--
2 files changed, 20 insertions(+), 7 deletions(-)
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] target/tricore: Fix out-of-bounds index in imask instruction
2023-06-12 11:32 [PATCH 0/4] TriCore bugfixes Bastian Koppelmann
@ 2023-06-12 11:32 ` Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 2/4] target/tricore: Correctly fix saving PSW.CDE to CSA on call Bastian Koppelmann
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Bastian Koppelmann @ 2023-06-12 11:32 UTC (permalink / raw)
To: qemu-devel; +Cc: kbastian, Siqi Chen
From: Siqi Chen <coc.cyqh@gmail.com>
When translating "imask" instruction of Tricore architecture, QEMU did not check whether the register index was out of bounds, resulting in a global-buffer-overflow.
Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1698
Reported-by: Siqi Chen <coc.cyqh@gmail.com>
Signed-off-by: Siqi Chen <coc.cyqh@gmail.com>
Message-Id: <20230612065633.149152-1-coc.cyqh@gmail.com>
---
target/tricore/translate.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index cd33a1dcdd..3b8d3f53ee 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -5331,6 +5331,7 @@ static void decode_rcrw_insert(DisasContext *ctx)
switch (op2) {
case OPC2_32_RCRW_IMASK:
+ CHECK_REG_PAIR(r4);
tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
tcg_gen_movi_tl(temp2, (1 << width) - 1);
tcg_gen_shl_tl(cpu_gpr_d[r4 + 1], temp2, temp);
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] target/tricore: Correctly fix saving PSW.CDE to CSA on call
2023-06-12 11:32 [PATCH 0/4] TriCore bugfixes Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 1/4] target/tricore: Fix out-of-bounds index in imask instruction Bastian Koppelmann
@ 2023-06-12 11:32 ` Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 3/4] target/tricore: Add CHECK_REG_PAIR() for insn accessing 64 bit regs Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 4/4] target/tricore: Fix helper_ret() not correctly restoring PSW Bastian Koppelmann
3 siblings, 0 replies; 5+ messages in thread
From: Bastian Koppelmann @ 2023-06-12 11:32 UTC (permalink / raw)
To: qemu-devel; +Cc: kbastian
we don't want to save PSW.CDC to the CSA, but PSW.CDE must be saved.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1699
Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
target/tricore/op_helper.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
index 54f54811d9..d3c836ecd9 100644
--- a/target/tricore/op_helper.c
+++ b/target/tricore/op_helper.c
@@ -2447,7 +2447,12 @@ void helper_call(CPUTriCoreState *env, uint32_t next_pc)
}
/* PSW.CDE = 1;*/
psw |= MASK_PSW_CDE;
- psw_write(env, psw);
+ /*
+ * we need to save PSW.CDE and not PSW.CDC into the CSAs. psw already
+ * contains the CDC from cdc_increment(), so we cannot call psw_write()
+ * here.
+ */
+ env->PSW |= MASK_PSW_CDE;
/* tmp_FCX = FCX; */
tmp_FCX = env->FCX;
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] target/tricore: Add CHECK_REG_PAIR() for insn accessing 64 bit regs
2023-06-12 11:32 [PATCH 0/4] TriCore bugfixes Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 1/4] target/tricore: Fix out-of-bounds index in imask instruction Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 2/4] target/tricore: Correctly fix saving PSW.CDE to CSA on call Bastian Koppelmann
@ 2023-06-12 11:32 ` Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 4/4] target/tricore: Fix helper_ret() not correctly restoring PSW Bastian Koppelmann
3 siblings, 0 replies; 5+ messages in thread
From: Bastian Koppelmann @ 2023-06-12 11:32 UTC (permalink / raw)
To: qemu-devel; +Cc: kbastian, Siqi Chen
some insns were not checking if an even index was used to access a 64
bit register. In the worst case that could lead to a buffer overflow as
reported in https://gitlab.com/qemu-project/qemu/-/issues/1698.
Reported-by: Siqi Chen <coc.cyqh@gmail.com>
Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
target/tricore/translate.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index 3b8d3f53ee..2a947e9bd5 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -309,6 +309,7 @@ static void gen_cmpswap(DisasContext *ctx, int reg, TCGv ea)
{
TCGv temp = tcg_temp_new();
TCGv temp2 = tcg_temp_new();
+ CHECK_REG_PAIR(reg);
tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
tcg_gen_movcond_tl(TCG_COND_EQ, temp2, cpu_gpr_d[reg+1], temp,
cpu_gpr_d[reg], temp);
@@ -321,7 +322,7 @@ static void gen_swapmsk(DisasContext *ctx, int reg, TCGv ea)
TCGv temp = tcg_temp_new();
TCGv temp2 = tcg_temp_new();
TCGv temp3 = tcg_temp_new();
-
+ CHECK_REG_PAIR(reg);
tcg_gen_qemu_ld_tl(temp, ea, ctx->mem_idx, MO_LEUL);
tcg_gen_and_tl(temp2, cpu_gpr_d[reg], cpu_gpr_d[reg+1]);
tcg_gen_andc_tl(temp3, temp, cpu_gpr_d[reg+1]);
@@ -3219,6 +3220,7 @@ static void decode_src_opc(DisasContext *ctx, int op1)
break;
case OPC1_16_SRC_MOV_E:
if (has_feature(ctx, TRICORE_FEATURE_16)) {
+ CHECK_REG_PAIR(r1);
tcg_gen_movi_tl(cpu_gpr_d[r1], const4);
tcg_gen_sari_tl(cpu_gpr_d[r1+1], cpu_gpr_d[r1], 31);
} else {
@@ -6172,6 +6174,7 @@ static void decode_rr_divide(DisasContext *ctx)
tcg_gen_sari_tl(cpu_gpr_d[r3+1], cpu_gpr_d[r1], 31);
break;
case OPC2_32_RR_DVINIT_U:
+ CHECK_REG_PAIR(r3);
/* overflow = (D[b] == 0) */
tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_PSW_V, cpu_gpr_d[r2], 0);
tcg_gen_shli_tl(cpu_PSW_V, cpu_PSW_V, 31);
@@ -6200,6 +6203,7 @@ static void decode_rr_divide(DisasContext *ctx)
break;
case OPC2_32_RR_DIV:
if (has_feature(ctx, TRICORE_FEATURE_16)) {
+ CHECK_REG_PAIR(r3);
GEN_HELPER_RR(divide, cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r1],
cpu_gpr_d[r2]);
} else {
@@ -6208,6 +6212,7 @@ static void decode_rr_divide(DisasContext *ctx)
break;
case OPC2_32_RR_DIV_U:
if (has_feature(ctx, TRICORE_FEATURE_16)) {
+ CHECK_REG_PAIR(r3);
GEN_HELPER_RR(divide_u, cpu_gpr_d[r3], cpu_gpr_d[r3+1],
cpu_gpr_d[r1], cpu_gpr_d[r2]);
} else {
@@ -6734,6 +6739,8 @@ static void decode_rrr2_msub(DisasContext *ctx)
cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
break;
case OPC2_32_RRR2_MSUB_U_64:
+ CHECK_REG_PAIR(r4);
+ CHECK_REG_PAIR(r3);
gen_msubu64_d(cpu_gpr_d[r4], cpu_gpr_d[r4+1], cpu_gpr_d[r1],
cpu_gpr_d[r3], cpu_gpr_d[r3+1], cpu_gpr_d[r2]);
break;
@@ -7817,7 +7824,7 @@ static void decode_rrrw_extract_insert(DisasContext *ctx)
break;
case OPC2_32_RRRW_IMASK:
temp2 = tcg_temp_new();
-
+ CHECK_REG_PAIR(r4);
tcg_gen_andi_tl(temp, cpu_gpr_d[r3], 0x1f);
tcg_gen_movi_tl(temp2, (1 << width) - 1);
tcg_gen_shl_tl(temp2, temp2, temp);
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] target/tricore: Fix helper_ret() not correctly restoring PSW
2023-06-12 11:32 [PATCH 0/4] TriCore bugfixes Bastian Koppelmann
` (2 preceding siblings ...)
2023-06-12 11:32 ` [PATCH 3/4] target/tricore: Add CHECK_REG_PAIR() for insn accessing 64 bit regs Bastian Koppelmann
@ 2023-06-12 11:32 ` Bastian Koppelmann
3 siblings, 0 replies; 5+ messages in thread
From: Bastian Koppelmann @ 2023-06-12 11:32 UTC (permalink / raw)
To: qemu-devel; +Cc: kbastian
We are always taking the TRICORE_FEATURE_13 branch as every CPU has TRICORE_FEATURE_13.
For CPUs with ISA > 1.3 we have to take the else branch.
We fix this by inverting the condition. We check for
TRICORE_FEATURE_131, which every CPU except TRICORE_FEATURE_13 CPUs
have.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1700
Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
target/tricore/op_helper.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
index d3c836ecd9..cbc46b2a5f 100644
--- a/target/tricore/op_helper.c
+++ b/target/tricore/op_helper.c
@@ -2532,12 +2532,12 @@ void helper_ret(CPUTriCoreState *env)
/* PCXI = new_PCXI; */
env->PCXI = new_PCXI;
- if (tricore_feature(env, TRICORE_FEATURE_13)) {
- /* PSW = new_PSW */
- psw_write(env, new_PSW);
- } else {
+ if (tricore_feature(env, TRICORE_FEATURE_131)) {
/* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
psw_write(env, (new_PSW & ~(0x3000000)) + (psw & (0x3000000)));
+ } else { /* TRICORE_FEATURE_13 only */
+ /* PSW = new_PSW */
+ psw_write(env, new_PSW);
}
}
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-12 11:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-12 11:32 [PATCH 0/4] TriCore bugfixes Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 1/4] target/tricore: Fix out-of-bounds index in imask instruction Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 2/4] target/tricore: Correctly fix saving PSW.CDE to CSA on call Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 3/4] target/tricore: Add CHECK_REG_PAIR() for insn accessing 64 bit regs Bastian Koppelmann
2023-06-12 11:32 ` [PATCH 4/4] target/tricore: Fix helper_ret() not correctly restoring PSW Bastian Koppelmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).