GoboLinux Downloads Documentation Community Recipes Screenshots

GoboLinux Recipe & Package Search Tool

71 versions of Linux.

ProgramAgeSizeByWWWSummary
Linux 4.13.2-r1 976  88794 Luca...
The Linux Kernel.
Linux 4.9.16-r3 1147  100651 Luca...
The Linux Kernel.
Linux 4.9.4-r5 1203  99374 Luca...
The Linux Kernel.
Linux 4.8.2-r2 1269  89394 Luca...
The Linux Kernel.
view entry at GitHub | download recipe.bz2 file
01-gobohide.patch
02-apple-gmux.patch
03-macbook-suspend.patch
04-apple-poweroff-quirk-workaround.patch
05-intel-pstate-backport.patch
06-dirty_cow.patch
Recipe
Resources/BuildDependencies
Resources/BuildInformation
Resources/Dependencies
Resources/Description
cell/02-memcpy-cell.patch
cell/Recipe
cell/dot-config
i686/Recipe
i686/dot-config
ppc/Recipe
ppc/dot-config
x86_64/Recipe
x86_64/dot-config
From 19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Thu, 13 Oct 2016 13:07:36 -0700
Subject: mm: remove gup_flags FOLL_WRITE games from __get_user_pages()

This is an ancient bug that was actually attempted to be fixed once
(badly) by me eleven years ago in commit 4ceb5db9757a ("Fix
get_user_pages() race for write access") but that was then undone due to
problems on s390 by commit f33ea7f404e5 ("fix get_user_pages bug").

In the meantime, the s390 situation has long been fixed, and we can now
fix it by checking the pte_dirty() bit properly (and do it better).  The
s390 dirty bit was implemented in abf09bed3cce ("s390/mm: implement
software dirty bits") which made it into v3.9.  Earlier kernels will
have to look at the page state itself.

Also, the VM has become more scalable, and what used a purely
theoretical race back then has become easier to trigger.

To fix it, we introduce a new internal FOLL_COW flag to mark the "yes,
we already did a COW" rather than play racy games with FOLL_WRITE that
is very fundamental, and then use the pte dirty flag to validate that
the FOLL_COW flag is still valid.

Reported-and-tested-by: Phil "not Paul" Oester <kernel@linuxace.com>
Acked-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Michal Hocko <mhocko@suse.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Nick Piggin <npiggin@gmail.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 include/linux/mm.h |  1 +
 mm/gup.c           | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index e9caec6..ed85879 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2232,6 +2232,7 @@ static inline struct page *follow_page(struct vm_area_struct \
*vma,
 #define FOLL_TRIED	0x800	/* a retry, previous pass started an IO */
 #define FOLL_MLOCK	0x1000	/* lock present pages */
 #define FOLL_REMOTE	0x2000	/* we are working on non-current tsk/mm */
+#define FOLL_COW	0x4000	/* internal GUP flag */
 
 typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
 			void *data);
diff --git a/mm/gup.c b/mm/gup.c
index 96b2b2f..22cc22e 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -60,6 +60,16 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned \
long address,
 	return -EEXIST;
 }
 
+/*
+ * FOLL_FORCE can write to even unwritable pte's, but only
+ * after we've gone through a COW cycle and they are dirty.
+ */
+static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
+{
+	return pte_write(pte) ||
+		((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
+}
+
 static struct page *follow_page_pte(struct vm_area_struct *vma,
 		unsigned long address, pmd_t *pmd, unsigned int flags)
 {
@@ -95,7 +105,7 @@ retry:
 	}
 	if ((flags & FOLL_NUMA) && pte_protnone(pte))
 		goto no_page;
-	if ((flags & FOLL_WRITE) && !pte_write(pte)) {
+	if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, flags)) {
 		pte_unmap_unlock(ptep, ptl);
 		return NULL;
 	}
@@ -412,7 +422,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct \
*vma,
 	 * reCOWed by userspace write).
 	 */
 	if ((ret & VM_FAULT_WRITE) && !(vma->vm_flags & VM_WRITE))
-		*flags &= ~FOLL_WRITE;
+	        *flags |= FOLL_COW;
 	return 0;
 }
 
-- 
cgit v0.12

Linux 4.7.4-r1 1339  82767 Luca...
The Linux Kernel.
Linux 4.7.0-r4 1394  82585 Luca...
The Linux Kernel.
Linux 3.13.3-r1 2274  252629 Luca...
The Linux Kernel.
Linux 3.12.6-r1 2334  238949 Luca...
The Linux Kernel.
Linux 3.9.4-r2 2529  70048 Luca...
The Linux Kernel.
Linux 3.7.1-r2 2702  67579 Luca...
The Linux Kernel.
Linux 3.5.0-r1 2853  124391 Luca...
The Linux Kernel.
Linux 3.4.4-r1 2853  124348 Luca...
The Linux Kernel.
Linux 3.3.6-r1 2853  124410 Luca...
The Linux Kernel.
Linux 3.2.12-r2 2981  124345 Luca...
The Linux Kernel.
Linux 3.2.7-r1 3011  123550 Mich...
The Linux Kernel.
Linux 3.1.1-r1 3116  122907 Mich...
The Linux Kernel.
Linux 3.0.4-r4 3177  122754 Luca...
The Linux Kernel.
Linux 2.6.36.3-r1 3400  116087 Diog...
The Linux Kernel.
Linux 2.6.32.3-r1 3778  117990 Luca...
The Linux Kernel.
Linux 2.6.32-r1 3819  117751 Luca...
The Linux Kernel.
Linux 2.6.31.6-r3 3824  126499 Luca...
The Linux Kernel.
Linux 2.6.30.5-r1 3903  166102 Jona...
The Linux Kernel.
Linux 2.6.29.1-r1 4046  117500 Luca...
The Linux Kernel.
Linux 2.6.28.7-r1 4102  115518 Giam...
The Linux Kernel.
Linux 2.6.28.1-r1 4102  115487 Giam...
The Linux Kernel.
Linux 2.6.28-r1 4102  116681 Mich...
The Linux Kernel.
Linux 2.6.27.8-r1 4102  134160 Giam...
The Linux Kernel.
Linux 2.6.27.4-r3 4102  149529 Luca...
The Linux Kernel.
Linux 2.6.25.17-r1 4102  172834 Giam...
The Linux Kernel.
Linux 2.6.25.16-r1 4102  166500 Giam...
The Linux Kernel.
Linux 2.6.25.10-r2 4102  165320 Giam...
The Linux Kernel.
Linux 2.6.25.7-r1 4102  157294 Giam...
The Linux Kernel.
Linux 2.6.25.4-r1 4102  133017 Hopp...
The Linux Kernel.
Linux 2.6.25-r1 4102  133216 Luca...
The Linux Kernel.
Linux 2.6.24.4-r5 4102  150733
The Linux Kernel.
Linux 2.6.24.3-r5 4102  150221 Luca...
The Linux Kernel.
Linux 2.6.24.2-r3 4102  146488 Giam...
The Linux Kernel.
Linux 2.6.24.1-r1 4102  146454 Giam...
The Linux Kernel.
Linux 2.6.24-r1 4102  146428 Luca...
The Linux Kernel.
Linux 2.6.23.8-r4 4102  155842 Luca...
The Linux Kernel.
Linux 2.6.22.7-r4 4102  114727 Luca...
The Linux Kernel.
Linux 2.6.22.1-r1 4102  121391 Luca...
The Linux Kernel.
Linux 2.6.21.1-r3 4102  118854 Luca...
The Linux Kernel.
Linux 2.6.20.7-r1 4102  117945 Luca...
The Linux Kernel.
Linux 2.6.20.4-r3 4102  151150 Luca...
The Linux Kernel.
Linux 2.6.20-r1 4102  106429 Luca...
The Linux Kernel.
Linux 2.6.18.3-r2 4102  111124 Luca...
The Linux Kernel.
Linux 2.6.17.11-r1 4102  164053 Luca...
The Linux Kernel.
Linux 2.6.17.3-r1 4102  165067 Luca...
The Linux Kernel.
Linux 2.6.16.20-r1 4102  133625 Luca...
The Linux Kernel.
Linux 2.6.16.14-r1 4102  168270 Luca...
The Linux Kernel.
Linux 2.6.15.5-r1 4102  224686 Jona...
The Linux Kernel.
Linux 2.6.15.2-r1 4102  177165 Carl...
The Linux Kernel.
Linux 2.6.15.1-r1 4102  149219 Jona...
The Linux Kernel.
Linux 2.6.15-r1 4102  149214 Luca...
The Linux Kernel.
Linux 2.6.14.4-r1 4102  150166 Jona...
The Linux Kernel.
Linux 2.6.14.3-r1 4102  150060 Jona...
The Linux Kernel.
Linux 2.6.14.2-r1 4102  149791 Carl...
The Linux Kernel.
Linux 2.6.13.4-r1 4102  149559 Luca...
The Linux Kernel.
Linux 2.6.13.2-r1 4102  56611 Jona...
The Linux Kernel.
Linux 2.6.13.1-r1 4102  56378 Luca...
The Linux Kernel.
Linux 2.6.12.2-r1 4102  50355 Luca...
The Linux Kernel.
Linux 2.6.11.9-r1 4102  98969 Luca...
The Linux Kernel.
Linux 2.6.11.8-r1 4102  109424 Jona...
The Linux Kernel.
Linux 2.6.11-r1 4102  99032 Luca...
The Linux Kernel.
Linux 2.6.10-r1 4102  65969 Luca...
The Linux Kernel.
Linux 2.6.9-r1 4102  278461 Luca...
The Linux Kernel.
Linux 2.6.8.1-r1 4102  35576 Luca...
The Linux Kernel.
Linux 2.6.7-r1 4102  22610 Luca...
The Linux Kernel.
Linux 2.6.6-r1 4102  21958 Luca...
The Linux Kernel.
Linux 2.4.26-r1 4102  22359 Luca...
The Linux Kernel.