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=1795037906; b=ZoGk245JbfamPGb1Ki3WDo5FfrV3lbWLDEVAlHXi0KmNVSYRjoYzun61yGBubW1//Z1b s9cvB2natMDNzl/FCFV/irvXC121tDM+GkcI5AI+vGE0Zqa7t5cMTi9c8d+FQItsAfRT4 oGvsp9gB2g9DSyyfKfXKaQAdYXxq/WwX4mLReabeNyMgCLUbo/1f5zmXARGvvAMawOp9E xxgheWPrMvbm/xyelu/m6alMtiEmo7UJyyo5atGqxSEEpDo+OK77SnoLnBm5spX4v4xLO /QkFGHdhEcRlzYyYrFnC7XvsbGzzSXZT6BAgnwZVDJ6xcGJ4oGyIj5DhfsTLmbQl6ug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795037906; 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=J49wZQmCjJpfT0SSz/7PUp9vmCSG4EQQkI4pLFqHO18=; b=O2lFXxxo4KnAK6290Bco5m4qzR6WTqcnpXsp/zw7rivu8exhxoBrXaiLjXBhnnNrPY0l dqwcx/LkUxS/RsykG/fyw4u3twIexrNSQsVddF9TgS+rraN66gXMHHqwtN7gcgY3AGY5t biu8XoJpTEJNxRJ+zbBFo0YgBtClrkNwBkqo60hd8nigYqdWoBYdRsZu9aL99V34k6418 c4rUeBVY4zF7igsaGbrg6DhJlBwi/D9fxgYlXOgZVgAJ+V0Cy/SzuC3vjE6TjVWzTOWFl V+XAsF+S7632DAP186b8dSLyq2f8Zb4CGQw70DBrglbMuZT9sltq90lMIBhOMUJkPeg== 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=oMshH0OJ; 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 DF93D606A31C; Wed, 18 Nov 2026 21:38:25 +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=oMshH0OJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45A0C1F000C4; Wed, 18 Nov 2026 21:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795037905; bh=J49wZQmCjJpfT0SSz/7PUp9vmCSG4EQQkI4pLFqHO18=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oMshH0OJWiUYCM+AfyrVkux4ft7szVhG3kZDi0ingowB1Vzk/f6ZWnRVNSuPjUKK2 4Tzty4B5rS2AiaH+dGX+98b30pyWvGPqqoz5M39SpFKTeWs6YLf/70L4QEhzJ5Reu2 9SefmAaOiGt//5hHIygKqtB4fD2U+Y0l891awz3Y= 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.6 1516/3318] mm/gup: fix out-of-bounds write for nr_pages == 0 in GUP-fast Date: Wed, 18 Nov 2026 15:35:38 +0100 Message-ID: <20261118150406.431314069@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@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 6.6-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 098a837043b61..5a78c23a77248 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3208,6 +3208,9 @@ static int internal_get_user_pages_fast(unsigned long start, 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(¤t->mm->flags); -- 2.53.0