KVM: Use memdup_user instead of kernel stack to allocate kvm_guest_debug
PATCH 1/1 KVM: Use memdup_user instead of kernel stack to allocate kvm_guest_debug
Switch to using memdup_user to allocate its memory because the size of kvm_guest_debug is over 512 bytes on Arm64 and is burdened allocation from kernel stack.
--- virt/kvm/kvm_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
virt/kvm/kvm_main.c +7 -4
@@ -4592,12 +4592,15 @@ static long kvm_vcpu_ioctl(struct file *filp,break ; }case KVM_SET_GUEST_DEBUG : { -struct kvm_guest_debug dbg; +struct kvm_guest_debug *dbg; - r = -EFAULT ; -if (copy_from_user (&dbg, argp,sizeof (dbg))) + dbg =memdup_user (argp,sizeof (*dbg)); +if (IS_ERR (dbg)) { + r =PTR_ERR (dbg); goto out; - r =kvm_arch_vcpu_ioctl_set_guest_debug (vcpu, &dbg); + } + r =kvm_arch_vcpu_ioctl_set_guest_debug (vcpu, dbg); +kfree (dbg);break ; }case KVM_SET_SIGNAL_MASK : {
Signature · 1 line
2.51.0
Bump up the patch in order to remind again.
2026년 2월 10일 (화) PM 4:25, Leesoo Ahn <[email protected]>님이 작성:
Quoted 37 lines
Switch to using
memdup_userto allocate its memory because the size ofkvm_guest_debugis over 512 bytes on Arm64 and is burdened allocation from kernel stack.Signed-off-by Leesoo Ahn <[email protected]>--- virt/kvm/kvm_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)virt/kvm/kvm_main.c +7
-5@@ -4592,12 +4592,15 @@ static long kvm_vcpu_ioctl(struct file *filp,break ; }case KVM_SET_GUEST_DEBUG : { -struct kvm_guest_debug dbg; +struct kvm_guest_debug *dbg; - r = -EFAULT ; -if (copy_from_user (&dbg, argp,sizeof (dbg))) + dbg =memdup_user (argp,sizeof (*dbg)); +if (IS_ERR (dbg)) { + r =PTR_ERR (dbg); goto out; - r =kvm_arch_vcpu_ioctl_set_guest_debug (vcpu, &dbg); + } + r =kvm_arch_vcpu_ioctl_set_guest_debug (vcpu, dbg); +kfree (dbg);break ; }case KVM_SET_SIGNAL_MASK : { --2.51.0
Sean Christopherson
reviewerQuoted 3 lines · Leesoo Ahn
Switch to using
memdup_userto allocate its memory because the size ofkvm_guest_debugis over 512 bytes on Arm64 and is burdened allocation from kernel stack.
520 bytes is a lot, but it's not _that_ much, especially since kvm_arch_vcpu_ioctl_set_guest_debug() is leaf function (ignoring tracing).
Is there an actual problem on arm64? I.e. does this one particular allocation lead to stack overflows that otherwise don't happen in KVM?