From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org, Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH] hw/timer/hpet: Detect invalid access to TN registers
Date: Tue, 18 Feb 2025 15:37:02 +0800 [thread overview]
Message-ID: <20250218073702.3299300-1-zhao1.liu@intel.com> (raw)
"addr & 0x18" ignores invalid address, so that the trace in default
branch (trace_hpet_ram_{read|write}_invalid()) doesn't work.
Mask addr by "0x1f & ~4", in which 0x1f means to get the complete TN
registers access and ~4 means to keep any invalid address offset.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
* Note: This patch applies the changes from Rust HPET [*] to C HPET to
ensure logic consistency.
[*]: The original comment should use "(0x1f & ~4)":
https://lore.kernel.org/qemu-devel/Z6edKxYFzA6suDlj@intel.com/
---
hw/timer/hpet.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index dcff18a9871d..0f786047e54f 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -455,7 +455,7 @@ static uint64_t hpet_ram_read(void *opaque, hwaddr addr,
return 0;
}
- switch (addr & 0x18) {
+ switch (addr & (0x1f & ~4)) {
case HPET_TN_CFG: // including interrupt capabilities
return timer->config >> shift;
case HPET_TN_CMP: // comparator register
@@ -511,7 +511,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
trace_hpet_timer_id_out_of_range(timer_id);
return;
}
- switch (addr & 0x18) {
+
+ switch (addr & (0x1f & ~4)) {
case HPET_TN_CFG:
trace_hpet_ram_write_tn_cfg(addr & 4);
old_val = timer->config;
--
2.34.1
next reply other threads:[~2025-02-18 7:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 7:37 Zhao Liu [this message]
2025-02-18 8:53 ` [PATCH] hw/timer/hpet: Detect invalid access to TN registers Paolo Bonzini
2025-02-18 9:07 ` Philippe Mathieu-Daudé
2025-02-19 3:34 ` Zhao Liu
2025-02-19 9:25 ` Paolo Bonzini
2025-02-19 14:38 ` Zhao Liu
2025-02-19 6:12 ` Zhao Liu
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=20250218073702.3299300-1-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=mst@redhat.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).