]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.9-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2018 07:31:28 +0000 (08:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2018 07:31:28 +0000 (08:31 +0100)
added patches:
blk_rq_map_user_iov-fix-error-override.patch
blktrace-fix-unlocked-registration-of-tracepoints.patch
cfg80211-check-dev_set_name-return-value.patch
crypto-x86-twofish-3way-fix-rbp-usage.patch
drm-require-__gfp_nofail-for-the-legacy-drm_modeset_lock_all.patch
kcm-check-if-sk_user_data-already-set-in-kcm_attach.patch
kcm-only-allow-tcp-sockets-to-be-attached-to-a-kcm-mux.patch
kcov-detect-double-association-with-a-single-task.patch
kvm-x86-fix-escape-of-guest-dr6-to-the-host.patch
mm-vmscan-make-unregister_shrinker-no-op-if-register_shrinker-failed.patch
net-avoid-skb_warn_bad_offload-on-is_err.patch
netfilter-ipt_clusterip-fix-out-of-bounds-accesses-in-clusterip_tg_check.patch
netfilter-on-sockopt-acquire-sock-lock-only-in-the-required-scope.patch
netfilter-x_tables-avoid-out-of-bounds-reads-in-xt_request_find_-match-target.patch
netfilter-x_tables-fix-int-overflow-in-xt_alloc_table_info.patch
netfilter-xt_cgroup-initialize-info-priv-in-cgroup_mt_check_v1.patch
netfilter-xt_rateest-acquire-xt_rateest_mutex-for-hash-insert.patch
provide-a-function-to-create-a-nul-terminated-string-from-unterminated-data.patch
ptr_ring-fail-early-if-queue-occupies-more-than-kmalloc_max_size.patch
rds-tcp-atomically-purge-entries-from-rds_tcp_conn_list-during-netns-delete.patch
sctp-set-frag_point-in-sctp_setsockopt_maxseg-correctly.patch
selinux-ensure-the-context-is-nul-terminated-in-security_context_to_sid_core.patch
selinux-skip-bounded-transition-processing-if-the-policy-isn-t-loaded.patch
staging-android-ion-add-__gfp_nowarn-for-system-contig-heap.patch
staging-android-ion-switch-from-warn-to-pr_warn.patch
vhost-use-mutex_lock_nested-in-vhost_dev_lock_vqs.patch
xfrm-check-id-proto-in-validate_tmpl.patch
xfrm-fix-stack-out-of-bounds-read-on-socket-policy-lookup.patch
xfrm-skip-policies-marked-as-dead-while-rehashing.patch

30 files changed:
queue-4.9/blk_rq_map_user_iov-fix-error-override.patch [new file with mode: 0644]
queue-4.9/blktrace-fix-unlocked-registration-of-tracepoints.patch [new file with mode: 0644]
queue-4.9/cfg80211-check-dev_set_name-return-value.patch [new file with mode: 0644]
queue-4.9/crypto-x86-twofish-3way-fix-rbp-usage.patch [new file with mode: 0644]
queue-4.9/drm-require-__gfp_nofail-for-the-legacy-drm_modeset_lock_all.patch [new file with mode: 0644]
queue-4.9/kcm-check-if-sk_user_data-already-set-in-kcm_attach.patch [new file with mode: 0644]
queue-4.9/kcm-only-allow-tcp-sockets-to-be-attached-to-a-kcm-mux.patch [new file with mode: 0644]
queue-4.9/kcov-detect-double-association-with-a-single-task.patch [new file with mode: 0644]
queue-4.9/kvm-x86-fix-escape-of-guest-dr6-to-the-host.patch [new file with mode: 0644]
queue-4.9/mm-vmscan-make-unregister_shrinker-no-op-if-register_shrinker-failed.patch [new file with mode: 0644]
queue-4.9/net-avoid-skb_warn_bad_offload-on-is_err.patch [new file with mode: 0644]
queue-4.9/netfilter-ipt_clusterip-fix-out-of-bounds-accesses-in-clusterip_tg_check.patch [new file with mode: 0644]
queue-4.9/netfilter-on-sockopt-acquire-sock-lock-only-in-the-required-scope.patch [new file with mode: 0644]
queue-4.9/netfilter-x_tables-avoid-out-of-bounds-reads-in-xt_request_find_-match-target.patch [new file with mode: 0644]
queue-4.9/netfilter-x_tables-fix-int-overflow-in-xt_alloc_table_info.patch [new file with mode: 0644]
queue-4.9/netfilter-xt_cgroup-initialize-info-priv-in-cgroup_mt_check_v1.patch [new file with mode: 0644]
queue-4.9/netfilter-xt_rateest-acquire-xt_rateest_mutex-for-hash-insert.patch [new file with mode: 0644]
queue-4.9/provide-a-function-to-create-a-nul-terminated-string-from-unterminated-data.patch [new file with mode: 0644]
queue-4.9/ptr_ring-fail-early-if-queue-occupies-more-than-kmalloc_max_size.patch [new file with mode: 0644]
queue-4.9/rds-tcp-atomically-purge-entries-from-rds_tcp_conn_list-during-netns-delete.patch [new file with mode: 0644]
queue-4.9/sctp-set-frag_point-in-sctp_setsockopt_maxseg-correctly.patch [new file with mode: 0644]
queue-4.9/selinux-ensure-the-context-is-nul-terminated-in-security_context_to_sid_core.patch [new file with mode: 0644]
queue-4.9/selinux-skip-bounded-transition-processing-if-the-policy-isn-t-loaded.patch [new file with mode: 0644]
queue-4.9/series [new file with mode: 0644]
queue-4.9/staging-android-ion-add-__gfp_nowarn-for-system-contig-heap.patch [new file with mode: 0644]
queue-4.9/staging-android-ion-switch-from-warn-to-pr_warn.patch [new file with mode: 0644]
queue-4.9/vhost-use-mutex_lock_nested-in-vhost_dev_lock_vqs.patch [new file with mode: 0644]
queue-4.9/xfrm-check-id-proto-in-validate_tmpl.patch [new file with mode: 0644]
queue-4.9/xfrm-fix-stack-out-of-bounds-read-on-socket-policy-lookup.patch [new file with mode: 0644]
queue-4.9/xfrm-skip-policies-marked-as-dead-while-rehashing.patch [new file with mode: 0644]

diff --git a/queue-4.9/blk_rq_map_user_iov-fix-error-override.patch b/queue-4.9/blk_rq_map_user_iov-fix-error-override.patch
new file mode 100644 (file)
index 0000000..cf39659
--- /dev/null
@@ -0,0 +1,46 @@
+From 69e0927b3774563c19b5fb32e91d75edc147fb62 Mon Sep 17 00:00:00 2001
+From: Douglas Gilbert <dgilbert@interlog.com>
+Date: Sun, 14 Jan 2018 17:00:48 -0500
+Subject: blk_rq_map_user_iov: fix error override
+
+From: Douglas Gilbert <dgilbert@interlog.com>
+
+commit 69e0927b3774563c19b5fb32e91d75edc147fb62 upstream.
+
+During stress tests by syzkaller on the sg driver the block layer
+infrequently returns EINVAL. Closer inspection shows the block
+layer was trying to return ENOMEM (which is much more
+understandable) but for some reason overroad that useful error.
+
+Patch below does not show this (unchanged) line:
+   ret =__blk_rq_map_user_iov(rq, map_data, &i, gfp_mask, copy);
+That 'ret' was being overridden when that function failed.
+
+Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
+Signed-off-by: Jens Axboe <axboe@kernel.dk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ block/blk-map.c |    4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/block/blk-map.c
++++ b/block/blk-map.c
+@@ -116,7 +116,7 @@ int blk_rq_map_user_iov(struct request_q
+       unsigned long align = q->dma_pad_mask | queue_dma_alignment(q);
+       struct bio *bio = NULL;
+       struct iov_iter i;
+-      int ret;
++      int ret = -EINVAL;
+       if (!iter_is_iovec(iter))
+               goto fail;
+@@ -145,7 +145,7 @@ unmap_rq:
+       __blk_rq_unmap_user(bio);
+ fail:
+       rq->bio = NULL;
+-      return -EINVAL;
++      return ret;
+ }
+ EXPORT_SYMBOL(blk_rq_map_user_iov);
diff --git a/queue-4.9/blktrace-fix-unlocked-registration-of-tracepoints.patch b/queue-4.9/blktrace-fix-unlocked-registration-of-tracepoints.patch
new file mode 100644 (file)
index 0000000..2d0fe6f
--- /dev/null
@@ -0,0 +1,144 @@
+From a6da0024ffc19e0d47712bb5ca4fd083f76b07df Mon Sep 17 00:00:00 2001
+From: Jens Axboe <axboe@kernel.dk>
+Date: Sun, 5 Nov 2017 09:16:09 -0700
+Subject: blktrace: fix unlocked registration of tracepoints
+
+From: Jens Axboe <axboe@kernel.dk>
+
+commit a6da0024ffc19e0d47712bb5ca4fd083f76b07df upstream.
+
+We need to ensure that tracepoints are registered and unregistered
+with the users of them. The existing atomic count isn't enough for
+that. Add a lock around the tracepoints, so we serialize access
+to them.
+
+This fixes cases where we have multiple users setting up and
+tearing down tracepoints, like this:
+
+CPU: 0 PID: 2995 Comm: syzkaller857118 Not tainted
+4.14.0-rc5-next-20171018+ #36
+Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
+Google 01/01/2011
+Call Trace:
+  __dump_stack lib/dump_stack.c:16 [inline]
+  dump_stack+0x194/0x257 lib/dump_stack.c:52
+  panic+0x1e4/0x41c kernel/panic.c:183
+  __warn+0x1c4/0x1e0 kernel/panic.c:546
+  report_bug+0x211/0x2d0 lib/bug.c:183
+  fixup_bug+0x40/0x90 arch/x86/kernel/traps.c:177
+  do_trap_no_signal arch/x86/kernel/traps.c:211 [inline]
+  do_trap+0x260/0x390 arch/x86/kernel/traps.c:260
+  do_error_trap+0x120/0x390 arch/x86/kernel/traps.c:297
+  do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:310
+  invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905
+RIP: 0010:tracepoint_add_func kernel/tracepoint.c:210 [inline]
+RIP: 0010:tracepoint_probe_register_prio+0x397/0x9a0 kernel/tracepoint.c:283
+RSP: 0018:ffff8801d1d1f6c0 EFLAGS: 00010293
+RAX: ffff8801d22e8540 RBX: 00000000ffffffef RCX: ffffffff81710f07
+RDX: 0000000000000000 RSI: ffffffff85b679c0 RDI: ffff8801d5f19818
+RBP: ffff8801d1d1f7c8 R08: ffffffff81710c10 R09: 0000000000000004
+R10: ffff8801d1d1f6b0 R11: 0000000000000003 R12: ffffffff817597f0
+R13: 0000000000000000 R14: 00000000ffffffff R15: ffff8801d1d1f7a0
+  tracepoint_probe_register+0x2a/0x40 kernel/tracepoint.c:304
+  register_trace_block_rq_insert include/trace/events/block.h:191 [inline]
+  blk_register_tracepoints+0x1e/0x2f0 kernel/trace/blktrace.c:1043
+  do_blk_trace_setup+0xa10/0xcf0 kernel/trace/blktrace.c:542
+  blk_trace_setup+0xbd/0x180 kernel/trace/blktrace.c:564
+  sg_ioctl+0xc71/0x2d90 drivers/scsi/sg.c:1089
+  vfs_ioctl fs/ioctl.c:45 [inline]
+  do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
+  SYSC_ioctl fs/ioctl.c:700 [inline]
+  SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
+  entry_SYSCALL_64_fastpath+0x1f/0xbe
+RIP: 0033:0x444339
+RSP: 002b:00007ffe05bb5b18 EFLAGS: 00000206 ORIG_RAX: 0000000000000010
+RAX: ffffffffffffffda RBX: 00000000006d66c0 RCX: 0000000000444339
+RDX: 000000002084cf90 RSI: 00000000c0481273 RDI: 0000000000000009
+RBP: 0000000000000082 R08: 0000000000000000 R09: 0000000000000000
+R10: 0000000000000000 R11: 0000000000000206 R12: ffffffffffffffff
+R13: 00000000c0481273 R14: 0000000000000000 R15: 0000000000000000
+
+since we can now run these in parallel. Ensure that the exported helpers
+for doing this are grabbing the queue trace mutex.
+
+Reported-by: Steven Rostedt <rostedt@goodmis.org>
+Tested-by: Dmitry Vyukov <dvyukov@google.com>
+Signed-off-by: Jens Axboe <axboe@kernel.dk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ kernel/trace/blktrace.c |   32 ++++++++++++++++++++++----------
+ 1 file changed, 22 insertions(+), 10 deletions(-)
+
+--- a/kernel/trace/blktrace.c
++++ b/kernel/trace/blktrace.c
+@@ -57,7 +57,8 @@ static struct tracer_flags blk_tracer_fl
+ };
+ /* Global reference count of probes */
+-static atomic_t blk_probes_ref = ATOMIC_INIT(0);
++static DEFINE_MUTEX(blk_probe_mutex);
++static int blk_probes_ref;
+ static void blk_register_tracepoints(void);
+ static void blk_unregister_tracepoints(void);
+@@ -306,11 +307,26 @@ static void blk_trace_free(struct blk_tr
+       kfree(bt);
+ }
++static void get_probe_ref(void)
++{
++      mutex_lock(&blk_probe_mutex);
++      if (++blk_probes_ref == 1)
++              blk_register_tracepoints();
++      mutex_unlock(&blk_probe_mutex);
++}
++
++static void put_probe_ref(void)
++{
++      mutex_lock(&blk_probe_mutex);
++      if (!--blk_probes_ref)
++              blk_unregister_tracepoints();
++      mutex_unlock(&blk_probe_mutex);
++}
++
+ static void blk_trace_cleanup(struct blk_trace *bt)
+ {
+       blk_trace_free(bt);
+-      if (atomic_dec_and_test(&blk_probes_ref))
+-              blk_unregister_tracepoints();
++      put_probe_ref();
+ }
+ int blk_trace_remove(struct request_queue *q)
+@@ -522,8 +538,7 @@ int do_blk_trace_setup(struct request_qu
+       if (cmpxchg(&q->blk_trace, NULL, bt))
+               goto err;
+-      if (atomic_inc_return(&blk_probes_ref) == 1)
+-              blk_register_tracepoints();
++      get_probe_ref();
+       return 0;
+ err:
+@@ -1469,9 +1484,7 @@ static int blk_trace_remove_queue(struct
+       if (bt == NULL)
+               return -EINVAL;
+-      if (atomic_dec_and_test(&blk_probes_ref))
+-              blk_unregister_tracepoints();
+-
++      put_probe_ref();
+       blk_trace_free(bt);
+       return 0;
+ }
+@@ -1502,8 +1515,7 @@ static int blk_trace_setup_queue(struct
+       if (cmpxchg(&q->blk_trace, NULL, bt))
+               goto free_bt;
+-      if (atomic_inc_return(&blk_probes_ref) == 1)
+-              blk_register_tracepoints();
++      get_probe_ref();
+       return 0;
+ free_bt:
diff --git a/queue-4.9/cfg80211-check-dev_set_name-return-value.patch b/queue-4.9/cfg80211-check-dev_set_name-return-value.patch
new file mode 100644 (file)
index 0000000..27f4aed
--- /dev/null
@@ -0,0 +1,49 @@
+From 59b179b48ce2a6076448a44531242ac2b3f6cef2 Mon Sep 17 00:00:00 2001
+From: Johannes Berg <johannes.berg@intel.com>
+Date: Mon, 15 Jan 2018 09:58:27 +0100
+Subject: cfg80211: check dev_set_name() return value
+
+From: Johannes Berg <johannes.berg@intel.com>
+
+commit 59b179b48ce2a6076448a44531242ac2b3f6cef2 upstream.
+
+syzbot reported a warning from rfkill_alloc(), and after a while
+I think that the reason is that it was doing fault injection and
+the dev_set_name() failed, leaving the name NULL, and we didn't
+check the return value and got to rfkill_alloc() with a NULL name.
+Since we really don't want a NULL name, we ought to check the
+return value.
+
+Fixes: fb28ad35906a ("net: struct device - replace bus_id with dev_name(), dev_set_name()")
+Reported-by: syzbot+1ddfb3357e1d7bb5b5d3@syzkaller.appspotmail.com
+Signed-off-by: Johannes Berg <johannes.berg@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/wireless/core.c |    8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+--- a/net/wireless/core.c
++++ b/net/wireless/core.c
+@@ -421,6 +421,8 @@ struct wiphy *wiphy_new_nm(const struct
+               if (rv)
+                       goto use_default_name;
+       } else {
++              int rv;
++
+ use_default_name:
+               /* NOTE:  This is *probably* safe w/out holding rtnl because of
+                * the restrictions on phy names.  Probably this call could
+@@ -428,7 +430,11 @@ use_default_name:
+                * phyX.  But, might should add some locking and check return
+                * value, and use a different name if this one exists?
+                */
+-              dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
++              rv = dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
++              if (rv < 0) {
++                      kfree(rdev);
++                      return NULL;
++              }
+       }
+       INIT_LIST_HEAD(&rdev->wiphy.wdev_list);
diff --git a/queue-4.9/crypto-x86-twofish-3way-fix-rbp-usage.patch b/queue-4.9/crypto-x86-twofish-3way-fix-rbp-usage.patch
new file mode 100644 (file)
index 0000000..f8b333a
--- /dev/null
@@ -0,0 +1,260 @@
+From d8c7fe9f2a486a6e5f0d5229ca43807af5ab22c6 Mon Sep 17 00:00:00 2001
+From: Eric Biggers <ebiggers@google.com>
+Date: Mon, 18 Dec 2017 16:40:26 -0800
+Subject: crypto: x86/twofish-3way - Fix %rbp usage
+
+From: Eric Biggers <ebiggers@google.com>
+
+commit d8c7fe9f2a486a6e5f0d5229ca43807af5ab22c6 upstream.
+
+Using %rbp as a temporary register breaks frame pointer convention and
+breaks stack traces when unwinding from an interrupt in the crypto code.
+
+In twofish-3way, we can't simply replace %rbp with another register
+because there are none available.  Instead, we use the stack to hold the
+values that %rbp, %r11, and %r12 were holding previously.  Each of these
+values represents the half of the output from the previous Feistel round
+that is being passed on unchanged to the following round.  They are only
+used once per round, when they are exchanged with %rax, %rbx, and %rcx.
+
+As a result, we free up 3 registers (one per block) and can reassign
+them so that %rbp is not used, and additionally %r14 and %r15 are not
+used so they do not need to be saved/restored.
+
+There may be a small overhead caused by replacing 'xchg REG, REG' with
+the needed sequence 'mov MEM, REG; mov REG, MEM; mov REG, REG' once per
+round.  But, counterintuitively, when I tested "ctr-twofish-3way" on a
+Haswell processor, the new version was actually about 2% faster.
+(Perhaps 'xchg' is not as well optimized as plain moves.)
+
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Eric Biggers <ebiggers@google.com>
+Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
+Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/x86/crypto/twofish-x86_64-asm_64-3way.S |  118 ++++++++++++++-------------
+ 1 file changed, 63 insertions(+), 55 deletions(-)
+
+--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
++++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
+@@ -55,29 +55,31 @@
+ #define RAB1bl %bl
+ #define RAB2bl %cl
++#define CD0 0x0(%rsp)
++#define CD1 0x8(%rsp)
++#define CD2 0x10(%rsp)
++
++# used only before/after all rounds
+ #define RCD0 %r8
+ #define RCD1 %r9
+ #define RCD2 %r10
+-#define RCD0d %r8d
+-#define RCD1d %r9d
+-#define RCD2d %r10d
+-
+-#define RX0 %rbp
+-#define RX1 %r11
+-#define RX2 %r12
+-
+-#define RX0d %ebp
+-#define RX1d %r11d
+-#define RX2d %r12d
+-
+-#define RY0 %r13
+-#define RY1 %r14
+-#define RY2 %r15
+-
+-#define RY0d %r13d
+-#define RY1d %r14d
+-#define RY2d %r15d
++# used only during rounds
++#define RX0 %r8
++#define RX1 %r9
++#define RX2 %r10
++
++#define RX0d %r8d
++#define RX1d %r9d
++#define RX2d %r10d
++
++#define RY0 %r11
++#define RY1 %r12
++#define RY2 %r13
++
++#define RY0d %r11d
++#define RY1d %r12d
++#define RY2d %r13d
+ #define RT0 %rdx
+ #define RT1 %rsi
+@@ -85,6 +87,8 @@
+ #define RT0d %edx
+ #define RT1d %esi
++#define RT1bl %sil
++
+ #define do16bit_ror(rot, op1, op2, T0, T1, tmp1, tmp2, ab, dst) \
+       movzbl ab ## bl,                tmp2 ## d; \
+       movzbl ab ## bh,                tmp1 ## d; \
+@@ -92,6 +96,11 @@
+       op1##l T0(CTX, tmp2, 4),        dst ## d; \
+       op2##l T1(CTX, tmp1, 4),        dst ## d;
++#define swap_ab_with_cd(ab, cd, tmp)  \
++      movq cd, tmp;                   \
++      movq ab, cd;                    \
++      movq tmp, ab;
++
+ /*
+  * Combined G1 & G2 function. Reordered with help of rotates to have moves
+  * at begining.
+@@ -110,15 +119,15 @@
+       /* G1,2 && G2,2 */ \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 0, x ## 0); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 0, y ## 0); \
+-      xchgq cd ## 0, ab ## 0; \
++      swap_ab_with_cd(ab ## 0, cd ## 0, RT0); \
+       \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 1, x ## 1); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 1, y ## 1); \
+-      xchgq cd ## 1, ab ## 1; \
++      swap_ab_with_cd(ab ## 1, cd ## 1, RT0); \
+       \
+       do16bit_ror(32, xor, xor, Tx2, Tx3, RT0, RT1, ab ## 2, x ## 2); \
+       do16bit_ror(16, xor, xor, Ty3, Ty0, RT0, RT1, ab ## 2, y ## 2); \
+-      xchgq cd ## 2, ab ## 2;
++      swap_ab_with_cd(ab ## 2, cd ## 2, RT0);
+ #define enc_round_end(ab, x, y, n) \
+       addl y ## d,                    x ## d; \
+@@ -168,6 +177,16 @@
+       decrypt_round3(ba, dc, (n*2)+1); \
+       decrypt_round3(ba, dc, (n*2));
++#define push_cd()     \
++      pushq RCD2;     \
++      pushq RCD1;     \
++      pushq RCD0;
++
++#define pop_cd()      \
++      popq RCD0;      \
++      popq RCD1;      \
++      popq RCD2;
++
+ #define inpack3(in, n, xy, m) \
+       movq 4*(n)(in),                 xy ## 0; \
+       xorq w+4*m(CTX),                xy ## 0; \
+@@ -223,11 +242,8 @@ ENTRY(__twofish_enc_blk_3way)
+        *      %rdx: src, RIO
+        *      %rcx: bool, if true: xor output
+        */
+-      pushq %r15;
+-      pushq %r14;
+       pushq %r13;
+       pushq %r12;
+-      pushq %rbp;
+       pushq %rbx;
+       pushq %rcx; /* bool xor */
+@@ -235,40 +251,36 @@ ENTRY(__twofish_enc_blk_3way)
+       inpack_enc3();
+-      encrypt_cycle3(RAB, RCD, 0);
+-      encrypt_cycle3(RAB, RCD, 1);
+-      encrypt_cycle3(RAB, RCD, 2);
+-      encrypt_cycle3(RAB, RCD, 3);
+-      encrypt_cycle3(RAB, RCD, 4);
+-      encrypt_cycle3(RAB, RCD, 5);
+-      encrypt_cycle3(RAB, RCD, 6);
+-      encrypt_cycle3(RAB, RCD, 7);
++      push_cd();
++      encrypt_cycle3(RAB, CD, 0);
++      encrypt_cycle3(RAB, CD, 1);
++      encrypt_cycle3(RAB, CD, 2);
++      encrypt_cycle3(RAB, CD, 3);
++      encrypt_cycle3(RAB, CD, 4);
++      encrypt_cycle3(RAB, CD, 5);
++      encrypt_cycle3(RAB, CD, 6);
++      encrypt_cycle3(RAB, CD, 7);
++      pop_cd();
+       popq RIO; /* dst */
+-      popq %rbp; /* bool xor */
++      popq RT1; /* bool xor */
+-      testb %bpl, %bpl;
++      testb RT1bl, RT1bl;
+       jnz .L__enc_xor3;
+       outunpack_enc3(mov);
+       popq %rbx;
+-      popq %rbp;
+       popq %r12;
+       popq %r13;
+-      popq %r14;
+-      popq %r15;
+       ret;
+ .L__enc_xor3:
+       outunpack_enc3(xor);
+       popq %rbx;
+-      popq %rbp;
+       popq %r12;
+       popq %r13;
+-      popq %r14;
+-      popq %r15;
+       ret;
+ ENDPROC(__twofish_enc_blk_3way)
+@@ -278,35 +290,31 @@ ENTRY(twofish_dec_blk_3way)
+        *      %rsi: dst
+        *      %rdx: src, RIO
+        */
+-      pushq %r15;
+-      pushq %r14;
+       pushq %r13;
+       pushq %r12;
+-      pushq %rbp;
+       pushq %rbx;
+       pushq %rsi; /* dst */
+       inpack_dec3();
+-      decrypt_cycle3(RAB, RCD, 7);
+-      decrypt_cycle3(RAB, RCD, 6);
+-      decrypt_cycle3(RAB, RCD, 5);
+-      decrypt_cycle3(RAB, RCD, 4);
+-      decrypt_cycle3(RAB, RCD, 3);
+-      decrypt_cycle3(RAB, RCD, 2);
+-      decrypt_cycle3(RAB, RCD, 1);
+-      decrypt_cycle3(RAB, RCD, 0);
++      push_cd();
++      decrypt_cycle3(RAB, CD, 7);
++      decrypt_cycle3(RAB, CD, 6);
++      decrypt_cycle3(RAB, CD, 5);
++      decrypt_cycle3(RAB, CD, 4);
++      decrypt_cycle3(RAB, CD, 3);
++      decrypt_cycle3(RAB, CD, 2);
++      decrypt_cycle3(RAB, CD, 1);
++      decrypt_cycle3(RAB, CD, 0);
++      pop_cd();
+       popq RIO; /* dst */
+       outunpack_dec3();
+       popq %rbx;
+-      popq %rbp;
+       popq %r12;
+       popq %r13;
+-      popq %r14;
+-      popq %r15;
+       ret;
+ ENDPROC(twofish_dec_blk_3way)
diff --git a/queue-4.9/drm-require-__gfp_nofail-for-the-legacy-drm_modeset_lock_all.patch b/queue-4.9/drm-require-__gfp_nofail-for-the-legacy-drm_modeset_lock_all.patch
new file mode 100644 (file)
index 0000000..6fd5822
--- /dev/null
@@ -0,0 +1,43 @@
+From d18d1a5ac811d12f7ebc1129230312b5f2c50cb8 Mon Sep 17 00:00:00 2001
+From: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Tue, 31 Oct 2017 11:55:35 +0000
+Subject: drm: Require __GFP_NOFAIL for the legacy drm_modeset_lock_all
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d18d1a5ac811d12f7ebc1129230312b5f2c50cb8 upstream.
+
+To acquire all modeset locks requires a ww_ctx to be allocated. As this
+is the legacy path and the allocation small, to reduce the changes
+required (and complex untested error handling) to the legacy drivers, we
+simply assume that the allocation succeeds. At present, it relies on the
+too-small-to-fail rule, but syzbot found that by injecting a failure
+here we would hit the WARN. Document that this allocation must succeed
+with __GFP_NOFAIL.
+
+Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/20171031115535.15166-1-chris@chris-wilson.co.uk
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/gpu/drm/drm_modeset_lock.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/gpu/drm/drm_modeset_lock.c
++++ b/drivers/gpu/drm/drm_modeset_lock.c
+@@ -81,7 +81,7 @@ void drm_modeset_lock_all(struct drm_dev
+       struct drm_modeset_acquire_ctx *ctx;
+       int ret;
+-      ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
++      ctx = kzalloc(sizeof(*ctx), GFP_KERNEL | __GFP_NOFAIL);
+       if (WARN_ON(!ctx))
+               return;
diff --git a/queue-4.9/kcm-check-if-sk_user_data-already-set-in-kcm_attach.patch b/queue-4.9/kcm-check-if-sk_user_data-already-set-in-kcm_attach.patch
new file mode 100644 (file)
index 0000000..bf3a313
--- /dev/null
@@ -0,0 +1,63 @@
+From e5571240236c5652f3e079b1d5866716a7ad819c Mon Sep 17 00:00:00 2001
+From: Tom Herbert <tom@quantonium.net>
+Date: Wed, 24 Jan 2018 12:35:41 -0800
+Subject: kcm: Check if sk_user_data already set in kcm_attach
+
+From: Tom Herbert <tom@quantonium.net>
+
+commit e5571240236c5652f3e079b1d5866716a7ad819c upstream.
+
+This is needed to prevent sk_user_data being overwritten.
+The check is done under the callback lock. This should prevent
+a socket from being attached twice to a KCM mux. It also prevents
+a socket from being attached for other use cases of sk_user_data
+as long as the other cases set sk_user_data under the lock.
+Followup work is needed to unify all the use cases of sk_user_data
+to use the same locking.
+
+Reported-by: syzbot+114b15f2be420a8886c3@syzkaller.appspotmail.com
+Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module")
+Signed-off-by: Tom Herbert <tom@quantonium.net>
+Reviewed-by: Eric Dumazet <edumazet@google.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/kcm/kcmsock.c |   16 ++++++++++++++--
+ 1 file changed, 14 insertions(+), 2 deletions(-)
+
+--- a/net/kcm/kcmsock.c
++++ b/net/kcm/kcmsock.c
+@@ -1404,9 +1404,18 @@ static int kcm_attach(struct socket *soc
+               return err;
+       }
+-      sock_hold(csk);
+-
+       write_lock_bh(&csk->sk_callback_lock);
++
++      /* Check if sk_user_data is aready by KCM or someone else.
++       * Must be done under lock to prevent race conditions.
++       */
++      if (csk->sk_user_data) {
++              write_unlock_bh(&csk->sk_callback_lock);
++              strp_done(&psock->strp);
++              kmem_cache_free(kcm_psockp, psock);
++              return -EALREADY;
++      }
++
+       psock->save_data_ready = csk->sk_data_ready;
+       psock->save_write_space = csk->sk_write_space;
+       psock->save_state_change = csk->sk_state_change;
+@@ -1414,8 +1423,11 @@ static int kcm_attach(struct socket *soc
+       csk->sk_data_ready = psock_data_ready;
+       csk->sk_write_space = psock_write_space;
+       csk->sk_state_change = psock_state_change;
++
+       write_unlock_bh(&csk->sk_callback_lock);
++      sock_hold(csk);
++
+       /* Finished initialization, now add the psock to the MUX. */
+       spin_lock_bh(&mux->lock);
+       head = &mux->psocks;
diff --git a/queue-4.9/kcm-only-allow-tcp-sockets-to-be-attached-to-a-kcm-mux.patch b/queue-4.9/kcm-only-allow-tcp-sockets-to-be-attached-to-a-kcm-mux.patch
new file mode 100644 (file)
index 0000000..600baa4
--- /dev/null
@@ -0,0 +1,41 @@
+From 581e7226a5d43f629eb6399a121f85f6a15f81be Mon Sep 17 00:00:00 2001
+From: Tom Herbert <tom@quantonium.net>
+Date: Wed, 24 Jan 2018 12:35:40 -0800
+Subject: kcm: Only allow TCP sockets to be attached to a KCM mux
+
+From: Tom Herbert <tom@quantonium.net>
+
+commit 581e7226a5d43f629eb6399a121f85f6a15f81be upstream.
+
+TCP sockets for IPv4 and IPv6 that are not listeners or in closed
+stated are allowed to be attached to a KCM mux.
+
+Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module")
+Reported-by: syzbot+8865eaff7f9acd593945@syzkaller.appspotmail.com
+Signed-off-by: Tom Herbert <tom@quantonium.net>
+Reviewed-by: Eric Dumazet <edumazet@google.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/kcm/kcmsock.c |    9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+--- a/net/kcm/kcmsock.c
++++ b/net/kcm/kcmsock.c
+@@ -1381,8 +1381,13 @@ static int kcm_attach(struct socket *soc
+       if (!csk)
+               return -EINVAL;
+-      /* We must prevent loops or risk deadlock ! */
+-      if (csk->sk_family == PF_KCM)
++      /* Only allow TCP sockets to be attached for now */
++      if ((csk->sk_family != AF_INET && csk->sk_family != AF_INET6) ||
++          csk->sk_protocol != IPPROTO_TCP)
++              return -EOPNOTSUPP;
++
++      /* Don't allow listeners or closed sockets */
++      if (csk->sk_state == TCP_LISTEN || csk->sk_state == TCP_CLOSE)
+               return -EOPNOTSUPP;
+       psock = kmem_cache_zalloc(kcm_psockp, GFP_KERNEL);
diff --git a/queue-4.9/kcov-detect-double-association-with-a-single-task.patch b/queue-4.9/kcov-detect-double-association-with-a-single-task.patch
new file mode 100644 (file)
index 0000000..f996c72
--- /dev/null
@@ -0,0 +1,45 @@
+From a77660d231f8b3d84fd23ed482e0964f7aa546d6 Mon Sep 17 00:00:00 2001
+From: Dmitry Vyukov <dvyukov@google.com>
+Date: Tue, 6 Feb 2018 15:40:28 -0800
+Subject: kcov: detect double association with a single task
+
+From: Dmitry Vyukov <dvyukov@google.com>
+
+commit a77660d231f8b3d84fd23ed482e0964f7aa546d6 upstream.
+
+Currently KCOV_ENABLE does not check if the current task is already
+associated with another kcov descriptor.  As the result it is possible
+to associate a single task with more than one kcov descriptor, which
+later leads to a memory leak of the old descriptor.  This relation is
+really meant to be one-to-one (task has only one back link).
+
+Extend validation to detect such misuse.
+
+Link: http://lkml.kernel.org/r/20180122082520.15716-1-dvyukov@google.com
+Fixes: 5c9a8750a640 ("kernel: add kcov code coverage")
+Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
+Reported-by: Shankara Pailoor <sp3485@columbia.edu>
+Cc: Dmitry Vyukov <dvyukov@google.com>
+Cc: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ kernel/kcov.c |    4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/kernel/kcov.c
++++ b/kernel/kcov.c
+@@ -220,9 +220,9 @@ static int kcov_ioctl_locked(struct kcov
+               if (unused != 0 || kcov->mode == KCOV_MODE_DISABLED ||
+                   kcov->area == NULL)
+                       return -EINVAL;
+-              if (kcov->t != NULL)
+-                      return -EBUSY;
+               t = current;
++              if (kcov->t != NULL || t->kcov != NULL)
++                      return -EBUSY;
+               /* Cache in task struct for performance. */
+               t->kcov_size = kcov->size;
+               t->kcov_area = kcov->area;
diff --git a/queue-4.9/kvm-x86-fix-escape-of-guest-dr6-to-the-host.patch b/queue-4.9/kvm-x86-fix-escape-of-guest-dr6-to-the-host.patch
new file mode 100644 (file)
index 0000000..8efcdf1
--- /dev/null
@@ -0,0 +1,68 @@
+From efdab992813fb2ed825745625b83c05032e9cda2 Mon Sep 17 00:00:00 2001
+From: Wanpeng Li <wanpeng.li@hotmail.com>
+Date: Wed, 13 Dec 2017 10:46:40 +0100
+Subject: KVM: x86: fix escape of guest dr6 to the host
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Wanpeng Li <wanpeng.li@hotmail.com>
+
+commit efdab992813fb2ed825745625b83c05032e9cda2 upstream.
+
+syzkaller reported:
+
+   WARNING: CPU: 0 PID: 12927 at arch/x86/kernel/traps.c:780 do_debug+0x222/0x250
+   CPU: 0 PID: 12927 Comm: syz-executor Tainted: G           OE    4.15.0-rc2+ #16
+   RIP: 0010:do_debug+0x222/0x250
+   Call Trace:
+    <#DB>
+    debug+0x3e/0x70
+   RIP: 0010:copy_user_enhanced_fast_string+0x10/0x20
+    </#DB>
+    _copy_from_user+0x5b/0x90
+    SyS_timer_create+0x33/0x80
+    entry_SYSCALL_64_fastpath+0x23/0x9a
+
+The testcase sets a watchpoint (with perf_event_open) on a buffer that is
+passed to timer_create() as the struct sigevent argument.  In timer_create(),
+copy_from_user()'s rep movsb triggers the BP.  The testcase also sets
+the debug registers for the guest.
+
+However, KVM only restores host debug registers when the host has active
+watchpoints, which triggers a race condition when running the testcase with
+multiple threads.  The guest's DR6.BS bit can escape to the host before
+another thread invokes timer_create(), and do_debug() complains.
+
+The fix is to respect do_debug()'s dr6 invariant when leaving KVM.
+
+Reported-by: Dmitry Vyukov <dvyukov@google.com>
+Cc: Paolo Bonzini <pbonzini@redhat.com>
+Cc: Radim Krčmář <rkrcmar@redhat.com>
+Cc: David Hildenbrand <david@redhat.com>
+Cc: Dmitry Vyukov <dvyukov@google.com>
+Reviewed-by: David Hildenbrand <david@redhat.com>
+Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
+Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
+Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/x86/kvm/x86.c |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+--- a/arch/x86/kvm/x86.c
++++ b/arch/x86/kvm/x86.c
+@@ -2847,6 +2847,12 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *
+       kvm_x86_ops->vcpu_put(vcpu);
+       kvm_put_guest_fpu(vcpu);
+       vcpu->arch.last_host_tsc = rdtsc();
++      /*
++       * If userspace has set any breakpoints or watchpoints, dr6 is restored
++       * on every vmexit, but if not, we might have a stale dr6 from the
++       * guest. do_debug expects dr6 to be cleared after it runs, do the same.
++       */
++      set_debugreg(0, 6);
+ }
+ static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu,
diff --git a/queue-4.9/mm-vmscan-make-unregister_shrinker-no-op-if-register_shrinker-failed.patch b/queue-4.9/mm-vmscan-make-unregister_shrinker-no-op-if-register_shrinker-failed.patch
new file mode 100644 (file)
index 0000000..87f8e58
--- /dev/null
@@ -0,0 +1,110 @@
+From bb422a738f6566f7439cd347d54e321e4fe92a9f Mon Sep 17 00:00:00 2001
+From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
+Date: Mon, 18 Dec 2017 20:31:41 +0900
+Subject: mm,vmscan: Make unregister_shrinker() no-op if register_shrinker() failed.
+
+From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
+
+commit bb422a738f6566f7439cd347d54e321e4fe92a9f upstream.
+
+Syzbot caught an oops at unregister_shrinker() because combination of
+commit 1d3d4437eae1bb29 ("vmscan: per-node deferred work") and fault
+injection made register_shrinker() fail and the caller of
+register_shrinker() did not check for failure.
+
+----------
+[  554.881422] FAULT_INJECTION: forcing a failure.
+[  554.881422] name failslab, interval 1, probability 0, space 0, times 0
+[  554.881438] CPU: 1 PID: 13231 Comm: syz-executor1 Not tainted 4.14.0-rc8+ #82
+[  554.881443] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
+[  554.881445] Call Trace:
+[  554.881459]  dump_stack+0x194/0x257
+[  554.881474]  ? arch_local_irq_restore+0x53/0x53
+[  554.881486]  ? find_held_lock+0x35/0x1d0
+[  554.881507]  should_fail+0x8c0/0xa40
+[  554.881522]  ? fault_create_debugfs_attr+0x1f0/0x1f0
+[  554.881537]  ? check_noncircular+0x20/0x20
+[  554.881546]  ? find_next_zero_bit+0x2c/0x40
+[  554.881560]  ? ida_get_new_above+0x421/0x9d0
+[  554.881577]  ? find_held_lock+0x35/0x1d0
+[  554.881594]  ? __lock_is_held+0xb6/0x140
+[  554.881628]  ? check_same_owner+0x320/0x320
+[  554.881634]  ? lock_downgrade+0x990/0x990
+[  554.881649]  ? find_held_lock+0x35/0x1d0
+[  554.881672]  should_failslab+0xec/0x120
+[  554.881684]  __kmalloc+0x63/0x760
+[  554.881692]  ? lock_downgrade+0x990/0x990
+[  554.881712]  ? register_shrinker+0x10e/0x2d0
+[  554.881721]  ? trace_event_raw_event_module_request+0x320/0x320
+[  554.881737]  register_shrinker+0x10e/0x2d0
+[  554.881747]  ? prepare_kswapd_sleep+0x1f0/0x1f0
+[  554.881755]  ? _down_write_nest_lock+0x120/0x120
+[  554.881765]  ? memcpy+0x45/0x50
+[  554.881785]  sget_userns+0xbcd/0xe20
+(...snipped...)
+[  554.898693] kasan: CONFIG_KASAN_INLINE enabled
+[  554.898724] kasan: GPF could be caused by NULL-ptr deref or user memory access
+[  554.898732] general protection fault: 0000 [#1] SMP KASAN
+[  554.898737] Dumping ftrace buffer:
+[  554.898741]    (ftrace buffer empty)
+[  554.898743] Modules linked in:
+[  554.898752] CPU: 1 PID: 13231 Comm: syz-executor1 Not tainted 4.14.0-rc8+ #82
+[  554.898755] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
+[  554.898760] task: ffff8801d1dbe5c0 task.stack: ffff8801c9e38000
+[  554.898772] RIP: 0010:__list_del_entry_valid+0x7e/0x150
+[  554.898775] RSP: 0018:ffff8801c9e3f108 EFLAGS: 00010246
+[  554.898780] RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
+[  554.898784] RDX: 0000000000000000 RSI: ffff8801c53c6f98 RDI: ffff8801c53c6fa0
+[  554.898788] RBP: ffff8801c9e3f120 R08: 1ffff100393c7d55 R09: 0000000000000004
+[  554.898791] R10: ffff8801c9e3ef70 R11: 0000000000000000 R12: 0000000000000000
+[  554.898795] R13: dffffc0000000000 R14: 1ffff100393c7e45 R15: ffff8801c53c6f98
+[  554.898800] FS:  0000000000000000(0000) GS:ffff8801db300000(0000) knlGS:0000000000000000
+[  554.898804] CS:  0010 DS: 002b ES: 002b CR0: 0000000080050033
+[  554.898807] CR2: 00000000dbc23000 CR3: 00000001c7269000 CR4: 00000000001406e0
+[  554.898813] DR0: 0000000020000000 DR1: 0000000020000000 DR2: 0000000000000000
+[  554.898816] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600
+[  554.898818] Call Trace:
+[  554.898828]  unregister_shrinker+0x79/0x300
+[  554.898837]  ? perf_trace_mm_vmscan_writepage+0x750/0x750
+[  554.898844]  ? down_write+0x87/0x120
+[  554.898851]  ? deactivate_super+0x139/0x1b0
+[  554.898857]  ? down_read+0x150/0x150
+[  554.898864]  ? check_same_owner+0x320/0x320
+[  554.898875]  deactivate_locked_super+0x64/0xd0
+[  554.898883]  deactivate_super+0x141/0x1b0
+----------
+
+Since allowing register_shrinker() callers to call unregister_shrinker()
+when register_shrinker() failed can simplify error recovery path, this
+patch makes unregister_shrinker() no-op when register_shrinker() failed.
+Also, reset shrinker->nr_deferred in case unregister_shrinker() was
+by error called twice.
+
+Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
+Signed-off-by: Aliaksei Karaliou <akaraliou.dev@gmail.com>
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Cc: Glauber Costa <glauber@scylladb.com>
+Cc: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/vmscan.c |    3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/mm/vmscan.c
++++ b/mm/vmscan.c
+@@ -295,10 +295,13 @@ EXPORT_SYMBOL(register_shrinker);
+  */
+ void unregister_shrinker(struct shrinker *shrinker)
+ {
++      if (!shrinker->nr_deferred)
++              return;
+       down_write(&shrinker_rwsem);
+       list_del(&shrinker->list);
+       up_write(&shrinker_rwsem);
+       kfree(shrinker->nr_deferred);
++      shrinker->nr_deferred = NULL;
+ }
+ EXPORT_SYMBOL(unregister_shrinker);
diff --git a/queue-4.9/net-avoid-skb_warn_bad_offload-on-is_err.patch b/queue-4.9/net-avoid-skb_warn_bad_offload-on-is_err.patch
new file mode 100644 (file)
index 0000000..d95cbb9
--- /dev/null
@@ -0,0 +1,39 @@
+From 8d74e9f88d65af8bb2e095aff506aa6eac755ada Mon Sep 17 00:00:00 2001
+From: Willem de Bruijn <willemb@google.com>
+Date: Tue, 12 Dec 2017 11:39:04 -0500
+Subject: net: avoid skb_warn_bad_offload on IS_ERR
+
+From: Willem de Bruijn <willemb@google.com>
+
+commit 8d74e9f88d65af8bb2e095aff506aa6eac755ada upstream.
+
+skb_warn_bad_offload warns when packets enter the GSO stack that
+require skb_checksum_help or vice versa. Do not warn on arbitrary
+bad packets. Packet sockets can craft many. Syzkaller was able to
+demonstrate another one with eth_type games.
+
+In particular, suppress the warning when segmentation returns an
+error, which is for reasons other than checksum offload.
+
+See also commit 36c92474498a ("net: WARN if skb_checksum_help() is
+called on skb requiring segmentation") for context on this warning.
+
+Signed-off-by: Willem de Bruijn <willemb@google.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/core/dev.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/net/core/dev.c
++++ b/net/core/dev.c
+@@ -2763,7 +2763,7 @@ struct sk_buff *__skb_gso_segment(struct
+       segs = skb_mac_gso_segment(skb, features);
+-      if (unlikely(skb_needs_check(skb, tx_path)))
++      if (unlikely(skb_needs_check(skb, tx_path) && !IS_ERR(segs)))
+               skb_warn_bad_offload(skb);
+       return segs;
diff --git a/queue-4.9/netfilter-ipt_clusterip-fix-out-of-bounds-accesses-in-clusterip_tg_check.patch b/queue-4.9/netfilter-ipt_clusterip-fix-out-of-bounds-accesses-in-clusterip_tg_check.patch
new file mode 100644 (file)
index 0000000..b114d0f
--- /dev/null
@@ -0,0 +1,59 @@
+From 1a38956cce5eabd7b74f94bab70265e4df83165e Mon Sep 17 00:00:00 2001
+From: Dmitry Vyukov <dvyukov@google.com>
+Date: Tue, 30 Jan 2018 15:21:34 +0100
+Subject: netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check()
+
+From: Dmitry Vyukov <dvyukov@google.com>
+
+commit 1a38956cce5eabd7b74f94bab70265e4df83165e upstream.
+
+Commit 136e92bbec0a switched local_nodes from an array to a bitmask
+but did not add proper bounds checks. As the result
+clusterip_config_init_nodelist() can both over-read
+ipt_clusterip_tgt_info.local_nodes and over-write
+clusterip_config.local_nodes.
+
+Add bounds checks for both.
+
+Fixes: 136e92bbec0a ("[NETFILTER] CLUSTERIP: use a bitmap to store node responsibility data")
+Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/ipv4/netfilter/ipt_CLUSTERIP.c |   16 +++++++++++++---
+ 1 file changed, 13 insertions(+), 3 deletions(-)
+
+--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
++++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
+@@ -365,7 +365,7 @@ static int clusterip_tg_check(const stru
+       struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
+       const struct ipt_entry *e = par->entryinfo;
+       struct clusterip_config *config;
+-      int ret;
++      int ret, i;
+       if (par->nft_compat) {
+               pr_err("cannot use CLUSTERIP target from nftables compat\n");
+@@ -384,8 +384,18 @@ static int clusterip_tg_check(const stru
+               pr_info("Please specify destination IP\n");
+               return -EINVAL;
+       }
+-
+-      /* FIXME: further sanity checks */
++      if (cipinfo->num_local_nodes > ARRAY_SIZE(cipinfo->local_nodes)) {
++              pr_info("bad num_local_nodes %u\n", cipinfo->num_local_nodes);
++              return -EINVAL;
++      }
++      for (i = 0; i < cipinfo->num_local_nodes; i++) {
++              if (cipinfo->local_nodes[i] - 1 >=
++                  sizeof(config->local_nodes) * 8) {
++                      pr_info("bad local_nodes[%d] %u\n",
++                              i, cipinfo->local_nodes[i]);
++                      return -EINVAL;
++              }
++      }
+       config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1);
+       if (!config) {
diff --git a/queue-4.9/netfilter-on-sockopt-acquire-sock-lock-only-in-the-required-scope.patch b/queue-4.9/netfilter-on-sockopt-acquire-sock-lock-only-in-the-required-scope.patch
new file mode 100644 (file)
index 0000000..ec92173
--- /dev/null
@@ -0,0 +1,242 @@
+From 3f34cfae1238848fd53f25e5c8fd59da57901f4b Mon Sep 17 00:00:00 2001
+From: Paolo Abeni <pabeni@redhat.com>
+Date: Tue, 30 Jan 2018 19:01:40 +0100
+Subject: netfilter: on sockopt() acquire sock lock only in the required scope
+
+From: Paolo Abeni <pabeni@redhat.com>
+
+commit 3f34cfae1238848fd53f25e5c8fd59da57901f4b upstream.
+
+Syzbot reported several deadlocks in the netfilter area caused by
+rtnl lock and socket lock being acquired with a different order on
+different code paths, leading to backtraces like the following one:
+
+======================================================
+WARNING: possible circular locking dependency detected
+4.15.0-rc9+ #212 Not tainted
+------------------------------------------------------
+syzkaller041579/3682 is trying to acquire lock:
+  (sk_lock-AF_INET6){+.+.}, at: [<000000008775e4dd>] lock_sock
+include/net/sock.h:1463 [inline]
+  (sk_lock-AF_INET6){+.+.}, at: [<000000008775e4dd>]
+do_ipv6_setsockopt.isra.8+0x3c5/0x39d0 net/ipv6/ipv6_sockglue.c:167
+
+but task is already holding lock:
+  (rtnl_mutex){+.+.}, at: [<000000004342eaa9>] rtnl_lock+0x17/0x20
+net/core/rtnetlink.c:74
+
+which lock already depends on the new lock.
+
+the existing dependency chain (in reverse order) is:
+
+-> #1 (rtnl_mutex){+.+.}:
+        __mutex_lock_common kernel/locking/mutex.c:756 [inline]
+        __mutex_lock+0x16f/0x1a80 kernel/locking/mutex.c:893
+        mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:908
+        rtnl_lock+0x17/0x20 net/core/rtnetlink.c:74
+        register_netdevice_notifier+0xad/0x860 net/core/dev.c:1607
+        tee_tg_check+0x1a0/0x280 net/netfilter/xt_TEE.c:106
+        xt_check_target+0x22c/0x7d0 net/netfilter/x_tables.c:845
+        check_target net/ipv6/netfilter/ip6_tables.c:538 [inline]
+        find_check_entry.isra.7+0x935/0xcf0
+net/ipv6/netfilter/ip6_tables.c:580
+        translate_table+0xf52/0x1690 net/ipv6/netfilter/ip6_tables.c:749
+        do_replace net/ipv6/netfilter/ip6_tables.c:1165 [inline]
+        do_ip6t_set_ctl+0x370/0x5f0 net/ipv6/netfilter/ip6_tables.c:1691
+        nf_sockopt net/netfilter/nf_sockopt.c:106 [inline]
+        nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:115
+        ipv6_setsockopt+0x115/0x150 net/ipv6/ipv6_sockglue.c:928
+        udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
+        sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2978
+        SYSC_setsockopt net/socket.c:1849 [inline]
+        SyS_setsockopt+0x189/0x360 net/socket.c:1828
+        entry_SYSCALL_64_fastpath+0x29/0xa0
+
+-> #0 (sk_lock-AF_INET6){+.+.}:
+        lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:3914
+        lock_sock_nested+0xc2/0x110 net/core/sock.c:2780
+        lock_sock include/net/sock.h:1463 [inline]
+        do_ipv6_setsockopt.isra.8+0x3c5/0x39d0 net/ipv6/ipv6_sockglue.c:167
+        ipv6_setsockopt+0xd7/0x150 net/ipv6/ipv6_sockglue.c:922
+        udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
+        sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2978
+        SYSC_setsockopt net/socket.c:1849 [inline]
+        SyS_setsockopt+0x189/0x360 net/socket.c:1828
+        entry_SYSCALL_64_fastpath+0x29/0xa0
+
+other info that might help us debug this:
+
+  Possible unsafe locking scenario:
+
+        CPU0                    CPU1
+        ----                    ----
+   lock(rtnl_mutex);
+                                lock(sk_lock-AF_INET6);
+                                lock(rtnl_mutex);
+   lock(sk_lock-AF_INET6);
+
+  *** DEADLOCK ***
+
+1 lock held by syzkaller041579/3682:
+  #0:  (rtnl_mutex){+.+.}, at: [<000000004342eaa9>] rtnl_lock+0x17/0x20
+net/core/rtnetlink.c:74
+
+The problem, as Florian noted, is that nf_setsockopt() is always
+called with the socket held, even if the lock itself is required only
+for very tight scopes and only for some operation.
+
+This patch addresses the issues moving the lock_sock() call only
+where really needed, namely in ipv*_getorigdst(), so that nf_setsockopt()
+does not need anymore to acquire both locks.
+
+Fixes: 22265a5c3c10 ("netfilter: xt_TEE: resolve oif using netdevice notifiers")
+Reported-by: syzbot+a4c2dc980ac1af699b36@syzkaller.appspotmail.com
+Suggested-by: Florian Westphal <fw@strlen.de>
+Signed-off-by: Paolo Abeni <pabeni@redhat.com>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/ipv4/ip_sockglue.c                         |   14 ++++----------
+ net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |    6 +++++-
+ net/ipv6/ipv6_sockglue.c                       |   17 +++++------------
+ net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c |   18 ++++++++++++------
+ 4 files changed, 26 insertions(+), 29 deletions(-)
+
+--- a/net/ipv4/ip_sockglue.c
++++ b/net/ipv4/ip_sockglue.c
+@@ -1243,11 +1243,8 @@ int ip_setsockopt(struct sock *sk, int l
+       if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
+                       optname != IP_IPSEC_POLICY &&
+                       optname != IP_XFRM_POLICY &&
+-                      !ip_mroute_opt(optname)) {
+-              lock_sock(sk);
++                      !ip_mroute_opt(optname))
+               err = nf_setsockopt(sk, PF_INET, optname, optval, optlen);
+-              release_sock(sk);
+-      }
+ #endif
+       return err;
+ }
+@@ -1272,12 +1269,9 @@ int compat_ip_setsockopt(struct sock *sk
+       if (err == -ENOPROTOOPT && optname != IP_HDRINCL &&
+                       optname != IP_IPSEC_POLICY &&
+                       optname != IP_XFRM_POLICY &&
+-                      !ip_mroute_opt(optname)) {
+-              lock_sock(sk);
+-              err = compat_nf_setsockopt(sk, PF_INET, optname,
+-                                         optval, optlen);
+-              release_sock(sk);
+-      }
++                      !ip_mroute_opt(optname))
++              err = compat_nf_setsockopt(sk, PF_INET, optname, optval,
++                                         optlen);
+ #endif
+       return err;
+ }
+--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
++++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+@@ -218,15 +218,19 @@ getorigdst(struct sock *sk, int optval,
+       struct nf_conntrack_tuple tuple;
+       memset(&tuple, 0, sizeof(tuple));
++
++      lock_sock(sk);
+       tuple.src.u3.ip = inet->inet_rcv_saddr;
+       tuple.src.u.tcp.port = inet->inet_sport;
+       tuple.dst.u3.ip = inet->inet_daddr;
+       tuple.dst.u.tcp.port = inet->inet_dport;
+       tuple.src.l3num = PF_INET;
+       tuple.dst.protonum = sk->sk_protocol;
++      release_sock(sk);
+       /* We only do TCP and SCTP at the moment: is there a better way? */
+-      if (sk->sk_protocol != IPPROTO_TCP && sk->sk_protocol != IPPROTO_SCTP) {
++      if (tuple.dst.protonum != IPPROTO_TCP &&
++          tuple.dst.protonum != IPPROTO_SCTP) {
+               pr_debug("SO_ORIGINAL_DST: Not a TCP/SCTP socket\n");
+               return -ENOPROTOOPT;
+       }
+--- a/net/ipv6/ipv6_sockglue.c
++++ b/net/ipv6/ipv6_sockglue.c
+@@ -907,12 +907,8 @@ int ipv6_setsockopt(struct sock *sk, int
+ #ifdef CONFIG_NETFILTER
+       /* we need to exclude all possible ENOPROTOOPTs except default case */
+       if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
+-                      optname != IPV6_XFRM_POLICY) {
+-              lock_sock(sk);
+-              err = nf_setsockopt(sk, PF_INET6, optname, optval,
+-                              optlen);
+-              release_sock(sk);
+-      }
++                      optname != IPV6_XFRM_POLICY)
++              err = nf_setsockopt(sk, PF_INET6, optname, optval, optlen);
+ #endif
+       return err;
+ }
+@@ -942,12 +938,9 @@ int compat_ipv6_setsockopt(struct sock *
+ #ifdef CONFIG_NETFILTER
+       /* we need to exclude all possible ENOPROTOOPTs except default case */
+       if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
+-          optname != IPV6_XFRM_POLICY) {
+-              lock_sock(sk);
+-              err = compat_nf_setsockopt(sk, PF_INET6, optname,
+-                                         optval, optlen);
+-              release_sock(sk);
+-      }
++          optname != IPV6_XFRM_POLICY)
++              err = compat_nf_setsockopt(sk, PF_INET6, optname, optval,
++                                         optlen);
+ #endif
+       return err;
+ }
+--- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
++++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
+@@ -226,20 +226,27 @@ static struct nf_hook_ops ipv6_conntrack
+ static int
+ ipv6_getorigdst(struct sock *sk, int optval, void __user *user, int *len)
+ {
+-      const struct inet_sock *inet = inet_sk(sk);
++      struct nf_conntrack_tuple tuple = { .src.l3num = NFPROTO_IPV6 };
+       const struct ipv6_pinfo *inet6 = inet6_sk(sk);
++      const struct inet_sock *inet = inet_sk(sk);
+       const struct nf_conntrack_tuple_hash *h;
+       struct sockaddr_in6 sin6;
+-      struct nf_conntrack_tuple tuple = { .src.l3num = NFPROTO_IPV6 };
+       struct nf_conn *ct;
++      __be32 flow_label;
++      int bound_dev_if;
++      lock_sock(sk);
+       tuple.src.u3.in6 = sk->sk_v6_rcv_saddr;
+       tuple.src.u.tcp.port = inet->inet_sport;
+       tuple.dst.u3.in6 = sk->sk_v6_daddr;
+       tuple.dst.u.tcp.port = inet->inet_dport;
+       tuple.dst.protonum = sk->sk_protocol;
++      bound_dev_if = sk->sk_bound_dev_if;
++      flow_label = inet6->flow_label;
++      release_sock(sk);
+-      if (sk->sk_protocol != IPPROTO_TCP && sk->sk_protocol != IPPROTO_SCTP)
++      if (tuple.dst.protonum != IPPROTO_TCP &&
++          tuple.dst.protonum != IPPROTO_SCTP)
+               return -ENOPROTOOPT;
+       if (*len < 0 || (unsigned int) *len < sizeof(sin6))
+@@ -257,14 +264,13 @@ ipv6_getorigdst(struct sock *sk, int opt
+       sin6.sin6_family = AF_INET6;
+       sin6.sin6_port = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.tcp.port;
+-      sin6.sin6_flowinfo = inet6->flow_label & IPV6_FLOWINFO_MASK;
++      sin6.sin6_flowinfo = flow_label & IPV6_FLOWINFO_MASK;
+       memcpy(&sin6.sin6_addr,
+               &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.in6,
+                                       sizeof(sin6.sin6_addr));
+       nf_ct_put(ct);
+-      sin6.sin6_scope_id = ipv6_iface_scope_id(&sin6.sin6_addr,
+-                                               sk->sk_bound_dev_if);
++      sin6.sin6_scope_id = ipv6_iface_scope_id(&sin6.sin6_addr, bound_dev_if);
+       return copy_to_user(user, &sin6, sizeof(sin6)) ? -EFAULT : 0;
+ }
diff --git a/queue-4.9/netfilter-x_tables-avoid-out-of-bounds-reads-in-xt_request_find_-match-target.patch b/queue-4.9/netfilter-x_tables-avoid-out-of-bounds-reads-in-xt_request_find_-match-target.patch
new file mode 100644 (file)
index 0000000..e5c5e6a
--- /dev/null
@@ -0,0 +1,51 @@
+From da17c73b6eb74aad3c3c0654394635675b623b3e Mon Sep 17 00:00:00 2001
+From: Eric Dumazet <edumazet@google.com>
+Date: Wed, 24 Jan 2018 17:16:09 -0800
+Subject: netfilter: x_tables: avoid out-of-bounds reads in xt_request_find_{match|target}
+
+From: Eric Dumazet <edumazet@google.com>
+
+commit da17c73b6eb74aad3c3c0654394635675b623b3e upstream.
+
+It looks like syzbot found its way into netfilter territory.
+
+Issue here is that @name comes from user space and might
+not be null terminated.
+
+Out-of-bound reads happen, KASAN is not happy.
+
+v2 added similar fix for xt_request_find_target(),
+as Florian advised.
+
+Signed-off-by: Eric Dumazet <edumazet@google.com>
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Acked-by: Florian Westphal <fw@strlen.de>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/netfilter/x_tables.c |    6 ++++++
+ 1 file changed, 6 insertions(+)
+
+--- a/net/netfilter/x_tables.c
++++ b/net/netfilter/x_tables.c
+@@ -207,6 +207,9 @@ xt_request_find_match(uint8_t nfproto, c
+ {
+       struct xt_match *match;
++      if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)
++              return ERR_PTR(-EINVAL);
++
+       match = xt_find_match(nfproto, name, revision);
+       if (IS_ERR(match)) {
+               request_module("%st_%s", xt_prefix[nfproto], name);
+@@ -249,6 +252,9 @@ struct xt_target *xt_request_find_target
+ {
+       struct xt_target *target;
++      if (strnlen(name, XT_EXTENSION_MAXNAMELEN) == XT_EXTENSION_MAXNAMELEN)
++              return ERR_PTR(-EINVAL);
++
+       target = xt_find_target(af, name, revision);
+       if (IS_ERR(target)) {
+               request_module("%st_%s", xt_prefix[af], name);
diff --git a/queue-4.9/netfilter-x_tables-fix-int-overflow-in-xt_alloc_table_info.patch b/queue-4.9/netfilter-x_tables-fix-int-overflow-in-xt_alloc_table_info.patch
new file mode 100644 (file)
index 0000000..572ca7a
--- /dev/null
@@ -0,0 +1,45 @@
+From 889c604fd0b5f6d3b8694ade229ee44124de1127 Mon Sep 17 00:00:00 2001
+From: Dmitry Vyukov <dvyukov@google.com>
+Date: Thu, 28 Dec 2017 09:48:54 +0100
+Subject: netfilter: x_tables: fix int overflow in xt_alloc_table_info()
+
+From: Dmitry Vyukov <dvyukov@google.com>
+
+commit 889c604fd0b5f6d3b8694ade229ee44124de1127 upstream.
+
+syzkaller triggered OOM kills by passing ipt_replace.size = -1
+to IPT_SO_SET_REPLACE. The root cause is that SMP_ALIGN() in
+xt_alloc_table_info() causes int overflow and the size check passes
+when it should not. SMP_ALIGN() is no longer needed leftover.
+
+Remove SMP_ALIGN() call in xt_alloc_table_info().
+
+Reported-by: syzbot+4396883fa8c4f64e0175@syzkaller.appspotmail.com
+Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/netfilter/x_tables.c |    4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+--- a/net/netfilter/x_tables.c
++++ b/net/netfilter/x_tables.c
+@@ -39,8 +39,6 @@ MODULE_LICENSE("GPL");
+ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
+ MODULE_DESCRIPTION("{ip,ip6,arp,eb}_tables backend module");
+-#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
+-
+ struct compat_delta {
+       unsigned int offset; /* offset in kernel */
+       int delta; /* delta in 32bit user land */
+@@ -952,7 +950,7 @@ struct xt_table_info *xt_alloc_table_inf
+               return NULL;
+       /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
+-      if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
++      if ((size >> PAGE_SHIFT) + 2 > totalram_pages)
+               return NULL;
+       if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
diff --git a/queue-4.9/netfilter-xt_cgroup-initialize-info-priv-in-cgroup_mt_check_v1.patch b/queue-4.9/netfilter-xt_cgroup-initialize-info-priv-in-cgroup_mt_check_v1.patch
new file mode 100644 (file)
index 0000000..c698ca5
--- /dev/null
@@ -0,0 +1,33 @@
+From ba7cd5d95f25cc6005f687dabdb4e7a6063adda9 Mon Sep 17 00:00:00 2001
+From: Cong Wang <xiyou.wangcong@gmail.com>
+Date: Wed, 31 Jan 2018 15:02:47 -0800
+Subject: netfilter: xt_cgroup: initialize info->priv in cgroup_mt_check_v1()
+
+From: Cong Wang <xiyou.wangcong@gmail.com>
+
+commit ba7cd5d95f25cc6005f687dabdb4e7a6063adda9 upstream.
+
+xt_cgroup_info_v1->priv is an internal pointer only used for kernel,
+we should not trust what user-space provides.
+
+Reported-by: <syzbot+4fbcfcc0d2e6592bd641@syzkaller.appspotmail.com>
+Fixes: c38c4597e4bf ("netfilter: implement xt_cgroup cgroup2 path match")
+Cc: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/netfilter/xt_cgroup.c |    1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/net/netfilter/xt_cgroup.c
++++ b/net/netfilter/xt_cgroup.c
+@@ -52,6 +52,7 @@ static int cgroup_mt_check_v1(const stru
+               return -EINVAL;
+       }
++      info->priv = NULL;
+       if (info->has_path) {
+               cgrp = cgroup_get_from_path(info->path);
+               if (IS_ERR(cgrp)) {
diff --git a/queue-4.9/netfilter-xt_rateest-acquire-xt_rateest_mutex-for-hash-insert.patch b/queue-4.9/netfilter-xt_rateest-acquire-xt_rateest_mutex-for-hash-insert.patch
new file mode 100644 (file)
index 0000000..3c8e2da
--- /dev/null
@@ -0,0 +1,92 @@
+From 7dc68e98757a8eccf8ca7a53a29b896f1eef1f76 Mon Sep 17 00:00:00 2001
+From: Cong Wang <xiyou.wangcong@gmail.com>
+Date: Mon, 5 Feb 2018 14:41:45 -0800
+Subject: netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert
+
+From: Cong Wang <xiyou.wangcong@gmail.com>
+
+commit 7dc68e98757a8eccf8ca7a53a29b896f1eef1f76 upstream.
+
+rateest_hash is supposed to be protected by xt_rateest_mutex,
+and, as suggested by Eric, lookup and insert should be atomic,
+so we should acquire the xt_rateest_mutex once for both.
+
+So introduce a non-locking helper for internal use and keep the
+locking one for external.
+
+Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
+Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
+Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
+Reviewed-by: Florian Westphal <fw@strlen.de>
+Reviewed-by: Eric Dumazet <edumazet@google.com>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/netfilter/xt_RATEEST.c |   22 +++++++++++++++++-----
+ 1 file changed, 17 insertions(+), 5 deletions(-)
+
+--- a/net/netfilter/xt_RATEEST.c
++++ b/net/netfilter/xt_RATEEST.c
+@@ -39,23 +39,31 @@ static void xt_rateest_hash_insert(struc
+       hlist_add_head(&est->list, &rateest_hash[h]);
+ }
+-struct xt_rateest *xt_rateest_lookup(const char *name)
++static struct xt_rateest *__xt_rateest_lookup(const char *name)
+ {
+       struct xt_rateest *est;
+       unsigned int h;
+       h = xt_rateest_hash(name);
+-      mutex_lock(&xt_rateest_mutex);
+       hlist_for_each_entry(est, &rateest_hash[h], list) {
+               if (strcmp(est->name, name) == 0) {
+                       est->refcnt++;
+-                      mutex_unlock(&xt_rateest_mutex);
+                       return est;
+               }
+       }
+-      mutex_unlock(&xt_rateest_mutex);
++
+       return NULL;
+ }
++
++struct xt_rateest *xt_rateest_lookup(const char *name)
++{
++      struct xt_rateest *est;
++
++      mutex_lock(&xt_rateest_mutex);
++      est = __xt_rateest_lookup(name);
++      mutex_unlock(&xt_rateest_mutex);
++      return est;
++}
+ EXPORT_SYMBOL_GPL(xt_rateest_lookup);
+ void xt_rateest_put(struct xt_rateest *est)
+@@ -100,8 +108,10 @@ static int xt_rateest_tg_checkentry(cons
+       net_get_random_once(&jhash_rnd, sizeof(jhash_rnd));
+-      est = xt_rateest_lookup(info->name);
++      mutex_lock(&xt_rateest_mutex);
++      est = __xt_rateest_lookup(info->name);
+       if (est) {
++              mutex_unlock(&xt_rateest_mutex);
+               /*
+                * If estimator parameters are specified, they must match the
+                * existing estimator.
+@@ -139,11 +149,13 @@ static int xt_rateest_tg_checkentry(cons
+       info->est = est;
+       xt_rateest_hash_insert(est);
++      mutex_unlock(&xt_rateest_mutex);
+       return 0;
+ err2:
+       kfree(est);
+ err1:
++      mutex_unlock(&xt_rateest_mutex);
+       return ret;
+ }
diff --git a/queue-4.9/provide-a-function-to-create-a-nul-terminated-string-from-unterminated-data.patch b/queue-4.9/provide-a-function-to-create-a-nul-terminated-string-from-unterminated-data.patch
new file mode 100644 (file)
index 0000000..4422644
--- /dev/null
@@ -0,0 +1,74 @@
+From f35157417215ec138c920320c746fdb3e04ef1d5 Mon Sep 17 00:00:00 2001
+From: David Howells <dhowells@redhat.com>
+Date: Tue, 4 Jul 2017 17:25:02 +0100
+Subject: Provide a function to create a NUL-terminated string from unterminated data
+
+From: David Howells <dhowells@redhat.com>
+
+commit f35157417215ec138c920320c746fdb3e04ef1d5 upstream.
+
+Provide a function, kmemdup_nul(), that will create a NUL-terminated string
+from an unterminated character array where the length is known in advance.
+
+This is better than kstrndup() in situations where we already know the
+string length as the strnlen() in kstrndup() is superfluous.
+
+Signed-off-by: David Howells <dhowells@redhat.com>
+Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/linux/string.h |    1 +
+ mm/util.c              |   24 ++++++++++++++++++++++++
+ 2 files changed, 25 insertions(+)
+
+--- a/include/linux/string.h
++++ b/include/linux/string.h
+@@ -123,6 +123,7 @@ extern char *kstrdup(const char *s, gfp_
+ extern const char *kstrdup_const(const char *s, gfp_t gfp);
+ extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+ extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
++extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
+ extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
+ extern void argv_free(char **argv);
+--- a/mm/util.c
++++ b/mm/util.c
+@@ -80,6 +80,8 @@ EXPORT_SYMBOL(kstrdup_const);
+  * @s: the string to duplicate
+  * @max: read at most @max chars from @s
+  * @gfp: the GFP mask used in the kmalloc() call when allocating memory
++ *
++ * Note: Use kmemdup_nul() instead if the size is known exactly.
+  */
+ char *kstrndup(const char *s, size_t max, gfp_t gfp)
+ {
+@@ -118,6 +120,28 @@ void *kmemdup(const void *src, size_t le
+ EXPORT_SYMBOL(kmemdup);
+ /**
++ * kmemdup_nul - Create a NUL-terminated string from unterminated data
++ * @s: The data to stringify
++ * @len: The size of the data
++ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
++ */
++char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
++{
++      char *buf;
++
++      if (!s)
++              return NULL;
++
++      buf = kmalloc_track_caller(len + 1, gfp);
++      if (buf) {
++              memcpy(buf, s, len);
++              buf[len] = '\0';
++      }
++      return buf;
++}
++EXPORT_SYMBOL(kmemdup_nul);
++
++/**
+  * memdup_user - duplicate memory region from user space
+  *
+  * @src: source address in user space
diff --git a/queue-4.9/ptr_ring-fail-early-if-queue-occupies-more-than-kmalloc_max_size.patch b/queue-4.9/ptr_ring-fail-early-if-queue-occupies-more-than-kmalloc_max_size.patch
new file mode 100644 (file)
index 0000000..6016e77
--- /dev/null
@@ -0,0 +1,34 @@
+From 6e6e41c3112276288ccaf80c70916779b84bb276 Mon Sep 17 00:00:00 2001
+From: Jason Wang <jasowang@redhat.com>
+Date: Fri, 9 Feb 2018 17:45:49 +0800
+Subject: ptr_ring: fail early if queue occupies more than KMALLOC_MAX_SIZE
+
+From: Jason Wang <jasowang@redhat.com>
+
+commit 6e6e41c3112276288ccaf80c70916779b84bb276 upstream.
+
+To avoid slab to warn about exceeded size, fail early if queue
+occupies more than KMALLOC_MAX_SIZE.
+
+Reported-by: syzbot+e4d4f9ddd4295539735d@syzkaller.appspotmail.com
+Fixes: 2e0ab8ca83c12 ("ptr_ring: array based FIFO for pointers")
+Signed-off-by: Jason Wang <jasowang@redhat.com>
+Acked-by: Michael S. Tsirkin <mst@redhat.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/linux/ptr_ring.h |    2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/include/linux/ptr_ring.h
++++ b/include/linux/ptr_ring.h
+@@ -351,6 +351,8 @@ static inline void *ptr_ring_consume_bh(
+ static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp)
+ {
++      if (size * sizeof(void *) > KMALLOC_MAX_SIZE)
++              return NULL;
+       return kcalloc(size, sizeof(void *), gfp);
+ }
diff --git a/queue-4.9/rds-tcp-atomically-purge-entries-from-rds_tcp_conn_list-during-netns-delete.patch b/queue-4.9/rds-tcp-atomically-purge-entries-from-rds_tcp_conn_list-during-netns-delete.patch
new file mode 100644 (file)
index 0000000..bbf7626
--- /dev/null
@@ -0,0 +1,71 @@
+From f10b4cff98c6977668434fbf5dd58695eeca2897 Mon Sep 17 00:00:00 2001
+From: Sowmini Varadhan <sowmini.varadhan@oracle.com>
+Date: Thu, 30 Nov 2017 11:11:29 -0800
+Subject: rds: tcp: atomically purge entries from rds_tcp_conn_list during netns delete
+
+From: Sowmini Varadhan <sowmini.varadhan@oracle.com>
+
+commit f10b4cff98c6977668434fbf5dd58695eeca2897 upstream.
+
+The rds_tcp_kill_sock() function parses the rds_tcp_conn_list
+to find the rds_connection entries marked for deletion as part
+of the netns deletion under the protection of the rds_tcp_conn_lock.
+Since the rds_tcp_conn_list tracks rds_tcp_connections (which
+have a 1:1 mapping with rds_conn_path), multiple tc entries in
+the rds_tcp_conn_list will map to a single rds_connection, and will
+be deleted as part of the rds_conn_destroy() operation that is
+done outside the rds_tcp_conn_lock.
+
+The rds_tcp_conn_list traversal done under the protection of
+rds_tcp_conn_lock should not leave any doomed tc entries in
+the list after the rds_tcp_conn_lock is released, else another
+concurrently executiong netns delete (for a differnt netns) thread
+may trip on these entries.
+
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
+Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/rds/tcp.c |    9 +++++++--
+ net/rds/tcp.h |    1 +
+ 2 files changed, 8 insertions(+), 2 deletions(-)
+
+--- a/net/rds/tcp.c
++++ b/net/rds/tcp.c
+@@ -303,7 +303,8 @@ static void rds_tcp_conn_free(void *arg)
+       rdsdebug("freeing tc %p\n", tc);
+       spin_lock_irqsave(&rds_tcp_conn_lock, flags);
+-      list_del(&tc->t_tcp_node);
++      if (!tc->t_tcp_node_detached)
++              list_del(&tc->t_tcp_node);
+       spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
+       kmem_cache_free(rds_tcp_conn_slab, tc);
+@@ -528,8 +529,12 @@ static void rds_tcp_kill_sock(struct net
+               if (net != c_net || !tc->t_sock)
+                       continue;
+-              if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
++              if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) {
+                       list_move_tail(&tc->t_tcp_node, &tmp_list);
++              } else {
++                      list_del(&tc->t_tcp_node);
++                      tc->t_tcp_node_detached = true;
++              }
+       }
+       spin_unlock_irq(&rds_tcp_conn_lock);
+       list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node) {
+--- a/net/rds/tcp.h
++++ b/net/rds/tcp.h
+@@ -11,6 +11,7 @@ struct rds_tcp_incoming {
+ struct rds_tcp_connection {
+       struct list_head        t_tcp_node;
++      bool                    t_tcp_node_detached;
+       struct rds_conn_path    *t_cpath;
+       /* t_conn_path_lock synchronizes the connection establishment between
+        * rds_tcp_accept_one and rds_tcp_conn_path_connect
diff --git a/queue-4.9/sctp-set-frag_point-in-sctp_setsockopt_maxseg-correctly.patch b/queue-4.9/sctp-set-frag_point-in-sctp_setsockopt_maxseg-correctly.patch
new file mode 100644 (file)
index 0000000..88aa8d0
--- /dev/null
@@ -0,0 +1,112 @@
+From ecca8f88da5c4260cc2bccfefd2a24976704c366 Mon Sep 17 00:00:00 2001
+From: Xin Long <lucien.xin@gmail.com>
+Date: Fri, 17 Nov 2017 14:11:11 +0800
+Subject: sctp: set frag_point in sctp_setsockopt_maxseg correctly
+
+From: Xin Long <lucien.xin@gmail.com>
+
+commit ecca8f88da5c4260cc2bccfefd2a24976704c366 upstream.
+
+Now in sctp_setsockopt_maxseg user_frag or frag_point can be set with
+val >= 8 and val <= SCTP_MAX_CHUNK_LEN. But both checks are incorrect.
+
+val >= 8 means frag_point can even be less than SCTP_DEFAULT_MINSEGMENT.
+Then in sctp_datamsg_from_user(), when it's value is greater than cookie
+echo len and trying to bundle with cookie echo chunk, the first_len will
+overflow.
+
+The worse case is when it's value is equal as cookie echo len, first_len
+becomes 0, it will go into a dead loop for fragment later on. In Hangbin
+syzkaller testing env, oom was even triggered due to consecutive memory
+allocation in that loop.
+
+Besides, SCTP_MAX_CHUNK_LEN is the max size of the whole chunk, it should
+deduct the data header for frag_point or user_frag check.
+
+This patch does a proper check with SCTP_DEFAULT_MINSEGMENT subtracting
+the sctphdr and datahdr, SCTP_MAX_CHUNK_LEN subtracting datahdr when
+setting frag_point via sockopt. It also improves sctp_setsockopt_maxseg
+codes.
+
+Suggested-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
+Reported-by: Hangbin Liu <liuhangbin@gmail.com>
+Signed-off-by: Xin Long <lucien.xin@gmail.com>
+Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/net/sctp/sctp.h |    3 ++-
+ net/sctp/socket.c       |   29 +++++++++++++++++++----------
+ 2 files changed, 21 insertions(+), 11 deletions(-)
+
+--- a/include/net/sctp/sctp.h
++++ b/include/net/sctp/sctp.h
+@@ -433,7 +433,8 @@ static inline int sctp_frag_point(const
+       if (asoc->user_frag)
+               frag = min_t(int, frag, asoc->user_frag);
+-      frag = SCTP_TRUNC4(min_t(int, frag, SCTP_MAX_CHUNK_LEN));
++      frag = SCTP_TRUNC4(min_t(int, frag, SCTP_MAX_CHUNK_LEN -
++                                          sizeof(struct sctp_data_chunk)));
+       return frag;
+ }
+--- a/net/sctp/socket.c
++++ b/net/sctp/socket.c
+@@ -3125,9 +3125,9 @@ static int sctp_setsockopt_mappedv4(stru
+  */
+ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen)
+ {
++      struct sctp_sock *sp = sctp_sk(sk);
+       struct sctp_assoc_value params;
+       struct sctp_association *asoc;
+-      struct sctp_sock *sp = sctp_sk(sk);
+       int val;
+       if (optlen == sizeof(int)) {
+@@ -3143,26 +3143,35 @@ static int sctp_setsockopt_maxseg(struct
+               if (copy_from_user(&params, optval, optlen))
+                       return -EFAULT;
+               val = params.assoc_value;
+-      } else
++      } else {
+               return -EINVAL;
++      }
+-      if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN)))
+-              return -EINVAL;
++      if (val) {
++              int min_len, max_len;
+-      asoc = sctp_id2assoc(sk, params.assoc_id);
+-      if (!asoc && params.assoc_id && sctp_style(sk, UDP))
+-              return -EINVAL;
++              min_len = SCTP_DEFAULT_MINSEGMENT - sp->pf->af->net_header_len;
++              min_len -= sizeof(struct sctphdr) +
++                         sizeof(struct sctp_data_chunk);
++
++              max_len = SCTP_MAX_CHUNK_LEN - sizeof(struct sctp_data_chunk);
++              if (val < min_len || val > max_len)
++                      return -EINVAL;
++      }
++
++      asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (asoc) {
+               if (val == 0) {
+-                      val = asoc->pathmtu;
+-                      val -= sp->pf->af->net_header_len;
++                      val = asoc->pathmtu - sp->pf->af->net_header_len;
+                       val -= sizeof(struct sctphdr) +
+-                                      sizeof(struct sctp_data_chunk);
++                             sizeof(struct sctp_data_chunk);
+               }
+               asoc->user_frag = val;
+               asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu);
+       } else {
++              if (params.assoc_id && sctp_style(sk, UDP))
++                      return -EINVAL;
+               sp->user_frag = val;
+       }
diff --git a/queue-4.9/selinux-ensure-the-context-is-nul-terminated-in-security_context_to_sid_core.patch b/queue-4.9/selinux-ensure-the-context-is-nul-terminated-in-security_context_to_sid_core.patch
new file mode 100644 (file)
index 0000000..92fef5f
--- /dev/null
@@ -0,0 +1,67 @@
+From ef28df55ac27e1e5cd122e19fa311d886d47a756 Mon Sep 17 00:00:00 2001
+From: Paul Moore <paul@paul-moore.com>
+Date: Tue, 28 Nov 2017 18:51:12 -0500
+Subject: selinux: ensure the context is NUL terminated in security_context_to_sid_core()
+
+From: Paul Moore <paul@paul-moore.com>
+
+commit ef28df55ac27e1e5cd122e19fa311d886d47a756 upstream.
+
+The syzbot/syzkaller automated tests found a problem in
+security_context_to_sid_core() during early boot (before we load the
+SELinux policy) where we could potentially feed context strings without
+NUL terminators into the strcmp() function.
+
+We already guard against this during normal operation (after the SELinux
+policy has been loaded) by making a copy of the context strings and
+explicitly adding a NUL terminator to the end.  The patch extends this
+protection to the early boot case (no loaded policy) by moving the context
+copy earlier in security_context_to_sid_core().
+
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Paul Moore <paul@paul-moore.com>
+Reviewed-By: William Roberts <william.c.roberts@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ security/selinux/ss/services.c |   18 ++++++++----------
+ 1 file changed, 8 insertions(+), 10 deletions(-)
+
+--- a/security/selinux/ss/services.c
++++ b/security/selinux/ss/services.c
+@@ -1400,27 +1400,25 @@ static int security_context_to_sid_core(
+       if (!scontext_len)
+               return -EINVAL;
++      /* Copy the string to allow changes and ensure a NUL terminator */
++      scontext2 = kmemdup_nul(scontext, scontext_len, gfp_flags);
++      if (!scontext2)
++              return -ENOMEM;
++
+       if (!ss_initialized) {
+               int i;
+               for (i = 1; i < SECINITSID_NUM; i++) {
+-                      if (!strcmp(initial_sid_to_string[i], scontext)) {
++                      if (!strcmp(initial_sid_to_string[i], scontext2)) {
+                               *sid = i;
+-                              return 0;
++                              goto out;
+                       }
+               }
+               *sid = SECINITSID_KERNEL;
+-              return 0;
++              goto out;
+       }
+       *sid = SECSID_NULL;
+-      /* Copy the string so that we can modify the copy as we parse it. */
+-      scontext2 = kmalloc(scontext_len + 1, gfp_flags);
+-      if (!scontext2)
+-              return -ENOMEM;
+-      memcpy(scontext2, scontext, scontext_len);
+-      scontext2[scontext_len] = 0;
+-
+       if (force) {
+               /* Save another copy for storing in uninterpreted form */
+               rc = -ENOMEM;
diff --git a/queue-4.9/selinux-skip-bounded-transition-processing-if-the-policy-isn-t-loaded.patch b/queue-4.9/selinux-skip-bounded-transition-processing-if-the-policy-isn-t-loaded.patch
new file mode 100644 (file)
index 0000000..273cf30
--- /dev/null
@@ -0,0 +1,38 @@
+From 4b14752ec4e0d87126e636384cf37c8dd9df157c Mon Sep 17 00:00:00 2001
+From: Paul Moore <paul@paul-moore.com>
+Date: Tue, 5 Dec 2017 17:17:43 -0500
+Subject: selinux: skip bounded transition processing if the policy isn't loaded
+
+From: Paul Moore <paul@paul-moore.com>
+
+commit 4b14752ec4e0d87126e636384cf37c8dd9df157c upstream.
+
+We can't do anything reasonable in security_bounded_transition() if we
+don't have a policy loaded, and in fact we could run into problems
+with some of the code inside expecting a policy.  Fix these problems
+like we do many others in security/selinux/ss/services.c by checking
+to see if the policy is loaded (ss_initialized) and returning quickly
+if it isn't.
+
+Reported-by: syzbot <syzkaller-bugs@googlegroups.com>
+Signed-off-by: Paul Moore <paul@paul-moore.com>
+Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
+Reviewed-by: James Morris <james.l.morris@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ security/selinux/ss/services.c |    3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/security/selinux/ss/services.c
++++ b/security/selinux/ss/services.c
+@@ -854,6 +854,9 @@ int security_bounded_transition(u32 old_
+       int index;
+       int rc;
++      if (!ss_initialized)
++              return 0;
++
+       read_lock(&policy_rwlock);
+       rc = -EINVAL;
diff --git a/queue-4.9/series b/queue-4.9/series
new file mode 100644 (file)
index 0000000..85716a9
--- /dev/null
@@ -0,0 +1,29 @@
+vhost-use-mutex_lock_nested-in-vhost_dev_lock_vqs.patch
+kcm-check-if-sk_user_data-already-set-in-kcm_attach.patch
+kcm-only-allow-tcp-sockets-to-be-attached-to-a-kcm-mux.patch
+cfg80211-check-dev_set_name-return-value.patch
+xfrm-skip-policies-marked-as-dead-while-rehashing.patch
+mm-vmscan-make-unregister_shrinker-no-op-if-register_shrinker-failed.patch
+xfrm-fix-stack-out-of-bounds-read-on-socket-policy-lookup.patch
+xfrm-check-id-proto-in-validate_tmpl.patch
+sctp-set-frag_point-in-sctp_setsockopt_maxseg-correctly.patch
+blktrace-fix-unlocked-registration-of-tracepoints.patch
+drm-require-__gfp_nofail-for-the-legacy-drm_modeset_lock_all.patch
+ptr_ring-fail-early-if-queue-occupies-more-than-kmalloc_max_size.patch
+provide-a-function-to-create-a-nul-terminated-string-from-unterminated-data.patch
+selinux-ensure-the-context-is-nul-terminated-in-security_context_to_sid_core.patch
+selinux-skip-bounded-transition-processing-if-the-policy-isn-t-loaded.patch
+crypto-x86-twofish-3way-fix-rbp-usage.patch
+staging-android-ion-add-__gfp_nowarn-for-system-contig-heap.patch
+staging-android-ion-switch-from-warn-to-pr_warn.patch
+blk_rq_map_user_iov-fix-error-override.patch
+kvm-x86-fix-escape-of-guest-dr6-to-the-host.patch
+kcov-detect-double-association-with-a-single-task.patch
+netfilter-x_tables-fix-int-overflow-in-xt_alloc_table_info.patch
+netfilter-x_tables-avoid-out-of-bounds-reads-in-xt_request_find_-match-target.patch
+netfilter-ipt_clusterip-fix-out-of-bounds-accesses-in-clusterip_tg_check.patch
+netfilter-on-sockopt-acquire-sock-lock-only-in-the-required-scope.patch
+netfilter-xt_cgroup-initialize-info-priv-in-cgroup_mt_check_v1.patch
+netfilter-xt_rateest-acquire-xt_rateest_mutex-for-hash-insert.patch
+rds-tcp-atomically-purge-entries-from-rds_tcp_conn_list-during-netns-delete.patch
+net-avoid-skb_warn_bad_offload-on-is_err.patch
diff --git a/queue-4.9/staging-android-ion-add-__gfp_nowarn-for-system-contig-heap.patch b/queue-4.9/staging-android-ion-add-__gfp_nowarn-for-system-contig-heap.patch
new file mode 100644 (file)
index 0000000..59ec4db
--- /dev/null
@@ -0,0 +1,53 @@
+From 0c75f10312a35b149b2cebb1832316b35c2337ca Mon Sep 17 00:00:00 2001
+From: Laura Abbott <labbott@redhat.com>
+Date: Fri, 5 Jan 2018 11:14:08 -0800
+Subject: staging: android: ion: Add __GFP_NOWARN for system contig heap
+
+From: Laura Abbott <labbott@redhat.com>
+
+commit 0c75f10312a35b149b2cebb1832316b35c2337ca upstream.
+
+syzbot reported a warning from Ion:
+
+  WARNING: CPU: 1 PID: 3485 at mm/page_alloc.c:3926
+
+  ...
+   __alloc_pages_nodemask+0x9fb/0xd80 mm/page_alloc.c:4252
+  alloc_pages_current+0xb6/0x1e0 mm/mempolicy.c:2036
+  alloc_pages include/linux/gfp.h:492 [inline]
+  ion_system_contig_heap_allocate+0x40/0x2c0
+  drivers/staging/android/ion/ion_system_heap.c:374
+  ion_buffer_create drivers/staging/android/ion/ion.c:93 [inline]
+  ion_alloc+0x2c1/0x9e0 drivers/staging/android/ion/ion.c:420
+  ion_ioctl+0x26d/0x380 drivers/staging/android/ion/ion-ioctl.c:84
+  vfs_ioctl fs/ioctl.c:46 [inline]
+  do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:686
+  SYSC_ioctl fs/ioctl.c:701 [inline]
+  SyS_ioctl+0x8f/0xc0 fs/ioctl.c:692
+
+This is a warning about attempting to allocate order > MAX_ORDER. This
+is coming from a userspace Ion allocation request. Since userspace is
+free to request however much memory it wants (and the kernel is free to
+deny its allocation), silence the allocation attempt with __GFP_NOWARN
+in case it fails.
+
+Reported-by: syzbot+76e7efc4748495855a4d@syzkaller.appspotmail.com
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Laura Abbott <labbott@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/staging/android/ion/ion_system_heap.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/staging/android/ion/ion_system_heap.c
++++ b/drivers/staging/android/ion/ion_system_heap.c
+@@ -384,7 +384,7 @@ static int ion_system_contig_heap_alloca
+       if (align > (PAGE_SIZE << order))
+               return -EINVAL;
+-      page = alloc_pages(low_order_gfp_flags, order);
++      page = alloc_pages(low_order_gfp_flags | __GFP_NOWARN, order);
+       if (!page)
+               return -ENOMEM;
diff --git a/queue-4.9/staging-android-ion-switch-from-warn-to-pr_warn.patch b/queue-4.9/staging-android-ion-switch-from-warn-to-pr_warn.patch
new file mode 100644 (file)
index 0000000..dfcf8b1
--- /dev/null
@@ -0,0 +1,42 @@
+From e4e179a844f52e907e550f887d0a2171f1508af1 Mon Sep 17 00:00:00 2001
+From: Laura Abbott <labbott@redhat.com>
+Date: Fri, 5 Jan 2018 11:14:09 -0800
+Subject: staging: android: ion: Switch from WARN to pr_warn
+
+From: Laura Abbott <labbott@redhat.com>
+
+commit e4e179a844f52e907e550f887d0a2171f1508af1 upstream.
+
+Syzbot reported a warning with Ion:
+
+WARNING: CPU: 0 PID: 3502 at drivers/staging/android/ion/ion-ioctl.c:73 ion_ioctl+0x2db/0x380 drivers/staging/android/ion/ion-ioctl.c:73
+Kernel panic - not syncing: panic_on_warn set ...
+
+This is a warning that validation of the ioctl fields failed. This was
+deliberately added as a warning to make it very obvious to developers that
+something needed to be fixed. In reality, this is overkill and disturbs
+fuzzing. Switch to pr_warn for a message instead.
+
+Reported-by: syzbot+fa2d5f63ee5904a0115a@syzkaller.appspotmail.com
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Laura Abbott <labbott@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/staging/android/ion/ion-ioctl.c |    4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+--- a/drivers/staging/android/ion/ion-ioctl.c
++++ b/drivers/staging/android/ion/ion-ioctl.c
+@@ -83,8 +83,10 @@ long ion_ioctl(struct file *filp, unsign
+               return -EFAULT;
+       ret = validate_ioctl_arg(cmd, &data);
+-      if (WARN_ON_ONCE(ret))
++      if (ret) {
++              pr_warn_once("%s: ioctl validate failed\n", __func__);
+               return ret;
++      }
+       if (!(dir & _IOC_WRITE))
+               memset(&data, 0, sizeof(data));
diff --git a/queue-4.9/vhost-use-mutex_lock_nested-in-vhost_dev_lock_vqs.patch b/queue-4.9/vhost-use-mutex_lock_nested-in-vhost_dev_lock_vqs.patch
new file mode 100644 (file)
index 0000000..008e25f
--- /dev/null
@@ -0,0 +1,36 @@
+From e9cb4239134c860e5f92c75bf5321bd377bb505b Mon Sep 17 00:00:00 2001
+From: Jason Wang <jasowang@redhat.com>
+Date: Tue, 23 Jan 2018 17:27:25 +0800
+Subject: vhost: use mutex_lock_nested() in vhost_dev_lock_vqs()
+
+From: Jason Wang <jasowang@redhat.com>
+
+commit e9cb4239134c860e5f92c75bf5321bd377bb505b upstream.
+
+We used to call mutex_lock() in vhost_dev_lock_vqs() which tries to
+hold mutexes of all virtqueues. This may confuse lockdep to report a
+possible deadlock because of trying to hold locks belong to same
+class. Switch to use mutex_lock_nested() to avoid false positive.
+
+Fixes: 6b1e6cc7855b0 ("vhost: new device IOTLB API")
+Reported-by: syzbot+dbb7c1161485e61b0241@syzkaller.appspotmail.com
+Signed-off-by: Jason Wang <jasowang@redhat.com>
+Acked-by: Michael S. Tsirkin <mst@redhat.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/vhost/vhost.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/vhost/vhost.c
++++ b/drivers/vhost/vhost.c
+@@ -849,7 +849,7 @@ static void vhost_dev_lock_vqs(struct vh
+ {
+       int i = 0;
+       for (i = 0; i < d->nvqs; ++i)
+-              mutex_lock(&d->vqs[i]->mutex);
++              mutex_lock_nested(&d->vqs[i]->mutex, i);
+ }
+ static void vhost_dev_unlock_vqs(struct vhost_dev *d)
diff --git a/queue-4.9/xfrm-check-id-proto-in-validate_tmpl.patch b/queue-4.9/xfrm-check-id-proto-in-validate_tmpl.patch
new file mode 100644 (file)
index 0000000..55a3370
--- /dev/null
@@ -0,0 +1,57 @@
+From 6a53b7593233ab9e4f96873ebacc0f653a55c3e1 Mon Sep 17 00:00:00 2001
+From: Cong Wang <xiyou.wangcong@gmail.com>
+Date: Mon, 27 Nov 2017 11:15:16 -0800
+Subject: xfrm: check id proto in validate_tmpl()
+
+From: Cong Wang <xiyou.wangcong@gmail.com>
+
+commit 6a53b7593233ab9e4f96873ebacc0f653a55c3e1 upstream.
+
+syzbot reported a kernel warning in xfrm_state_fini(), which
+indicates that we have entries left in the list
+net->xfrm.state_all whose proto is zero. And
+xfrm_id_proto_match() doesn't consider them as a match with
+IPSEC_PROTO_ANY in this case.
+
+Proto with value 0 is probably not a valid value, at least
+verify_newsa_info() doesn't consider it valid either.
+
+This patch fixes it by checking the proto value in
+validate_tmpl() and rejecting invalid ones, like what iproute2
+does in xfrm_xfrmproto_getbyname().
+
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Cc: Steffen Klassert <steffen.klassert@secunet.com>
+Cc: Herbert Xu <herbert@gondor.apana.org.au>
+Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
+Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/xfrm/xfrm_user.c |   15 +++++++++++++++
+ 1 file changed, 15 insertions(+)
+
+--- a/net/xfrm/xfrm_user.c
++++ b/net/xfrm/xfrm_user.c
+@@ -1406,6 +1406,21 @@ static int validate_tmpl(int nr, struct
+               default:
+                       return -EINVAL;
+               }
++
++              switch (ut[i].id.proto) {
++              case IPPROTO_AH:
++              case IPPROTO_ESP:
++              case IPPROTO_COMP:
++#if IS_ENABLED(CONFIG_IPV6)
++              case IPPROTO_ROUTING:
++              case IPPROTO_DSTOPTS:
++#endif
++              case IPSEC_PROTO_ANY:
++                      break;
++              default:
++                      return -EINVAL;
++              }
++
+       }
+       return 0;
diff --git a/queue-4.9/xfrm-fix-stack-out-of-bounds-read-on-socket-policy-lookup.patch b/queue-4.9/xfrm-fix-stack-out-of-bounds-read-on-socket-policy-lookup.patch
new file mode 100644 (file)
index 0000000..512b781
--- /dev/null
@@ -0,0 +1,46 @@
+From ddc47e4404b58f03e98345398fb12d38fe291512 Mon Sep 17 00:00:00 2001
+From: Steffen Klassert <steffen.klassert@secunet.com>
+Date: Wed, 29 Nov 2017 06:53:55 +0100
+Subject: xfrm: Fix stack-out-of-bounds read on socket policy lookup.
+
+From: Steffen Klassert <steffen.klassert@secunet.com>
+
+commit ddc47e4404b58f03e98345398fb12d38fe291512 upstream.
+
+When we do tunnel or beet mode, we pass saddr and daddr from the
+template to xfrm_state_find(), this is ok. On transport mode,
+we pass the addresses from the flowi, assuming that the IP
+addresses (and address family) don't change during transformation.
+This assumption is wrong in the IPv4 mapped IPv6 case, packet
+is IPv4 and template is IPv6.
+
+Fix this by catching address family missmatches of the policy
+and the flow already before we do the lookup.
+
+Reported-by: syzbot <syzkaller@googlegroups.com>
+Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/xfrm/xfrm_policy.c |    8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+--- a/net/xfrm/xfrm_policy.c
++++ b/net/xfrm/xfrm_policy.c
+@@ -1257,9 +1257,15 @@ static struct xfrm_policy *xfrm_sk_polic
+  again:
+       pol = rcu_dereference(sk->sk_policy[dir]);
+       if (pol != NULL) {
+-              bool match = xfrm_selector_match(&pol->selector, fl, family);
++              bool match;
+               int err = 0;
++              if (pol->family != family) {
++                      pol = NULL;
++                      goto out;
++              }
++
++              match = xfrm_selector_match(&pol->selector, fl, family);
+               if (match) {
+                       if ((sk->sk_mark & pol->mark.m) != pol->mark.v) {
+                               pol = NULL;
diff --git a/queue-4.9/xfrm-skip-policies-marked-as-dead-while-rehashing.patch b/queue-4.9/xfrm-skip-policies-marked-as-dead-while-rehashing.patch
new file mode 100644 (file)
index 0000000..1e874c3
--- /dev/null
@@ -0,0 +1,64 @@
+From 862591bf4f519d1b8d859af720fafeaebdd0162a Mon Sep 17 00:00:00 2001
+From: Florian Westphal <fw@strlen.de>
+Date: Wed, 27 Dec 2017 23:25:45 +0100
+Subject: xfrm: skip policies marked as dead while rehashing
+
+From: Florian Westphal <fw@strlen.de>
+
+commit 862591bf4f519d1b8d859af720fafeaebdd0162a upstream.
+
+syzkaller triggered following KASAN splat:
+
+BUG: KASAN: slab-out-of-bounds in xfrm_hash_rebuild+0xdbe/0xf00 net/xfrm/xfrm_policy.c:618
+read of size 2 at addr ffff8801c8e92fe4 by task kworker/1:1/23 [..]
+Workqueue: events xfrm_hash_rebuild [..]
+ __asan_report_load2_noabort+0x14/0x20 mm/kasan/report.c:428
+ xfrm_hash_rebuild+0xdbe/0xf00 net/xfrm/xfrm_policy.c:618
+ process_one_work+0xbbf/0x1b10 kernel/workqueue.c:2112
+ worker_thread+0x223/0x1990 kernel/workqueue.c:2246 [..]
+
+The reproducer triggers:
+1016                 if (error) {
+1017                         list_move_tail(&walk->walk.all, &x->all);
+1018                         goto out;
+1019                 }
+
+in xfrm_policy_walk() via pfkey (it sets tiny rcv space, dump
+callback returns -ENOBUFS).
+
+In this case, *walk is located the pfkey socket struct, so this socket
+becomes visible in the global policy list.
+
+It looks like this is intentional -- phony walker has walk.dead set to 1
+and all other places skip such "policies".
+
+Ccing original authors of the two commits that seem to expose this
+issue (first patch missed ->dead check, second patch adds pfkey
+sockets to policies dumper list).
+
+Fixes: 880a6fab8f6ba5b ("xfrm: configure policy hash table thresholds by netlink")
+Fixes: 12a169e7d8f4b1c ("ipsec: Put dumpers on the dump list")
+Cc: Herbert Xu <herbert@gondor.apana.org.au>
+Cc: Timo Teras <timo.teras@iki.fi>
+Cc: Christophe Gouault <christophe.gouault@6wind.com>
+Reported-by: syzbot <bot+c028095236fcb6f4348811565b75084c754dc729@syzkaller.appspotmail.com>
+Signed-off-by: Florian Westphal <fw@strlen.de>
+Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/xfrm/xfrm_policy.c |    3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+--- a/net/xfrm/xfrm_policy.c
++++ b/net/xfrm/xfrm_policy.c
+@@ -643,7 +643,8 @@ static void xfrm_hash_rebuild(struct wor
+       /* re-insert all policies by order of creation */
+       list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) {
+-              if (xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) {
++              if (policy->walk.dead ||
++                  xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) {
+                       /* skip socket policies */
+                       continue;
+               }