All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mukesh R" <mrathor@linux.microsoft.com>
Cc: linux-pci@vger.kernel.org, linux-hyperv@vger.kernel.org
Subject: Re: [PATCH V4 1/9] mshv: Provide a way to get partition ID if running in a VMM process
Date: Sat, 18 Jul 2026 02:32:22 +0000	[thread overview]
Message-ID: <20260718023223.302381F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260718021949.926306-2-mrathor@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Using global `current->tgid` to track and authorize partition ownership introduces a PID reuse vulnerability and breaks support for VMMs managing multiple partitions.
- [High] `mshv_current_partid()` returns a raw partition ID without acquiring a reference, leading to a TOCTOU race where the partition can be freed and its ID reused.

Pre-existing issues:
- [High] VPs are freed before their parent partition is unlinked from the RCU hash table, causing a Use-After-Free for concurrent RCU readers.
--

--- Patch [1]: [PATCH V4 1/9] mshv: Provide a way to get partition ID if running in a VMM process ---
commit ce04f426ae72519f5c20b1bad8ffd34a07810200
Author: Mukesh R <mrathor@linux.microsoft.com>

mshv: Provide a way to get partition ID if running in a VMM process

Many PCI passthru related hypercalls require partition ID of the target
guest. Guests are actually managed by MSHV driver and the partition ID
is only maintained there. Add a field in the partition struct in MSHV
driver to save the tgid of the VMM process creating the partition, and
add a function there to retrieve partition ID if the current process is
a VMM process.

> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 146726cc4e9ba..f1ff45a77b42c 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -1908,6 +1908,27 @@ mshv_partition_release(struct inode *inode, struct file *filp)
>  	return 0;
>  }

[Severity: High]
This is a pre-existing issue, but there appears to be a use-after-free
condition when a partition is being destroyed.

In destroy_partition(), child mshv_vp objects are freed while the parent
partition remains linked in the RCU-protected mshv_root.pt_htable:

destroy_partition() {
    ...
    kfree(vp);
    partition->pt_vp_array[i] = NULL;
    ...
    remove_partition(partition);
}

If a concurrent asynchronous interrupt (like handle_bitset_message) looks up
the partition via mshv_partition_find() and accesses the VP before
remove_partition() unlinks the partition and waits for a grace period,
could the ISR call kick_vp(vp) on freed memory?

> +/* Given a process tgid, return partition id if it is a VMM process */
> +u64 mshv_current_partid(void)
> +{
> +	struct mshv_partition *pt;
> +	int i;
> +	u64 ret_ptid = HV_PARTITION_ID_INVALID;
> +
> +	rcu_read_lock();
> +
> +	hash_for_each_rcu(mshv_root.pt_htable, i, pt, pt_hnode) {
> +		if (pt->pt_vmm_tgid == current->tgid) {
> +			ret_ptid = pt->pt_id;
> +			break;
> +		}
> +	}

[Severity: High]
Is it safe to track partition ownership using a global transient identifier
like current->tgid instead of an explicit file descriptor or reference-counted
token?

If a single VMM process creates multiple partitions, wouldn't
mshv_current_partid() arbitrarily return the first one found in the hash
table, breaking PCI passthru operations for all subsequent partitions?

Furthermore, could PID recycling lead to a situation where a new VMM process
accidentally matches an old partition whose fd was passed to a long-running
process that outlived the original creator?

> +
> +	rcu_read_unlock();
> +	return ret_ptid;

[Severity: High]
Does returning the raw pt_id here without acquiring a reference to the
partition object introduce a race condition?

Once the RCU read lock is dropped, a concurrent thread could close the
partition fd, causing destroy_partition() to delete it in the hypervisor.

If the hypervisor reuses this ID for a newly created partition belonging to a
different VMM, could the original caller's subsequent PCI passthru hypercall
mistakenly target the unrelated partition?

> +}
> +EXPORT_SYMBOL_GPL(mshv_current_partid);

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

  reply	other threads:[~2026-07-18  2:32 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 [this message]
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

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=20260718023223.302381F00A3A@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.