From: Chao Gao <chao.gao@intel.com>
To: Mathias Krause <minipli@grsecurity.net>
Cc: <kvm@vger.kernel.org>, <pbonzini@redhat.com>, <seanjc@google.com>
Subject: Re: [PATCH 1/2] x86/eventinj: Use global asm label for nested NMI IP address verification
Date: Wed, 15 Oct 2025 09:47:14 +0800 [thread overview]
Message-ID: <aO79InNMh/5tp3ih@intel.com> (raw)
In-Reply-To: <a8c4d415-a23b-46f6-89fc-28facaba0a44@grsecurity.net>
On Tue, Sep 16, 2025 at 12:10:46PM +0200, Mathias Krause wrote:
>Am 15.09.25 um 16:49 schrieb Chao Gao:
>> Use a global asm label to get the expected IP address for nested NMI
>> interception instead of reading a hardcoded offset from the stack.
>>
>> the NMI test in eventinj.c verifies that a nested NMI occurs immediately at
>> the return address (IP register) in the IRET frame, as IRET opens the
>> NMI window. Currently, nested_nmi_iret_isr() reads the return address
>> using a magic offset (iret_stack[-3]), which is unclear and may break if
>> more values are pushed to the "iret_stack".
>>
>> To improve readability, add a global 'ip_after_iret' label for the expected
>> return address, push it to the IRET frame, and verify it matches the
>> interrupted address in the nested NMI handler.
>>
>> Signed-off-by: Chao Gao <chao.gao@intel.com>
>> ---
>> x86/eventinj.c | 11 +++++++----
>> 1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/x86/eventinj.c b/x86/eventinj.c
>> index 6fbb2d0f..ec8a5ef1 100644
>> --- a/x86/eventinj.c
>> +++ b/x86/eventinj.c
>> @@ -127,12 +127,13 @@ static void nmi_isr(struct ex_regs *r)
>> }
>>
>> unsigned long *iret_stack;
>> +extern char ip_after_iret[];
>>
>> static void nested_nmi_iret_isr(struct ex_regs *r)
>> {
>> printf("Nested NMI isr running rip=%lx\n", r->rip);
>>
>> - if (r->rip == iret_stack[-3])
>> + if (r->rip == (unsigned long)ip_after_iret)
>
>This change basically eliminates the need for the global
>'ip_after_iret', it can be local to nmi_iret_isr() now.
You meant 'iret_stack', right? if so, sure, I will make it local to
nmi_iret_isr().
next prev parent reply other threads:[~2025-10-15 1:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 14:49 [kvm-unit-tests PATCH 0/2] Fix triple fault in eventinj test Chao Gao
2025-09-15 14:49 ` [PATCH 1/2] x86/eventinj: Use global asm label for nested NMI IP address verification Chao Gao
2025-09-16 10:10 ` Mathias Krause
2025-10-15 1:47 ` Chao Gao [this message]
2025-10-15 4:29 ` Mathias Krause
2025-09-15 14:49 ` [PATCH 2/2] x86/eventinj: Push SP to IRET frame Chao Gao
2025-09-16 10:21 ` Mathias Krause
2025-10-15 1:49 ` Chao Gao
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=aO79InNMh/5tp3ih@intel.com \
--to=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=minipli@grsecurity.net \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox