From: Thomas Huth <thuth@redhat.com>
To: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>,
Sairaj Kodilkar <sarunkod@amd.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org
Subject: [PATCH] hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits()
Date: Fri, 31 Jul 2026 16:02:29 +0200 [thread overview]
Message-ID: <20260731140229.259272-1-thuth@redhat.com> (raw)
From: Thomas Huth <thuth@redhat.com>
The code in amdvi_encode_event() calls amdvi_setevent_bits() with
start = 64:
amdvi_setevent_bits(evt, addr, 64, 64);
and amdvi_setevent_bits() then calculates:
uint64_t mask = MAKE_64BIT_MASK(start, length);
but this MAKE_64BIT_MASK() macro shifts a value left by "start" bit
positions. Shifting left by more than 63 is undefined behavior and
could have unexpected results with different compilers / architectures.
Fix it by using "bitpos" instead, which was likely the original
intended behavior anyway. (bitpos is calculated as bitpos = start % 64).
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3633
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/i386/amd_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 90252c52af4..578c27ccbef 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -323,7 +323,7 @@ static void amdvi_setevent_bits(uint64_t *buffer, uint64_t value, int start,
int length)
{
int index = start / 64, bitpos = start % 64;
- uint64_t mask = MAKE_64BIT_MASK(start, length);
+ uint64_t mask = MAKE_64BIT_MASK(bitpos, length);
buffer[index] &= ~mask;
buffer[index] |= (value << bitpos) & mask;
}
--
2.55.0
reply other threads:[~2026-07-31 14:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260731140229.259272-1-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sarunkod@amd.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.