From: Richard Henderson <richard.henderson@linaro.org>
To: Zhiwei Jiang <jiangzw@tecorigin.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: Re: [PATCH] tcg: Fix the overflow in indexing tcg_ctx->temps
Date: Thu, 18 Apr 2024 07:58:13 -0700 [thread overview]
Message-ID: <7c3b9a13-b503-47dc-ae02-ac9da8142605@linaro.org> (raw)
In-Reply-To: <20240418102747.27703-1-jiangzw@tecorigin.com>
On 4/18/24 03:27, Zhiwei Jiang wrote:
> Sometimes, when the address of the passed TCGTemp *ts variable is the same as tcg_ctx,
Pardon? When would TCGTemp *ts == TCGContext *tcg_ctx?
> the index calculated in the temp_idx function, i.e., ts - tcg_ctx->temps,
> can result in a particularly large value, causing overflow in the subsequent array access.
Or, assert:
size_t temp_idx(TCGTemp *ts)
{
ptrdiff_t n = ts - tcg_ctx->temps;
assert(n >= 0 && n < tcg_ctx->nb_temps);
return n;
}
> static inline TCGTemp *tcgv_i32_temp(TCGv_i32 v)
> {
> - return (void *)tcg_ctx + (uintptr_t)v;
> + return (void *)tcg_ctx->temps + (uintptr_t)v;
> }
This will generate 0 for the first temp, which will test as NULL.
r~
next prev parent reply other threads:[~2024-04-18 14:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 10:27 [PATCH] tcg: Fix the overflow in indexing tcg_ctx->temps Zhiwei Jiang
2024-04-18 14:58 ` Richard Henderson [this message]
2024-04-19 3:48 ` 回复:[PATCH] " 姜智伟
2024-04-19 9:19 ` [PATCH] " Peter Maydell
2024-04-19 9:37 ` 回复:[PATCH] " 姜智伟
2024-04-19 10:21 ` [PATCH] " Peter Maydell
2024-04-19 11:02 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7c3b9a13-b503-47dc-ae02-ac9da8142605@linaro.org \
--to=richard.henderson@linaro.org \
--cc=jiangzw@tecorigin.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).