Skip to contentSkip to conversation

KVM: Use memdup_user instead of kernel stack to allocate kvm_guest_debug

PATCH In review Leesoo Ahn 2 participants 3 messages Feb 10 – Feb 20 KVM

lore
Share & tools
lore

Leesoo Ahn

author
#0 lore raw

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
index 5b5b69c97665..bc0a53129df7 100644
@@ -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
author
#1 lore raw

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_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 -5
index 5b5b69c97665..bc0a53129df7 100644
@@ -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

#2 lore raw
In reply to Leesoo Ahn
Quoted 3 lines · Leesoo Ahn

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.

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?