From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC48436C9E5 for ; Fri, 24 Apr 2026 14:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777039485; cv=none; b=HD+ybHVutUjl9wWWyPUQr2FJMFiVYLut2ZZyDmExfmLjLVoYiWz9/wRtMCxmKZCntdFYRzZX6MW724kAXBRD5V8cRaUJux0Bj4GOmLnwDcvRaUq05a1OYp3GMDnO5G75rgKt44v2f7H8oeRkvUL6gYCoXR1zlz0eZNt6fEZeA2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777039485; c=relaxed/simple; bh=SO7bu4Vm6Jfq2usB8FujQrfzdLbxnKL5FBIA6ufdnJM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MgLHGE/hLJY/rwNHXep72TiBSRmUTj8SCNDRXOtvIx4A9AG7y14K6qsEAY9tCfeuPZYZc9hKlUO+1hsSVKYod6lzAlXdG5IJYHBPy1Sd1XNB7sNPW9+++5Ac9z9VvjONPnpXwYQBKjmT1yyvjif3Xe4OEAL6F06RyTgOw+h4EJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MZZTlo9u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MZZTlo9u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39BBDC19425; Fri, 24 Apr 2026 14:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777039484; bh=SO7bu4Vm6Jfq2usB8FujQrfzdLbxnKL5FBIA6ufdnJM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MZZTlo9un/36T3NeFLTE3v1e9mrOtneILLaBx+/DA5CWK5k8yQ4YQDraUoqChAmCM QHz/6VzayChM7XN1aNwuRdV9Fgp0oCQMNOAvYk/QMqzT02ik4FGSY5R0WNOktJu/9l al4i4K7Tg85QeB7K1ZCQpQh0XOHa13xWUcyS7Yo4= Date: Fri, 24 Apr 2026 16:04:42 +0200 From: Greg Kroah-Hartman To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand , Jason Gunthorpe , John Hubbard , Peter Xu Subject: Re: [PATCH v2] mm/gup: honour FOLL_PIN in NOMMU __get_user_pages_locked() Message-ID: <2026042418-facing-viewer-c7d9@gregkh> References: <2026042303-vendor-outright-b9d2@gregkh> <20260424063817.552a894d4b5bfa4de40792fa@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260424063817.552a894d4b5bfa4de40792fa@linux-foundation.org> On Fri, Apr 24, 2026 at 06:38:17AM -0700, Andrew Morton wrote: > On Thu, 23 Apr 2026 16:28:04 +0200 Greg Kroah-Hartman wrote: > > > The !CONFIG_MMU implementation of __get_user_pages_locked() takes a bare > > get_page() reference for each page regardless of foll_flags: > > if (pages[i]) > > get_page(pages[i]); > > > > This is reached from pin_user_pages*() with FOLL_PIN set. > > unpin_user_page() is shared between MMU and NOMMU configurations and > > unconditionally calls gup_put_folio(..., FOLL_PIN), which subtracts > > GUP_PIN_COUNTING_BIAS (1024) from the folio refcount. > > > > This means that pin adds 1, and then unpin will subtract 1024. > > > > If a user maps a page (refcount 1), registers it 1023 times as an > > io_uring fixed buffer (1023 pin_user_pages calls -> refcount 1024), then > > unregisters: the first unpin_user_page subtracts 1024, refcount hits 0, > > the page is freed and returned to the buddy allocator. The remaining > > 1022 unpins write into whatever was reallocated, and the user's VMA > > still maps the freed page (NOMMU has no MMU to invalidate it). > > Reallocating the page for an io_uring pbuf_ring then lets userspace > > corrupt the new owner's data through the stale mapping. > > > > Use try_grab_folio() which adds GUP_PIN_COUNTING_BIAS for FOLL_PIN and 1 > > for FOLL_GET, mirroring the CONFIG_MMU path so pin and unpin are > > symmetric. > > Battle of the bots? > https://sashiko.dev/#/patchset/2026042303-vendor-outright-b9d2@gregkh Odd, I really don't know the answer to that. I can provide my reproducer if anyone wants to tell me this patch is wrong. thanks, greg k-h