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=1794590407; b=T9gbFHmITi7OjyHQmJ/dVWEAG//NLVnUOLnfVWVBvFVvbuaSXELfTquqRc856v9BPkiT aacZgzNxiDf8+HcDpmavGO2hcApCAM84zI4D0YfcYBZaiI735T5jWjFy7oURaWvUQvhqM Th0El2t8v1inij4Sosxaib1gOj9F8QAnvZVeAPSjtLRfYQtvQh+79i5xkeIUzn+obM1oq wMPxH5mVb4+QhI86Q30j0mHd90R+85VIosKnRpXWJh/mwygUVZwJjbvx+Z7zgKtUUwBhW IG2Pb2jIP2yA1AFEw/gYoHFh6rUVgSWm5nZXQrvrocF2kfeV6GJ5b2gQfGcU5Fuw/HA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590407; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EcpNon18O9o1otibpwnCFv1BMFpd5uZjm4OtiS5v/P8=; b=yC4ZgrdIvsmufNp6yjQt0EFa3dbHcUYsz1SGjzVglqU5TsM5pP/nbOGTWzuXAIGjqoqX 0zzmMdLZ9NPXA6Vbb9Mb2N7ncjA1KCxvOyd/UUiJN+Gf+I/Hgp+CbGHGiQavHO9T7+nDi SAzuR/exXo5WZyqJIR5qT80mNJJ65KxabLaIs7DdXk+989KbITekZ7COiqDGRm8AR/0rI Kx9BuvGDHK9ghmhz/pEQ5/NirPlYsan4fNhsu4OSULgBwzqr1olSkHmNL20kK2BiXRfh4 Zxe2/DuoZuDdh95HIRxkE/xzEix0rghbRtfLmdstZH1JbAXlqOytsIsXZIDguS/H5xw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TuLTRAPH; 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 23F4060A6F7A; Fri, 13 Nov 2026 17:20:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TuLTRAPH Received: by smtp.kernel.org (Postfix) with ESMTPSA id C57C41F000C4; Fri, 13 Nov 2026 17:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590407; bh=EcpNon18O9o1otibpwnCFv1BMFpd5uZjm4OtiS5v/P8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TuLTRAPHfPPbkjgJcLC5WpFQTh1HgMuCF700VVnXSCEzVws56W0zGWCrOHgfQpJDn krr+GAP6OsGyfMgWTFdDakfPehk65SEjBo9ik+BE42RQEISfKaburQHkLTS6rhOuge DpkLXYZ6PPIh2MeERxjAshTJ41fAvLFSyHc/ajdU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , "Lorenzo Stoakes (ARM)" , Muchun Song , Muhammad Usama Anjum , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 6.18 374/686] mm/gup: fix out-of-bounds write for nr_pages == 0 in GUP-fast Date: Fri, 13 Nov 2026 10:48:27 -0500 Message-ID: <20261113153833.592250619@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 1dfe4b276c23189394afb42d114ee8a54cc3aff2 ] With nr_pages == 0, GUP-fast still enters its page table walk and can write past the caller's page array. The old end <= start check caught empty ranges, but was replaced with an overflow check. Users such as OrangeFS can pass a zero page count derived from a userspace-supplied length. So let's return zero for nr_pages == 0 before starting the walk, just like GUP-slow. Fix generated by an LLM and sent by Chris Mason in private. Fixes: c28b1fc70390 ("mm/gup: reorganize internal_get_user_pages_fast()") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ david: simplify description ] Reviewed-by: Lorenzo Stoakes (ARM) Acked-by: Muchun Song Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-21-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Sasha Levin --- mm/gup.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 6ea400b5b8c5e..ac5abfc3dff7e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3207,6 +3207,9 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages, FOLL_PCI_P2PDMA | FOLL_HONOR_NUMA_FAULT))) return -EINVAL; + if (unlikely(!nr_pages)) + return 0; + if (gup_flags & FOLL_PIN) mm_set_has_pinned_flag(current->mm); -- 2.53.0