From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Richard Henderson <richard.henderson@linaro.org>
Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Subject: [PULL 6/6] hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits()
Date: Fri, 14 Aug 2026 12:09:17 +0200 [thread overview]
Message-ID: <20260814100917.163448-7-thuth@redhat.com> (raw)
In-Reply-To: <20260814100917.163448-1-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
Fixes: 1d5b128cbeea ("hw/iommu: Fix problems reported by Coverity scan")
Reviewed-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20260731140229.259272-1-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
prev parent reply other threads:[~2026-08-14 10:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 10:09 [PULL 0/6] Functional test framework improvements & bug fixes Thomas Huth
2026-08-14 10:09 ` [PULL 1/6] tests/functional: add skipWithoutSudo() decorator Thomas Huth
2026-08-14 10:09 ` [PULL 2/6] tests/functional/qemu_test: drop *args argument from .get_vm() Thomas Huth
2026-08-14 10:09 ` [PULL 3/6] tests/testcase.py: passthrough monitor_address Thomas Huth
2026-08-14 10:09 ` [PULL 4/6] hw/usb/dev-uas: Don't abort if guest provided an undersized buffer for status Thomas Huth
2026-08-14 10:09 ` [PULL 5/6] hw/net/vmxnet3: Do not abort if guest provides bad interrupt numbers Thomas Huth
2026-08-14 10:09 ` Thomas Huth [this message]
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=20260814100917.163448-7-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 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.