Skip to content

Commit bc2cad5

Browse files
Philipp Stannersean-jc
authored andcommitted
KVM: Harden copying of userspace-array against overflow
kvm_main.c utilizes vmemdup_user() and array_size() to copy a userspace array. Currently, this does not check for an overflow. Use the new wrapper vmemdup_array_user() to copy the array more safely. Note, KVM explicitly checks the number of entries before duplicating the array, i.e. adding the overflow check should be a glorified nop. Suggested-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Philipp Stanner <pstanner@redhat.com> Link: https://lore.kernel.org/r/20231102181526.43279-4-pstanner@redhat.com [sean: call out that KVM pre-checks the number of entries] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8b81a8d commit bc2cad5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

virt/kvm/kvm_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,9 +5262,8 @@ static long kvm_vm_ioctl(struct file *filp,
52625262
goto out;
52635263
if (routing.nr) {
52645264
urouting = argp;
5265-
entries = vmemdup_user(urouting->entries,
5266-
array_size(sizeof(*entries),
5267-
routing.nr));
5265+
entries = vmemdup_array_user(urouting->entries,
5266+
routing.nr, sizeof(*entries));
52685267
if (IS_ERR(entries)) {
52695268
r = PTR_ERR(entries);
52705269
goto out;

0 commit comments

Comments
 (0)