All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mukesh R" <mrathor@linux.microsoft.com>
Cc: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH V4 9/9] mshv: Disable movable regions upfront if device passthru
Date: Sat, 18 Jul 2026 02:40:33 +0000	[thread overview]
Message-ID: <20260718024033.6EE6B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260718021949.926306-10-mrathor@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Malicious userspace can bypass memory pinning enforcement by forcing copy_to_user() to fail.
- [Low] Module parameter `hv_memreg` is exposed as runtime-writable despite being designed as a boot parameter.
--

--- Patch [9]: [PATCH V4 9/9] mshv: Disable movable regions upfront if device passthru ---
commit c768ee85b3efb1c981444ab02e4e4d365693795e
Author: Mukesh R <mrathor@linux.microsoft.com>

mshv: Disable movable regions upfront if device passthru

If a VM is started with a device attached, the memory regions must be marked
non-movable since the device attach hypercall allows the use of SLAT for IOMMU.
This patch marks them non-movable upfront upon device passthru and adds a boot
parameter to allow a user to pin them manually if anticipated.

> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 58cf61cb227ba..b085fa13574f0 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -46,6 +46,10 @@ MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
>  #define HV_VP_COUNTER_ROOT_DISPATCH_THREAD_BLOCKED 95
>  #endif
>  
> +static uint hv_memreg;  /* mshv_mem_region allocations type */
> +module_param(hv_memreg, uint, 0644);

[Severity: Low]
The commit message states this is a "boot parameter". Is it intentional
that this module parameter is created with 0644 permissions? This allows
root to change the allocation policy at runtime, whereas 0444 would
correctly enforce its boot-only nature.

> +MODULE_PARM_DESC(hv_memreg, "0: movable (default), 1: pinned");
> +
>  struct mshv_root mshv_root;

[ ... ]

> @@ -1801,6 +1811,9 @@ static long mshv_partition_ioctl_create_device(struct mshv_partition *partition,
>  	if (copy_to_user(uarg, &devargk, sizeof(devargk)))
>  		return -EFAULT;    /* cleanup in mshv_device_fop_release() */

[Severity: High]
If userspace passes a read-only memory buffer to the MSHV_CREATE_DEVICE ioctl,
copy_from_user() can succeed but copy_to_user() will fault and return -EFAULT.

Because the file descriptor has already been installed via anon_inode_getfd()
prior to the copy_to_user() call, the user can recover the functional device
FD via /proc/self/fd/ even after the ioctl returns an error.

Does this early return allow malicious userspace to bypass the memory pinning
enforcement by forcing copy_to_user() to fail, intentionally skipping the
partition->pt_regions_pinned = true assignment?

>  
> +	/* For now, just mark regions pinned if there is device passthru. */
> +	partition->pt_regions_pinned = true;
> +
>  	return 0;
>  
>  undo_out:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260718021949.926306-1-mrathor@linux.microsoft.com?part=9

      reply	other threads:[~2026-07-18  2:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18  2:19 [PATCH V4 0/9] PCI passthru on Hyper-V Mukesh R
2026-07-18  2:19 ` [PATCH V4 1/9] mshv: Provide a way to get partition ID if running in a VMM process Mukesh R
2026-07-18  2:32   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 2/9] mshv: Add declarations and definitions for VFIO-MSHV bridge device Mukesh R
2026-07-18  2:31   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 3/9] mshv: Introduce basic mshv bridge device for VFIO to build upon Mukesh R
2026-07-18  2:36   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 4/9] mshv: Add ioctl support for MSHV-VFIO bridge device Mukesh R
2026-07-18  2:34   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 5/9] mshv: Import data structs around device passthru from hyperv headers Mukesh R
2026-07-18  2:30   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 6/9] PCI: hv: Export hv_build_devid_type_pci() and change return type Mukesh R
2026-07-18  2:32   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 7/9] x86/hyperv: Implement Hyper-V virtual IOMMU Mukesh R
2026-07-18  2:34   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 8/9] mshv: Populate mmio mappings for PCI passthru Mukesh R
2026-07-18  2:33   ` sashiko-bot
2026-07-18  2:19 ` [PATCH V4 9/9] mshv: Disable movable regions upfront if device passthru Mukesh R
2026-07-18  2:40   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260718024033.6EE6B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mrathor@linux.microsoft.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.