| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * VMware VMCI Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 VMware, Inc. All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 8 | | - * Free Software Foundation version 2 and no later version. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 11 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|---|
| 12 | | - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 13 | | - * for more details. |
|---|
| 14 | 6 | */ |
|---|
| 15 | 7 | |
|---|
| 16 | 8 | #include <linux/vmw_vmci_defs.h> |
|---|
| 17 | 9 | #include <linux/vmw_vmci_api.h> |
|---|
| 18 | | -#include <linux/moduleparam.h> |
|---|
| 19 | 10 | #include <linux/miscdevice.h> |
|---|
| 20 | 11 | #include <linux/interrupt.h> |
|---|
| 21 | 12 | #include <linux/highmem.h> |
|---|
| .. | .. |
|---|
| 115 | 106 | return vmci_host_device_initialized && |
|---|
| 116 | 107 | (!vmci_guest_code_active() || |
|---|
| 117 | 108 | atomic_read(&vmci_host_active_users) > 0); |
|---|
| 109 | +} |
|---|
| 110 | + |
|---|
| 111 | +int vmci_host_users(void) |
|---|
| 112 | +{ |
|---|
| 113 | + return atomic_read(&vmci_host_active_users); |
|---|
| 118 | 114 | } |
|---|
| 119 | 115 | |
|---|
| 120 | 116 | /* |
|---|
| .. | .. |
|---|
| 237 | 233 | * about the size. |
|---|
| 238 | 234 | */ |
|---|
| 239 | 235 | BUILD_BUG_ON(sizeof(bool) != sizeof(u8)); |
|---|
| 240 | | - if (!access_ok(VERIFY_WRITE, (void __user *)uva, sizeof(u8))) |
|---|
| 241 | | - return VMCI_ERROR_GENERIC; |
|---|
| 242 | 236 | |
|---|
| 243 | 237 | /* |
|---|
| 244 | 238 | * Lock physical page backing a given user VA. |
|---|
| 245 | 239 | */ |
|---|
| 246 | | - retval = get_user_pages_fast(uva, 1, 1, &context->notify_page); |
|---|
| 240 | + retval = get_user_pages_fast(uva, 1, FOLL_WRITE, &context->notify_page); |
|---|
| 247 | 241 | if (retval != 1) { |
|---|
| 248 | 242 | context->notify_page = NULL; |
|---|
| 249 | 243 | return VMCI_ERROR_GENERIC; |
|---|
| .. | .. |
|---|
| 347 | 341 | vmci_host_dev->ct_type = VMCIOBJ_CONTEXT; |
|---|
| 348 | 342 | atomic_inc(&vmci_host_active_users); |
|---|
| 349 | 343 | |
|---|
| 344 | + vmci_call_vsock_callback(true); |
|---|
| 345 | + |
|---|
| 350 | 346 | retval = 0; |
|---|
| 351 | 347 | |
|---|
| 352 | 348 | out: |
|---|
| .. | .. |
|---|
| 448 | 444 | struct vmci_handle handle; |
|---|
| 449 | 445 | int vmci_status; |
|---|
| 450 | 446 | int __user *retptr; |
|---|
| 451 | | - u32 cid; |
|---|
| 452 | 447 | |
|---|
| 453 | 448 | if (vmci_host_dev->ct_type != VMCIOBJ_CONTEXT) { |
|---|
| 454 | 449 | vmci_ioctl_err("only valid for contexts\n"); |
|---|
| 455 | 450 | return -EINVAL; |
|---|
| 456 | 451 | } |
|---|
| 457 | | - |
|---|
| 458 | | - cid = vmci_ctx_get_id(vmci_host_dev->context); |
|---|
| 459 | 452 | |
|---|
| 460 | 453 | if (vmci_host_dev->user_version < VMCI_VERSION_NOVMVM) { |
|---|
| 461 | 454 | struct vmci_qp_alloc_info_vmvm alloc_info; |
|---|
| .. | .. |
|---|
| 754 | 747 | if (copy_from_user(&set_info, uptr, sizeof(set_info))) |
|---|
| 755 | 748 | return -EFAULT; |
|---|
| 756 | 749 | |
|---|
| 757 | | - cpt_buf = kmalloc(set_info.buf_size, GFP_KERNEL); |
|---|
| 758 | | - if (!cpt_buf) { |
|---|
| 759 | | - vmci_ioctl_err( |
|---|
| 760 | | - "cannot allocate memory to set cpt state (type=%d)\n", |
|---|
| 761 | | - set_info.cpt_type); |
|---|
| 762 | | - return -ENOMEM; |
|---|
| 763 | | - } |
|---|
| 764 | | - |
|---|
| 765 | | - if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf, |
|---|
| 766 | | - set_info.buf_size)) { |
|---|
| 767 | | - retval = -EFAULT; |
|---|
| 768 | | - goto out; |
|---|
| 769 | | - } |
|---|
| 750 | + cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf, |
|---|
| 751 | + set_info.buf_size); |
|---|
| 752 | + if (IS_ERR(cpt_buf)) |
|---|
| 753 | + return PTR_ERR(cpt_buf); |
|---|
| 770 | 754 | |
|---|
| 771 | 755 | cid = vmci_ctx_get_id(vmci_host_dev->context); |
|---|
| 772 | 756 | set_info.result = vmci_ctx_set_chkpt_state(cid, set_info.cpt_type, |
|---|
| .. | .. |
|---|
| 774 | 758 | |
|---|
| 775 | 759 | retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0; |
|---|
| 776 | 760 | |
|---|
| 777 | | -out: |
|---|
| 778 | 761 | kfree(cpt_buf); |
|---|
| 779 | 762 | return retval; |
|---|
| 780 | 763 | } |
|---|
| .. | .. |
|---|
| 983 | 966 | .release = vmci_host_close, |
|---|
| 984 | 967 | .poll = vmci_host_poll, |
|---|
| 985 | 968 | .unlocked_ioctl = vmci_host_unlocked_ioctl, |
|---|
| 986 | | - .compat_ioctl = vmci_host_unlocked_ioctl, |
|---|
| 969 | + .compat_ioctl = compat_ptr_ioctl, |
|---|
| 987 | 970 | }; |
|---|
| 988 | 971 | |
|---|
| 989 | 972 | static struct miscdevice vmci_host_miscdev = { |
|---|