Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix heap buffer overflow in op_cksm function #2096

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions qemu/target/s390x/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# define LOG_DISAS(...) do { } while (0)
#endif

#define NUM_REGS 16

#include "qemu/osdep.h"
#include "cpu.h"
#include "internal.h"
Expand Down Expand Up @@ -2089,6 +2091,12 @@ static DisasJumpType op_cksm(DisasContext *s, DisasOps *o)
TCGContext *tcg_ctx = s->uc->tcg_ctx;
int r2 = get_field(s, r2);
TCGv_i64 len = tcg_temp_new_i64(tcg_ctx);

if (r2 < 0 || r2 + 1 >= NUM_REGS) {
// Handle invalid r2 index
tcg_temp_free_i64(tcg_ctx, len);
return DISAS_NORETURN;
}

gen_helper_cksm(tcg_ctx, len, tcg_ctx->cpu_env, o->in1, o->in2, tcg_ctx->regs[r2 + 1]);
set_cc_static(s);
Expand Down
Loading