Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jason J. Herne" <jjherne@linux.ibm.com>, linux-s390@vger.kernel.org
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed
Date: Thu, 03 Dec 2026 22:14:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-248733@kernel.org> (raw)
In-Reply-To: <20261203214531.1395796-4-jjherne@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] s390/vfio-ap: guest-triggerable permanent folio leak in
  vfio_ap_irq_disable()
- [Medium] s390/vfio-ap: get_page() in vfio_ap_leak_aqic_resources()
  drops FOLL_PIN
--

commit 3b9e364f526db43b7ae435971ce6e07ced29e979
Author: Jason J. Herne <jjherne@linux.ibm.com>

s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed

This commit saves the pinned NIB struct page in vfio_ap_queue and adds
vfio_ap_leak_aqic_resources() to take an extra page reference before
unpinning from VFIO when a queue reset or IRQ disable cannot be confirmed.

> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index fba6f256ce77a..d460337e365f2 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c

[ ... ]

> +static void vfio_ap_leak_aqic_resources(struct vfio_ap_queue *q)
> +{
> +	if (q->saved_page) {
> +		pr_warn_ratelimited("vfio_ap: APQN %02x.%04x: leaking NIB page to prevent reuse while the queue may still write to it\n",
> +				    AP_QID_CARD(q->apqn), AP_QID_QUEUE(q->apqn));
> +		get_page(q->saved_page);
> +		q->saved_page = NULL;
> +	}
> +	vfio_ap_free_aqic_resources(q);
> +}

[Severity: Medium]
Does get_page() lose FOLL_PIN DMA protection once vfio_unpin_pages() runs?

get_page() only takes a plain refcount, so once vfio_unpin_pages() drops
VFIO's pin, folio_maybe_dma_pinned() becomes false while hardware may still
write to the NIB.  Paths gated on it, such as shrink_folio_list() on
file-backed guest memory, then lose DMA protection.

Also, if VFIO type1 maps a VM_PFNMAP reserved page without GUP pinning,
get_page() on a zero-refcount page can hit VM_WARN_ON_FOLIO().  Using
folio_add_pins(page_folio(q->saved_page), 1) when folio_maybe_dma_pinned()
is true would preserve FOLL_PIN semantics and skip non-GUP reserved pages.

[ ... ]

> @@ -338,6 +363,8 @@ static struct ap_queue_status vfio_ap_irq_disable(struct vfio_ap_queue *q)
>  
>  	WARN_ONCE(1, "%s: ap_aqic status %d\n", __func__,
>  		  status.response_code);
> +	vfio_ap_leak_aqic_resources(q);
> +	return status;
>  end_free:
>  	vfio_ap_free_aqic_resources(q);
>  	return status;

[Severity: High]
Can an untrusted guest use this path to permanently leak host folios?

handle_pqap() calls vfio_ap_irq_disable() on guest PQAP(AQIC) with IR
clear, while PQAP(RAPQ) and PQAP(ZAPQ) run in SIE without interception.
A guest can enable IRQs on a page and keep the queue busy or resetting from
another vCPU across the 100ms retry loop to hit vfio_ap_leak_aqic_resources().

That drops the VFIO pin (releasing RLIMIT_MEMLOCK) while taking a permanent
folio reference and leaving the queue assigned.  The guest can repeat this
on new folios to exhaust host RAM, and the leak survives VM teardown.

Unlike unmap_iova(), handle_pqap() does not need to unpin the NIB when
ap_aqic() is busy or resetting; keeping the VFIO pin and returning the
status lets the guest retry without leaking memory.

Even on the unmap_iova() path, polling for only 100ms (compared to
VFIOAP_RESET_TIMEOUT of 2000ms) risks leaking a folio if a normal queue
reset coincides with a DMA unmap.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203214531.1395796-1-jjherne@linux.ibm.com?part=3

  reply	other threads:[~2026-12-03 22:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
2026-12-03 21:45 ` [PATCH 1/5] s390/vfio-ap: Prevent passing unreset queues Jason J. Herne
2026-12-03 22:08   ` sashiko-bot
2026-12-03 21:45 ` [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification Jason J. Herne
2026-12-03 22:08   ` sashiko-bot
2026-12-03 21:45 ` [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed Jason J. Herne
2026-12-03 22:14   ` sashiko-bot [this message]
2026-12-03 21:45 ` [PATCH 4/5] s390/vfio-ap: clear matrix_mdev link for queues not reset on unassign Jason J. Herne
2026-12-03 22:02   ` sashiko-bot
2026-12-03 21:45 ` [PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests Jason J. Herne
2026-12-03 22:14 ` [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling 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=sashiko-outbox-248733@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --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