summaryrefslogtreecommitdiff
path: root/tools/perf/python/stackcollapse.py
diff options
context:
space:
mode:
authorHaotian Jiang <jianghaotian.sunday@gmail.com>2026-08-06 10:06:01 -0700
committerSean Christopherson <seanjc@google.com>2026-09-22 06:40:38 -0700
commitaec196ba2affa5b396ed1bc16340067d66972f24 (patch)
tree65cf14be377e88bb53480451bb773dce0bd47fad /tools/perf/python/stackcollapse.py
parent1a66112cbc0214743c0d6d52427609379ac858f7 (diff)
downloadlinux-next-aec196ba2affa5b396ed1bc16340067d66972f24.tar.gz
linux-next-aec196ba2affa5b396ed1bc16340067d66972f24.zip
KVM: TDX: Reject INIT_MEM_REGION if number of bytes would overflow a u64
The nr_pages field in struct kvm_tdx_init_mem_region is a u64 that comes directly from userspace via copy_from_user(). The current validation uses a manual overflow check: region.gpa + (region.nr_pages << PAGE_SHIFT) <= region.gpa When nr_pages >= 2^52, the shift (nr_pages << PAGE_SHIFT) wraps around to a small value, bypassing the wrap check. While downstream protections (gfn_to_memslot() returning NULL for GFNs outside any memslot, and kvm_slot_has_gmem() checking for NULL) prevent any actual out-of-bounds access, the overflow itself is a real bug that should be caught at the validation layer. Replace the manual overflow check with check_shl_overflow() to correctly detect the wrap-around. Note, the manual wrap-around check on the gpa+size technically has a benign off-by-one bug, and can also use check_add_overflow(). Those flaws will be addressed shortly. Opportunistically separate the initial sanity checks from the more involved checks to try and make the code easier to read. Fixes: c846b451d3c5 ("KVM: TDX: Add an ioctl to create initial guest memory") Reported-by: Sashiko Bot <sashiko-bot@kernel.org> Closes: https://lore.kernel.org/all/20260630214952.98C851F000E9@smtp.kernel.org Cc: Yan Zhao <yan.y.zhao@intel.com> Cc: Binbin Wu <binbin.wu@linux.intel.com> Cc: Ackerley Tng <ackerleytng@google.com> Signed-off-by: Haotian Jiang <jianghaotian.sunday@gmail.com> [sean: use gpa_t, isolate check_shl_overflow() change, tweak changelog] Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Link: https://patch.msgid.link/20260806170602.4112602-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/perf/python/stackcollapse.py')
0 files changed, 0 insertions, 0 deletions