aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/patches-4.4
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/generic/patches-4.4')
-rw-r--r--target/linux/generic/patches-4.4/097-mm-remove-gup_flags-FOLL_WRITE-games-from-__get_user.patch96
-rw-r--r--target/linux/generic/patches-4.4/520-squashfs_update_xz_comp_opts.patch25
-rw-r--r--target/linux/generic/patches-4.4/615-netfilter_add_xt_id_match.patch95
3 files changed, 96 insertions, 120 deletions
diff --git a/target/linux/generic/patches-4.4/097-mm-remove-gup_flags-FOLL_WRITE-games-from-__get_user.patch b/target/linux/generic/patches-4.4/097-mm-remove-gup_flags-FOLL_WRITE-games-from-__get_user.patch
new file mode 100644
index 0000000000..101dbf29ac
--- /dev/null
+++ b/target/linux/generic/patches-4.4/097-mm-remove-gup_flags-FOLL_WRITE-games-from-__get_user.patch
@@ -0,0 +1,96 @@
+From 1294d355881cc5c3421d24fee512f16974addb6c 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()
+
+commit 19be0eaffa3ac7d8eb6784ad9bdbc7d67ed8e619 upstream.
+
+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>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.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 cfebb74..f0ffa01 100644
+--- a/include/linux/mm.h
++++ b/include/linux/mm.h
+@@ -2112,6 +2112,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma,
+ #define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
+ #define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */
+ #define FOLL_MLOCK 0x1000 /* lock present pages */
++#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 deafa2c..4b0b7e7 100644
+--- a/mm/gup.c
++++ b/mm/gup.c
+@@ -58,6 +58,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)
+ {
+@@ -92,7 +102,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;
+ }
+@@ -352,7 +362,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
+
diff --git a/target/linux/generic/patches-4.4/520-squashfs_update_xz_comp_opts.patch b/target/linux/generic/patches-4.4/520-squashfs_update_xz_comp_opts.patch
deleted file mode 100644
index ad11b30281..0000000000
--- a/target/linux/generic/patches-4.4/520-squashfs_update_xz_comp_opts.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From f31b7c0efa255dd17a5f584022a319387f09b0d8 Mon Sep 17 00:00:00 2001
-From: Jonas Gorski <jonas.gorski@gmail.com>
-Date: Tue, 12 Apr 2011 19:55:41 +0200
-Subject: [PATCH] squashfs: update xz compressor options struct.
-
-Update the xz compressor options struct to match the squashfs userspace
-one.
----
- fs/squashfs/xz_wrapper.c | 4 +++-
- 1 files changed, 3 insertions(+), 1 deletions(-)
-
---- a/fs/squashfs/xz_wrapper.c
-+++ b/fs/squashfs/xz_wrapper.c
-@@ -40,8 +40,10 @@ struct squashfs_xz {
- };
-
- struct disk_comp_opts {
-- __le32 dictionary_size;
- __le32 flags;
-+ __le16 bit_opts;
-+ __le16 fb;
-+ __le32 dictionary_size;
- };
-
- struct comp_opts {
diff --git a/target/linux/generic/patches-4.4/615-netfilter_add_xt_id_match.patch b/target/linux/generic/patches-4.4/615-netfilter_add_xt_id_match.patch
deleted file mode 100644
index 8ee29a791b..0000000000
--- a/target/linux/generic/patches-4.4/615-netfilter_add_xt_id_match.patch
+++ /dev/null
@@ -1,95 +0,0 @@
---- a/include/uapi/linux/netfilter/Kbuild
-+++ b/include/uapi/linux/netfilter/Kbuild
-@@ -55,6 +55,7 @@ header-y += xt_ecn.h
- header-y += xt_esp.h
- header-y += xt_hashlimit.h
- header-y += xt_helper.h
-+header-y += xt_id.h
- header-y += xt_ipcomp.h
- header-y += xt_iprange.h
- header-y += xt_ipvs.h
---- /dev/null
-+++ b/include/uapi/linux/netfilter/xt_id.h
-@@ -0,0 +1,8 @@
-+#ifndef _XT_ID_H
-+#define _XT_ID_H
-+
-+struct xt_id_info {
-+ u32 id;
-+};
-+
-+#endif /* XT_ID_H */
---- a/net/netfilter/Kconfig
-+++ b/net/netfilter/Kconfig
-@@ -1180,6 +1180,13 @@ config NETFILTER_XT_MATCH_IPCOMP
-
- To compile it as a module, choose M here. If unsure, say N.
-
-+config NETFILTER_XT_MATCH_ID
-+ tristate '"id" match support'
-+ depends on NETFILTER_ADVANCED
-+ ---help---
-+ This option adds a `id' dummy-match, which allows you to put
-+ numeric IDs into your iptables ruleset.
-+
- config NETFILTER_XT_MATCH_IPRANGE
- tristate '"iprange" address range match support'
- depends on NETFILTER_ADVANCED
---- a/net/netfilter/Makefile
-+++ b/net/netfilter/Makefile
-@@ -144,6 +144,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) +=
- obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
-+obj-$(CONFIG_NETFILTER_XT_MATCH_ID) += xt_id.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_IPCOMP) += xt_ipcomp.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_IPRANGE) += xt_iprange.o
- obj-$(CONFIG_NETFILTER_XT_MATCH_IPVS) += xt_ipvs.o
---- /dev/null
-+++ b/net/netfilter/xt_id.c
-@@ -0,0 +1,45 @@
-+/*
-+ * Implements a dummy match to allow attaching IDs to rules
-+ *
-+ * 2014-08-01 Jo-Philipp Wich <jow@openwrt.org>
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/skbuff.h>
-+#include <linux/netfilter/x_tables.h>
-+#include <linux/netfilter/xt_id.h>
-+
-+MODULE_AUTHOR("Jo-Philipp Wich <jow@openwrt.org>");
-+MODULE_DESCRIPTION("Xtables: No-op match which can be tagged with a 32bit ID");
-+MODULE_LICENSE("GPL");
-+MODULE_ALIAS("ipt_id");
-+MODULE_ALIAS("ip6t_id");
-+
-+static bool
-+id_mt(const struct sk_buff *skb, struct xt_action_param *par)
-+{
-+ /* We always match */
-+ return true;
-+}
-+
-+static struct xt_match id_mt_reg __read_mostly = {
-+ .name = "id",
-+ .revision = 0,
-+ .family = NFPROTO_UNSPEC,
-+ .match = id_mt,
-+ .matchsize = sizeof(struct xt_id_info),
-+ .me = THIS_MODULE,
-+};
-+
-+static int __init id_mt_init(void)
-+{
-+ return xt_register_match(&id_mt_reg);
-+}
-+
-+static void __exit id_mt_exit(void)
-+{
-+ xt_unregister_match(&id_mt_reg);
-+}
-+
-+module_init(id_mt_init);
-+module_exit(id_mt_exit);