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 94F2533E347 for ; Fri, 24 Apr 2026 13:38:18 +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=1777037898; cv=none; b=UWstF4hnRYPjNnlxriGT564Fk/ujWU+pRxLn0HO871eIvkCZ0bdFGGBGULY4ebzR+RM4AhtVrxOa2PrJVW36d5dbQPMijkrZjC8YMG92cAreAzC+UYnuYsrcE6qoM3q0x9zGKR67PLlfc79MoibQH4dkA6I36vDpf9tOH2Y5tX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777037898; c=relaxed/simple; bh=tBThDtj2tnEnBMiK83VY10biHSvNlAnlQoF2hPZIIoA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=JernSIPhdTctsf9EuJ/Au0518IVavw+U/PI/MCAfBAutBhg6zxz6Urt2bfLuzNF1kW/9eLBgb9HCMSzy1KIXzY6Ld0Yb3T7gq/TZJRHGL2ZQ34OX7P3rTUnJGQehQD4eHNxU3yrt0+Ye/U15xbtNFOxeneEw8i31ViIdHWOLPjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=Np6A/4u3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Np6A/4u3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F15F8C19425; Fri, 24 Apr 2026 13:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1777037898; bh=tBThDtj2tnEnBMiK83VY10biHSvNlAnlQoF2hPZIIoA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Np6A/4u3QyyNKYAy0Qt2eyfQhCDF5DkSTlTP3L2Dnc1ZLMSjUYd3NoVgdl10cFBpD +kat6UkIGOap2baYde3xR4vJkq2DdWwJvdeV1S/BSB7xxeXxtaYXE87knitidGpRq0 0ghkCTiy+YjUl5nqFLQ4ifFIa/7H5tBHYMuCxkRc= Date: Fri, 24 Apr 2026 06:38:17 -0700 From: Andrew Morton To: Greg Kroah-Hartman 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: <20260424063817.552a894d4b5bfa4de40792fa@linux-foundation.org> In-Reply-To: <2026042303-vendor-outright-b9d2@gregkh> References: <2026042303-vendor-outright-b9d2@gregkh> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit 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