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=1795059121; b=g2CEOXve9V9Ay9LEdGr4jK/W774JiXqzCxiJ/QWQd5c/mWaGHeJHzMCgo4GaY3zkcoVG M1rF0abBlBekgVSoD74wnIg1EY8bEZiRECJYZXXCwMN/WUbX5CieGT0Ubg+ITdjAQkGom 0W8W4Xt8myAIAqUkN/ukGPg9QsANWjDKeH5Cohi8GPEpUG1PM2NXJvRkOFd6fJPeZhpIq I4Nj6SmX+2cIf81OAk1SrvOdJuCNXzSnya4aLsVIXLzf/JqKu2mqa0eCIpSxeKXmVU5W+ iMAzCN4kAJt4hOh76gjhk2/DNEI/sRI9zPoi7c6k843oYarTt0CGcccaBC3aXb77kiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795059121; 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=pqdZamFETttjgnJrwibLiIjBrXysILwobFaWz9oieS0=; b=Wgtyl6O2Z1u/QTYaJtC7rxFAi1E2YkLR9/1i8Y7vZ2ZcOxkm1jGrBP9DDkenQzDHv3fU 9uCAqVc/zOAeXb7ZejDdi1PYAV5I42NRyblerVm2Jj2TtbARloQksWuaLiti1OHPbyBZY 8TpX5L5m/7XTOcIf+8oKsaJnvaSAfEjei1ZmcWDR9xK1VMqHh16p1CVhbCEKPRulxczf4 V/Rad0UuTB4uCR51dmmcD3DtB828wciOObKZlrUOdl4/Gp2Bj7k5kYW2+PfVG3q+Jkz1w 6CS4XiVNcll05rfYKtKu4yk9cKTDANgseVDb9wBDMZKiRSY3wUZ/jfzyIPLWIKEmJ+g== 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=PNeoRGT7; 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 E64B7606A32A; Thu, 19 Nov 2026 03:32:00 +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=PNeoRGT7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36BF71F000C4; Thu, 19 Nov 2026 03:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795059120; bh=pqdZamFETttjgnJrwibLiIjBrXysILwobFaWz9oieS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PNeoRGT7gjRarZO6KASBOeu2kBH7TyF5dAnLqO+fSFGgfLy+USsxuzEOxOn1bOX/j STexCVmrcumEoOxTVF+J6H8OCoe6bjglbcV7/JoKjd9Q/lcW/gbd76YyWI8St4OKwW Q70PYziwXx4Qzk0DK/noBWPwHIVWJAHdLcmc6QSU= 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 5.10 0729/1848] mm/gup: fix out-of-bounds write for nr_pages == 0 in GUP-fast Date: Wed, 18 Nov 2026 15:46:07 +0100 Message-ID: <20261118145946.646520483@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-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 11307a8b20d58..e1fe283badf3b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2743,6 +2743,9 @@ static int internal_get_user_pages_fast(unsigned long start, FOLL_FAST_ONLY))) return -EINVAL; + if (unlikely(!nr_pages)) + return 0; + if (gup_flags & FOLL_PIN) atomic_set(¤t->mm->has_pinned, 1); -- 2.53.0