From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336049; b=sqTnvXUB8EvWi189w3I7/ew9ODCvO7a8l4F76htvwYHzSt4re5Z/EjTGj2Gzy1V6he9s U5jzWGoCKeWwo4uFrQhKPKRE2W6Zd6M8gg5daWSt8cKeeYqb1/xTBQq+OyOnSDlwnAGLJ xud3jVN8TkmZbvNoMIHDU8Zos2YFpbHQvkRzU/1dQznoVQSOMAuULbCoD42V6q+KV27u+ 3Q9IZE54ArZNHnllpp3XkjNieGcMfYn9uaGy8TGR3BVz131vr5BZIix7ikHuYv1A8Raz/ 7vM/IFxycNxai1wBfk893tJ1ZSHZCUhgFyu8FyszH0EiVtFhS0KrAc20w1uvdQwim0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336049; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=KduzPFN5Bu2iku3g8FGYZn/XzxPx3HTAg875agalCfA=; b=sa84c7UW0z17ki2sUasMkCeBpPXfniM1v1TYhg7rIp3X5bMKezfN5As+aWcgJi4cdxsG dflBgO3tkiDd3EIUReXCDSZRIs3a2okjF4GmVe4hxtFrN2dKkj4ovl2qCG7Wc8pZx1+0C EZrR4dFmITh5HFu9mumWmdbLMMLWIN9/so+zUtAUvpG1CF05jzIUa8hHWAG68BGj1Rwrr MHVv5943sfqgrA4io4yxw8ok1Vx7wrhEpCAsTkzNZCF/jFJWmk9PCmMv7NUPmmn9JVvhT 19d8cf1Us9hS4VfU/aRe/FuSDIFzY55YZUAYVomN2VXqZx981FiOt4i18kU7vhFTYlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=deNnQden; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1CDE606A322 for ; Thu, 3 Dec 2026 22:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=deNnQden Received: by smtp.kernel.org (Postfix) with ESMTPSA id 362A51F00931; Thu, 3 Dec 2026 22:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796336049; bh=KduzPFN5Bu2iku3g8FGYZn/XzxPx3HTAg875agalCfA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=deNnQdenRoj6jvq2jQkqbHo0TCS88ZnVS3zlY2HpQXeENKbI9XeQzacv72IRz66uM lTiWflr/SbgBUvYEhDcLgn2ard48OadTP56eK5U37/uIbZI+nYp0AL77a+leZVb/cA 2sSKMC3XQYN5KwVJsLOjrVgm3OtxAOxITSBCSC6VXBZ1EwSgAe7xCBPEgaZBUOQIXA p6xTnRhAd6uC54WEqOWk6ilRcPU0BRbHP4Nyoy1kn4C5EGD2aG+fSzbl7bW5yOyFSK ltBO3houAuqfMPWOKKMybNC5PN/UaWVbMqyNYU5ji3U8pVkeywCv8dnjOrTqCt8O9h 8mPkgxsKay0eg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed Reply-To: sashiko-reviews@lists.linux.dev To: "Jason J. Herne" , linux-s390@vger.kernel.org Cc: "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261203214531.1395796-4-jjherne@linux.ibm.com> References: <20261203214531.1395796-1-jjherne@linux.ibm.com> <20261203214531.1395796-4-jjherne@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 22:14:08 +0000 X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 prev= ent 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 =3D 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(str= uct vfio_ap_queue *q) > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203214531.1395= 796-1-jjherne@linux.ibm.com?part=3D3