mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] KVM: x86: cr8 reserved bit check
@ 2026-09-08 16:04 Tharit Tangkijwanichakul
  2026-09-08 16:04 ` [PATCH v1 1/2] KVM: x86: Reject reserved CR8 bits in KVM_SET_SREGS Tharit Tangkijwanichakul
  2026-09-08 16:04 ` [PATCH v1 2/2] KVM: selftests: Add CR8 reserved-bit checks to set_sregs_test Tharit Tangkijwanichakul
  0 siblings, 2 replies; 4+ messages in thread
From: Tharit Tangkijwanichakul @ 2026-09-08 16:04 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, shuah
  Cc: hpa, binbin.wu, kai.huang, kvm, linux-kernel, linux-kselftest,
	linux-kernel-mentees, skhan, me, jkoolstra,
	Tharit Tangkijwanichakul

kvm_is_valid_sregs() validates the incoming CR0, CR4, and efer values on
KVM_SET_SREGS but never checks CR8. When userspace passes a CR8 value with
any reserved bit [63:4] set, __set_sregs_common() forwards it to
kvm_set_cr8(), which rejects the reserved bits and returns early. That
return value is not checked, so the ioctl reports success while the
requested value is silently dropped, and a subsequent KVM_GET_SREGS then
returns a CR8 different from the one userspace believed it had written.

This was found by code inspection of kvm_is_valid_sregs() and confirmed
with the selftest added in patch 2.

Patch 1 factors the reserved-bit check into kvm_is_valid_cr8() and uses it
in both kvm_set_cr8() and kvm_is_valid_sregs() so that KVM_SET_SREGS
rejects reserved CR8 bits up front.

Patch 2 extends set_sregs_test to cover CR8: it verifies that bits [3:0]
can be set and read back, and that every reserved bit [63:4] is rejected
by KVM_SET_SREGS.

Testing
=======
Tested on an Intel host:
                              Unpatched kernel    Patched kernel
set_sregs_test CR8 case       FAIL                PASS
KVM x86 selftests             baseline            no regressions
kvm-unit-tests                baseline            no regressions

Tharit Tangkijwanichakul (2):
  KVM: x86: Reject reserved CR8 bits in KVM_SET_SREGS
  KVM: selftests: Add CR8 reserved-bit checks to set_sregs_test

 arch/x86/kvm/regs.c                              |  8 +++++++-
 tools/testing/selftests/kvm/x86/set_sregs_test.c | 12 ++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-10  0:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 16:04 [PATCH v1 0/2] KVM: x86: cr8 reserved bit check Tharit Tangkijwanichakul
2026-09-08 16:04 ` [PATCH v1 1/2] KVM: x86: Reject reserved CR8 bits in KVM_SET_SREGS Tharit Tangkijwanichakul
2026-09-10  0:27   ` Sean Christopherson
2026-09-08 16:04 ` [PATCH v1 2/2] KVM: selftests: Add CR8 reserved-bit checks to set_sregs_test Tharit Tangkijwanichakul

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®