* [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init
@ 2026-11-17 12:29 Habil Eren Türker
2026-11-19 19:40 ` Dave Hansen
0 siblings, 1 reply; 5+ messages in thread
From: Habil Eren Türker @ 2026-11-17 12:29 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Habil Eren Türker, Daniel J Blueman,
Jiri Wiesner, linux-kernel
The following variables are only written during early boot or __init
functions and remain read-only at runtime:
- hpet_blockid: set once in acpi_parse_hpet() (__init)
- hpet_msi_disable: set only in force_disable_hpet_msi() (early PCI quirk)
- hpet_freq: set only in hpet_enable() (__init)
- boot_hpet_disable: set only in force_disable_hpet() (early-quirks.c)
and __init setup functions (hpet_setup(), disable_hpet(),
hpet_is_pc10_damaged())
Mark them as __ro_after_init to protect them against unintended runtime
modifications.
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
arch/x86/kernel/hpet.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 0edf0fe0ac2b..681660b8e548 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -51,8 +51,8 @@ struct hpet_base {
* HPET address is set in acpi/boot.c, when an ACPI entry exists
*/
unsigned long hpet_address;
-u8 hpet_blockid; /* OS timer block num */
-bool hpet_msi_disable;
+u8 hpet_blockid __ro_after_init; /* OS timer block num */
+bool hpet_msi_disable __ro_after_init;
#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_GENERIC_MSI_IRQ)
static DEFINE_PER_CPU(struct hpet_channel *, cpu_hpet_channel);
@@ -64,9 +64,9 @@ static void __iomem *hpet_virt_address;
static struct hpet_base hpet_base;
static bool hpet_legacy_int_enabled;
-static unsigned long hpet_freq;
+static unsigned long hpet_freq __ro_after_init;
-bool boot_hpet_disable;
+bool boot_hpet_disable __ro_after_init;
bool hpet_force_user;
static bool hpet_verbose;
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init
2026-11-17 12:29 [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init Habil Eren Türker
@ 2026-11-19 19:40 ` Dave Hansen
2026-11-19 20:37 ` Habil Eren Türker
0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2026-11-19 19:40 UTC (permalink / raw)
To: Habil Eren Türker, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Daniel J Blueman, Jiri Wiesner, linux-kernel
On 11/17/26 04:29, Habil Eren Türker wrote:
> The following variables are only written during early boot or __init
> functions and remain read-only at runtime:
>
> - hpet_blockid: set once in acpi_parse_hpet() (__init)
> - hpet_msi_disable: set only in force_disable_hpet_msi() (early PCI quirk)
> - hpet_freq: set only in hpet_enable() (__init)
> - boot_hpet_disable: set only in force_disable_hpet() (early-quirks.c)
> and __init setup functions (hpet_setup(), disable_hpet(),
> hpet_is_pc10_damaged())
>
> Mark them as __ro_after_init to protect them against unintended runtime
> modifications.
How did you find this? Why does it matter?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init
2026-11-19 19:40 ` Dave Hansen
@ 2026-11-19 20:37 ` Habil Eren Türker
2026-11-19 22:44 ` Dave Hansen
0 siblings, 1 reply; 5+ messages in thread
From: Habil Eren Türker @ 2026-11-19 20:37 UTC (permalink / raw)
To: dave.hansen
Cc: bp, daniel, dave.hansen, Habil Eren Türker, hpa, jwiesner,
linux-kernel, mingo, tglx, x86
On Thu, 19 Nov 2026, 11:40:32, -0800, Dave Hansen wrote:
> How did you find this? Why does it matter?
Hi Dave,
I found this by auditing the HPET code for variables that are only
written during early boot. I used `git grep` to trace every write
access to these variables and confirmed that all modifications happen
exclusively in __init functions or early setup paths.
Here is the exact breakdown from the tree:
- hpet_blockid: Written only in acpi_parse_hpet()
(arch/x86/kernel/acpi/boot.c:907), which is an __init function.
- hpet_msi_disable: Written only in early_disable_hpet_msi()
(arch/x86/kernel/quirks.c:529), an early PCI quirk.
- hpet_freq: Written only in hpet_enable()
(arch/x86/kernel/hpet.c:1022), which is __init.
- boot_hpet_disable: Written only in early-quirks.c:624 and __init
setup functions in hpet.c (lines 111, 124, 984).
Why it matters:
Marking these as __ro_after_init hardens the kernel by placing them in the
read-only data section post-init. This prevents accidental or malicious
runtime modifications (e.g., via a memory corruption exploit) that could
silently corrupt HPET frequencies or block IDs, causing severe timing
issues or system hangs.
It also explicitly documents the intent for future developers that
these are strictly boot-time variables.
Let me know if there is anything else needed.
Regards,
Türker
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init
2026-11-19 20:37 ` Habil Eren Türker
@ 2026-11-19 22:44 ` Dave Hansen
2026-11-19 23:02 ` Habil Eren Türker
0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2026-11-19 22:44 UTC (permalink / raw)
To: Habil Eren Türker
Cc: bp, daniel, dave.hansen, hpa, jwiesner, linux-kernel, mingo, tglx, x86
On 11/19/26 12:37, Habil Eren Türker wrote:
> Marking these as __ro_after_init hardens the kernel by placing them in the
> read-only data section post-init. This prevents accidental or malicious
> runtime modifications (e.g., via a memory corruption exploit) that could
> silently corrupt HPET frequencies or block IDs, causing severe timing
> issues or system hangs.
Heh, I'm familiar with the concept of __ro_after_init.
Maybe it's a sign of the times, but I'm doubting the veracity of the
claim that this was found through a random human audit of the HPET code.
I mean, if you're using an LLM to find these, generate the patches, and
respond to my emails, that *fine*. Just please be transparent about it
when I ask.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init
2026-11-19 22:44 ` Dave Hansen
@ 2026-11-19 23:02 ` Habil Eren Türker
0 siblings, 0 replies; 5+ messages in thread
From: Habil Eren Türker @ 2026-11-19 23:02 UTC (permalink / raw)
To: dave.hansen
Cc: bp, daniel, dave.hansen, Habil Eren Türker, hpa, jwiesner,
linux-kernel, mingo, tglx, x86
Hi Dave,
I've been working with HPET code for a long time, so I came across this
and just noticed it. And I verified the context and manually ran
`git grep`. I didn't use any LLM to find this.
However, English isn't my native language. Also, as a 17-year-old still
learning the kernel development process, I use various LLM tools to
translate my technical thoughts into professional English.
I understand the security and stability implications of __ro_after_init,
and the patch reflects a real technical improvement, even if my wording
was polished by an LLM assistant.
I will be completely transparent about my workflow going forward.
Thank you for taking the time to review this and for the guidance.
Is there anything specific in the patch logic itself that
needs adjustment?
Regards,
Türker
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 23:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 12:29 [PATCH] x86/hpet: Mark boot-time variables as __ro_after_init Habil Eren Türker
2026-11-19 19:40 ` Dave Hansen
2026-11-19 20:37 ` Habil Eren Türker
2026-11-19 22:44 ` Dave Hansen
2026-11-19 23:02 ` Habil Eren Türker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®