Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Longfang Liu" <liulongfang@huawei.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] hisi_acc_vfio_pci: fix VF BAR2 mmap on 64KB page size
Date: Mon, 03 Aug 2026 02:27:14 +0000	[thread overview]
Message-ID: <20260803022714.972861F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803021857.2370179-3-liulongfang@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Guest memory-mapping of BAR2 allows direct access to sensitive migration control registers, bypassing software isolation.
--

--- Patch [2]: [PATCH 2/2] hisi_acc_vfio_pci: fix VF BAR2 mmap on 64KB page size ---
commit 6249c89b3b40e6c3a5627d170614fe16d3e815bf
Author: Longfang Liu <liulongfang@huawei.com>

hisi_acc_vfio_pci: fix VF BAR2 mmap on 64KB page size

This commit aligns the BAR2 functional region mmap boundaries to PAGE_SIZE.
This is intended to prevent guest mmap operations from being rejected on 64KB
page size kernels when the functional region is smaller.

> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> index 36490be7a61aa..44b3e7d8fef5c 100644
> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> @@ -1355,14 +1355,21 @@ static int hisi_acc_vfio_pci_mmap(struct vfio_device *core_vdev,
>  	index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT);
>  	if (index == VFIO_PCI_BAR2_REGION_INDEX) {
>  		u64 req_len, pgoff, req_start;
> -		resource_size_t end;
> +		resource_size_t end, dev_len;
>  
> -		end = hisi_acc_get_resource_len(vdev, index);
> +		dev_len = hisi_acc_get_resource_len(vdev, index);
>  		req_len = vma->vm_end - vma->vm_start;
>  		pgoff = vma->vm_pgoff &
>  			((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
>  		req_start = pgoff << PAGE_SHIFT;
> -
> +		/*
> +		 * The BAR2 functional region (dev_len) may be smaller than the
> +		 * kernel page size. Align it to PAGE_SIZE so a page-rounded
> +		 * guest mmap is not rejected, which would make the VF unusable.
> +		 * The read/write path still truncates at the real functional
> +		 * boundary, keeping the migration registers inaccessible.
> +		 */
> +		end = PAGE_ALIGN(dev_len);
> +		if (req_start + req_len > end)
> +			return -EINVAL;

[Severity: Critical]
Does this change allow an untrusted guest or userspace process to bypass
software isolation and gain direct access to migration control registers?

By rounding dev_len up to PAGE_SIZE in hisi_acc_vfio_pci_mmap(), the boundary
check intended to prevent mapping of the hardware migration registers is
circumvented.

If a guest running on a 64KB page host requests an mmap of the BAR2
functional region, the code rounds dev_len up to PAGE_SIZE. This allows the
request to be validated and passed to vfio_pci_core_mmap(), mapping the
full 64KB physical page into the guest's stage-2 page tables.

If the functional region is 32KB and the migration registers reside in the
upper 32KB of the same physical page, the guest would gain unmediated
read/write access to the migration control registers via direct memory
load/store instructions. This appears to bypass the kernel's read/write
interception and the hisi_acc_pci_rw_access_check() boundary checks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803021857.2370179-1-liulongfang@huawei.com?part=2

      reply	other threads:[~2026-08-03  2:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  2:18 [PATCH 0/2] fix two issues related to the driver Longfang Liu
2026-08-03  2:18 ` [PATCH 1/2] hisi_acc_vfio_pci: fix live migration enable conditions for PF passthrough Longfang Liu
2026-08-03  2:42   ` sashiko-bot
2026-08-03  2:18 ` [PATCH 2/2] hisi_acc_vfio_pci: fix VF BAR2 mmap on 64KB page size Longfang Liu
2026-08-03  2:27   ` 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=20260803022714.972861F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=liulongfang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox