Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/gup: check for overflow when converting nr_pages to bytes in GUP-fast" failed to apply to 6.1-stable tree

PATCH New Sasha Levin 1 participant 2 messages Nov 10 – Nov 11

Subsystems (3)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 21a3888d3d2f87b7f15ccea1f0befd57346fe899
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From 21a3888d3d2f87b7f15ccea1f0befd57346fe899 Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <[email protected]>
Date: Sat, 31 Oct 2026 10:39:51 +0100
Subject: [PATCH] mm/gup: check for overflow when converting nr_pages to bytes
in GUP-fast

The overflow check in gup_fast_fallback() only covers the addition to start. The preceding nr_pages << PAGE_SHIFT can already have truncated the length on 32bit.

Users such as RapidIO's rio_dma_transfer() can derive such page counts from a 64-bit userspace length.

Let's just check_shl_overflow() to reject any such overflow with -EOVERFLOW early.

---
 mm/gup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/gup.c +2 -2
index 1c2ac7c66c309..ba4907b352323 100644
@@ -3225,8 +3225,8 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,
 		might_lock_read(&current->mm->mmap_lock);
 
 	start = untagged_addr(start) & PAGE_MASK;
-	len = nr_pages << PAGE_SHIFT;
-	if (check_add_overflow(start, len, &end))
+	if (check_shl_overflow(nr_pages, PAGE_SHIFT, &len) ||
+	    check_add_overflow(start, len, &end))
 		return -EOVERFLOW;
 	if (end > TASK_SIZE_MAX)
 		return -EFAULT;
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/1 mm/gup: check for overflow when converting nr_pages to bytes in GUP-fast

From: "David Hildenbrand (Arm)" <[email protected]>

[ Upstream commit 21a3888d3d2f87b7f15ccea1f0befd57346fe899 ]

The overflow check in gup_fast_fallback() only covers the addition to start. The preceding nr_pages << PAGE_SHIFT can already have truncated the length on 32bit.

Users such as RapidIO's rio_dma_transfer() can derive such page counts from a 64-bit userspace length.

Let's just check_shl_overflow() to reject any such overflow with -EOVERFLOW early.

Fixes c28b1fc70390 ("mm/gup: reorganize internal_get_user_pages_fast()")
[ sashal: adapted gup_fast_fallback() changes to internal_get_user_pages_fast() ]
---
 mm/gup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/gup.c +3 -3
index b3b6de2c37c12..8629b2e145460 100644
@@ -3065,9 +3065,9 @@ static int internal_get_user_pages_fast(unsigned long start,
 		might_lock_read(&current->mm->mmap_lock);
 
 	start = untagged_addr(start) & PAGE_MASK;
-	len = nr_pages << PAGE_SHIFT;
-	if (check_add_overflow(start, len, &end))
-		return 0;
+	if (check_shl_overflow(nr_pages, PAGE_SHIFT, &len) ||
+	    check_add_overflow(start, len, &end))
+		return -EOVERFLOW;
 	if (unlikely(!access_ok((void __user *)start, len)))
 		return -EFAULT;
 
Signature · 1 line
2.53.0