Skip to content

Commit

Permalink
KVM: Harden copying of userspace-array against overflow
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Philipp Stanner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[sean: call out that KVM pre-checks the number of entries]
Signed-off-by: Sean Christopherson <[email protected]>
  • Loading branch information
Philipp Stanner authored and sean-jc committed Dec 1, 2023
1 parent 8c49767 commit 1f82935
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5262,9 +5262,8 @@ static long kvm_vm_ioctl(struct file *filp,
goto out;
if (routing.nr) {
urouting = argp;
entries = vmemdup_user(urouting->entries,
array_size(sizeof(*entries),
routing.nr));
entries = vmemdup_array_user(urouting->entries,
routing.nr, sizeof(*entries));
if (IS_ERR(entries)) {
r = PTR_ERR(entries);
goto out;
Expand Down

0 comments on commit 1f82935

Please sign in to comment.