]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.19-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Apr 2020 09:30:51 +0000 (11:30 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Apr 2020 09:30:51 +0000 (11:30 +0200)
added patches:
bpf-fix-buggy-r0-retval-refinement-for-tracing-helpers.patch
fbdev-potential-information-leak-in-do_fb_ioctl.patch
iio-si1133-read-24-bit-signed-integer-for-measurement.patch
keys-don-t-write-out-to-userspace-while-holding-key-semaphore.patch
locktorture-print-ratio-of-acquisitions-not-failures.patch
mtd-lpddr-fix-a-double-free-in-probe.patch
mtd-phram-fix-a-double-free-issue-in-error-path.patch
mtd-spinand-explicitly-use-mtd_ops_raw-to-write-the-bad-block-marker-to-oob.patch
net-dsa-bcm_sf2-fix-overflow-checks.patch
tty-evh_bytechan-fix-out-of-bounds-accesses.patch

queue-4.19/bpf-fix-buggy-r0-retval-refinement-for-tracing-helpers.patch [new file with mode: 0644]
queue-4.19/fbdev-potential-information-leak-in-do_fb_ioctl.patch [new file with mode: 0644]
queue-4.19/iio-si1133-read-24-bit-signed-integer-for-measurement.patch [new file with mode: 0644]
queue-4.19/keys-don-t-write-out-to-userspace-while-holding-key-semaphore.patch [new file with mode: 0644]
queue-4.19/locktorture-print-ratio-of-acquisitions-not-failures.patch [new file with mode: 0644]
queue-4.19/mtd-lpddr-fix-a-double-free-in-probe.patch [new file with mode: 0644]
queue-4.19/mtd-phram-fix-a-double-free-issue-in-error-path.patch [new file with mode: 0644]
queue-4.19/mtd-spinand-explicitly-use-mtd_ops_raw-to-write-the-bad-block-marker-to-oob.patch [new file with mode: 0644]
queue-4.19/net-dsa-bcm_sf2-fix-overflow-checks.patch [new file with mode: 0644]
queue-4.19/series
queue-4.19/tty-evh_bytechan-fix-out-of-bounds-accesses.patch [new file with mode: 0644]

diff --git a/queue-4.19/bpf-fix-buggy-r0-retval-refinement-for-tracing-helpers.patch b/queue-4.19/bpf-fix-buggy-r0-retval-refinement-for-tracing-helpers.patch
new file mode 100644 (file)
index 0000000..749fd53
--- /dev/null
@@ -0,0 +1,147 @@
+From daniel@iogearbox.net  Wed Apr 22 10:21:06 2020
+From: Daniel Borkmann <daniel@iogearbox.net>
+Date: Tue, 21 Apr 2020 14:58:22 +0200
+Subject: bpf: fix buggy r0 retval refinement for tracing helpers
+To: gregkh@linuxfoundation.org
+Cc: alexei.starovoitov@gmail.com, john.fastabend@gmail.com, kpsingh@chromium.org, jannh@google.com, fontanalorenz@gmail.com, leodidonato@gmail.com, yhs@fb.com, bpf@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>, Alexei Starovoitov <ast@kernel.org>
+Message-ID: <20200421125822.14073-1-daniel@iogearbox.net>
+
+From: Daniel Borkmann <daniel@iogearbox.net>
+
+[ no upstream commit ]
+
+See the glory details in 100605035e15 ("bpf: Verifier, do_refine_retval_range
+may clamp umin to 0 incorrectly") for why 849fa50662fb ("bpf/verifier: refine
+retval R0 state for bpf_get_stack helper") is buggy. The whole series however
+is not suitable for stable since it adds significant amount [0] of verifier
+complexity in order to add 32bit subreg tracking. Something simpler is needed.
+
+Unfortunately, reverting 849fa50662fb ("bpf/verifier: refine retval R0 state
+for bpf_get_stack helper") or just cherry-picking 100605035e15 ("bpf: Verifier,
+do_refine_retval_range may clamp umin to 0 incorrectly") is not an option since
+it will break existing tracing programs badly (at least those that are using
+bpf_get_stack() and bpf_probe_read_str() helpers). Not fixing it in stable is
+also not an option since on 4.19 kernels an error will cause a soft-lockup due
+to hitting dead-code sanitized branch since we don't hard-wire such branches
+in old kernels yet. But even then for 5.x 849fa50662fb ("bpf/verifier: refine
+retval R0 state for bpf_get_stack helper") would cause wrong bounds on the
+verifier simluation when an error is hit.
+
+In one of the earlier iterations of mentioned patch series for upstream there
+was the concern that just using smax_value in do_refine_retval_range() would
+nuke bounds by subsequent <<32 >>32 shifts before the comparison against 0 [1]
+which eventually led to the 32bit subreg tracking in the first place. While I
+initially went for implementing the idea [1] to pattern match the two shift
+operations, it turned out to be more complex than actually needed, meaning, we
+could simply treat do_refine_retval_range() similarly to how we branch off
+verification for conditionals or under speculation, that is, pushing a new
+reg state to the stack for later verification. This means, instead of verifying
+the current path with the ret_reg in [S32MIN, msize_max_value] interval where
+later bounds would get nuked, we split this into two: i) for the success case
+where ret_reg can be in [0, msize_max_value], and ii) for the error case with
+ret_reg known to be in interval [S32MIN, -1]. Latter will preserve the bounds
+during these shift patterns and can match reg < 0 test. test_progs also succeed
+with this approach.
+
+  [0] https://lore.kernel.org/bpf/158507130343.15666.8018068546764556975.stgit@john-Precision-5820-Tower/
+  [1] https://lore.kernel.org/bpf/158015334199.28573.4940395881683556537.stgit@john-XPS-13-9370/T/#m2e0ad1d5949131014748b6daa48a3495e7f0456d
+
+Fixes: 849fa50662fb ("bpf/verifier: refine retval R0 state for bpf_get_stack helper")
+Reported-by: Lorenzo Fontana <fontanalorenz@gmail.com>
+Reported-by: Leonardo Di Donato <leodidonato@gmail.com>
+Reported-by: John Fastabend <john.fastabend@gmail.com>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Alexei Starovoitov <ast@kernel.org>
+Acked-by: John Fastabend <john.fastabend@gmail.com>
+Tested-by: John Fastabend <john.fastabend@gmail.com>
+Tested-by: Lorenzo Fontana <fontanalorenz@gmail.com>
+Tested-by: Leonardo Di Donato <leodidonato@gmail.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/bpf/verifier.c |   45 ++++++++++++++++++++++++++++++++++-----------
+ 1 file changed, 34 insertions(+), 11 deletions(-)
+
+--- a/kernel/bpf/verifier.c
++++ b/kernel/bpf/verifier.c
+@@ -188,8 +188,7 @@ struct bpf_call_arg_meta {
+       bool pkt_access;
+       int regno;
+       int access_size;
+-      s64 msize_smax_value;
+-      u64 msize_umax_value;
++      u64 msize_max_value;
+ };
+ static DEFINE_MUTEX(bpf_verifier_lock);
+@@ -2076,8 +2075,7 @@ static int check_func_arg(struct bpf_ver
+               /* remember the mem_size which may be used later
+                * to refine return values.
+                */
+-              meta->msize_smax_value = reg->smax_value;
+-              meta->msize_umax_value = reg->umax_value;
++              meta->msize_max_value = reg->umax_value;
+               /* The register is SCALAR_VALUE; the access check
+                * happens using its boundaries.
+@@ -2448,21 +2446,44 @@ static int prepare_func_exit(struct bpf_
+       return 0;
+ }
+-static void do_refine_retval_range(struct bpf_reg_state *regs, int ret_type,
+-                                 int func_id,
+-                                 struct bpf_call_arg_meta *meta)
++static int do_refine_retval_range(struct bpf_verifier_env *env,
++                                struct bpf_reg_state *regs, int ret_type,
++                                int func_id, struct bpf_call_arg_meta *meta)
+ {
+       struct bpf_reg_state *ret_reg = &regs[BPF_REG_0];
++      struct bpf_reg_state tmp_reg = *ret_reg;
++      bool ret;
+       if (ret_type != RET_INTEGER ||
+           (func_id != BPF_FUNC_get_stack &&
+            func_id != BPF_FUNC_probe_read_str))
+-              return;
++              return 0;
++
++      /* Error case where ret is in interval [S32MIN, -1]. */
++      ret_reg->smin_value = S32_MIN;
++      ret_reg->smax_value = -1;
+-      ret_reg->smax_value = meta->msize_smax_value;
+-      ret_reg->umax_value = meta->msize_umax_value;
+       __reg_deduce_bounds(ret_reg);
+       __reg_bound_offset(ret_reg);
++      __update_reg_bounds(ret_reg);
++
++      ret = push_stack(env, env->insn_idx + 1, env->insn_idx, false);
++      if (!ret)
++              return -EFAULT;
++
++      *ret_reg = tmp_reg;
++
++      /* Success case where ret is in range [0, msize_max_value]. */
++      ret_reg->smin_value = 0;
++      ret_reg->smax_value = meta->msize_max_value;
++      ret_reg->umin_value = ret_reg->smin_value;
++      ret_reg->umax_value = ret_reg->smax_value;
++
++      __reg_deduce_bounds(ret_reg);
++      __reg_bound_offset(ret_reg);
++      __update_reg_bounds(ret_reg);
++
++      return 0;
+ }
+ static int
+@@ -2617,7 +2638,9 @@ static int check_helper_call(struct bpf_
+               return -EINVAL;
+       }
+-      do_refine_retval_range(regs, fn->ret_type, func_id, &meta);
++      err = do_refine_retval_range(env, regs, fn->ret_type, func_id, &meta);
++      if (err)
++              return err;
+       err = check_map_func_compatibility(env, meta.map_ptr, func_id);
+       if (err)
diff --git a/queue-4.19/fbdev-potential-information-leak-in-do_fb_ioctl.patch b/queue-4.19/fbdev-potential-information-leak-in-do_fb_ioctl.patch
new file mode 100644 (file)
index 0000000..2e017d5
--- /dev/null
@@ -0,0 +1,46 @@
+From d3d19d6fc5736a798b118971935ce274f7deaa82 Mon Sep 17 00:00:00 2001
+From: Dan Carpenter <dan.carpenter@oracle.com>
+Date: Mon, 13 Jan 2020 14:08:14 +0300
+Subject: fbdev: potential information leak in do_fb_ioctl()
+
+From: Dan Carpenter <dan.carpenter@oracle.com>
+
+commit d3d19d6fc5736a798b118971935ce274f7deaa82 upstream.
+
+The "fix" struct has a 2 byte hole after ->ywrapstep and the
+"fix = info->fix;" assignment doesn't necessarily clear it.  It depends
+on the compiler.  The solution is just to replace the assignment with an
+memcpy().
+
+Fixes: 1f5e31d7e55a ("fbmem: don't call copy_from/to_user() with mutex held")
+Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Arnd Bergmann <arnd@arndb.de>
+Cc: "Eric W. Biederman" <ebiederm@xmission.com>
+Cc: Andrea Righi <righi.andrea@gmail.com>
+Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
+Cc: Sam Ravnborg <sam@ravnborg.org>
+Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
+Cc: Daniel Thompson <daniel.thompson@linaro.org>
+Cc: Peter Rosin <peda@axentia.se>
+Cc: Jani Nikula <jani.nikula@intel.com>
+Cc: Gerd Hoffmann <kraxel@redhat.com>
+Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
+Link: https://patchwork.freedesktop.org/patch/msgid/20200113100132.ixpaymordi24n3av@kili.mountain
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/video/fbdev/core/fbmem.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/video/fbdev/core/fbmem.c
++++ b/drivers/video/fbdev/core/fbmem.c
+@@ -1122,7 +1122,7 @@ static long do_fb_ioctl(struct fb_info *
+       case FBIOGET_FSCREENINFO:
+               if (!lock_fb_info(info))
+                       return -ENODEV;
+-              fix = info->fix;
++              memcpy(&fix, &info->fix, sizeof(fix));
+               unlock_fb_info(info);
+               ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0;
diff --git a/queue-4.19/iio-si1133-read-24-bit-signed-integer-for-measurement.patch b/queue-4.19/iio-si1133-read-24-bit-signed-integer-for-measurement.patch
new file mode 100644 (file)
index 0000000..fd6c03b
--- /dev/null
@@ -0,0 +1,131 @@
+From 328b50e9a0ad1fe8accdf8c19923deebab5e0c01 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Maxime=20Roussin-B=C3=A9langer?=
+ <maxime.roussinbelanger@gmail.com>
+Date: Wed, 19 Feb 2020 12:40:08 -0500
+Subject: iio: si1133: read 24-bit signed integer for measurement
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
+
+commit 328b50e9a0ad1fe8accdf8c19923deebab5e0c01 upstream.
+
+The chip is configured in 24 bit mode. The values read from
+it must always be treated as is. This fixes the issue by
+replacing the previous 16 bits value by a 24 bits buffer.
+
+This changes affects the value output by previous version of
+the driver, since the least significant byte was missing.
+The upper half of 16 bit values previously output are now
+the upper half of a 24 bit value.
+
+Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
+
+Reported-by: Simon Goyette <simon.goyette@gmail.com>
+Co-authored-by: Guillaume Champagne <champagne.guillaume.c@gmail.com>
+Signed-off-by: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
+Signed-off-by: Guillaume Champagne <champagne.guillaume.c@gmail.com>
+Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/iio/light/si1133.c |   37 ++++++++++++++++++++++++-------------
+ 1 file changed, 24 insertions(+), 13 deletions(-)
+
+--- a/drivers/iio/light/si1133.c
++++ b/drivers/iio/light/si1133.c
+@@ -102,6 +102,9 @@
+ #define SI1133_INPUT_FRACTION_LOW     15
+ #define SI1133_LUX_OUTPUT_FRACTION    12
+ #define SI1133_LUX_BUFFER_SIZE                9
++#define SI1133_MEASURE_BUFFER_SIZE    3
++
++#define SI1133_SIGN_BIT_INDEX 23
+ static const int si1133_scale_available[] = {
+       1, 2, 4, 8, 16, 32, 64, 128};
+@@ -234,13 +237,13 @@ static const struct si1133_lux_coeff lux
+       }
+ };
+-static int si1133_calculate_polynomial_inner(u32 input, u8 fraction, u16 mag,
++static int si1133_calculate_polynomial_inner(s32 input, u8 fraction, u16 mag,
+                                            s8 shift)
+ {
+       return ((input << fraction) / mag) << shift;
+ }
+-static int si1133_calculate_output(u32 x, u32 y, u8 x_order, u8 y_order,
++static int si1133_calculate_output(s32 x, s32 y, u8 x_order, u8 y_order,
+                                  u8 input_fraction, s8 sign,
+                                  const struct si1133_coeff *coeffs)
+ {
+@@ -276,7 +279,7 @@ static int si1133_calculate_output(u32 x
+  * The algorithm is from:
+  * https://siliconlabs.github.io/Gecko_SDK_Doc/efm32zg/html/si1133_8c_source.html#l00716
+  */
+-static int si1133_calc_polynomial(u32 x, u32 y, u8 input_fraction, u8 num_coeff,
++static int si1133_calc_polynomial(s32 x, s32 y, u8 input_fraction, u8 num_coeff,
+                                 const struct si1133_coeff *coeffs)
+ {
+       u8 x_order, y_order;
+@@ -614,7 +617,7 @@ static int si1133_measure(struct si1133_
+ {
+       int err;
+-      __be16 resp;
++      u8 buffer[SI1133_MEASURE_BUFFER_SIZE];
+       err = si1133_set_adcmux(data, 0, chan->channel);
+       if (err)
+@@ -625,12 +628,13 @@ static int si1133_measure(struct si1133_
+       if (err)
+               return err;
+-      err = si1133_bulk_read(data, SI1133_REG_HOSTOUT(0), sizeof(resp),
+-                             (u8 *)&resp);
++      err = si1133_bulk_read(data, SI1133_REG_HOSTOUT(0), sizeof(buffer),
++                             buffer);
+       if (err)
+               return err;
+-      *val = be16_to_cpu(resp);
++      *val = sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2],
++                           SI1133_SIGN_BIT_INDEX);
+       return err;
+ }
+@@ -704,9 +708,9 @@ static int si1133_get_lux(struct si1133_
+ {
+       int err;
+       int lux;
+-      u32 high_vis;
+-      u32 low_vis;
+-      u32 ir;
++      s32 high_vis;
++      s32 low_vis;
++      s32 ir;
+       u8 buffer[SI1133_LUX_BUFFER_SIZE];
+       /* Activate lux channels */
+@@ -719,9 +723,16 @@ static int si1133_get_lux(struct si1133_
+       if (err)
+               return err;
+-      high_vis = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
+-      low_vis = (buffer[3] << 16) | (buffer[4] << 8) | buffer[5];
+-      ir = (buffer[6] << 16) | (buffer[7] << 8) | buffer[8];
++      high_vis =
++              sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2],
++                            SI1133_SIGN_BIT_INDEX);
++
++      low_vis =
++              sign_extend32((buffer[3] << 16) | (buffer[4] << 8) | buffer[5],
++                            SI1133_SIGN_BIT_INDEX);
++
++      ir = sign_extend32((buffer[6] << 16) | (buffer[7] << 8) | buffer[8],
++                         SI1133_SIGN_BIT_INDEX);
+       if (high_vis > SI1133_ADC_THRESHOLD || ir > SI1133_ADC_THRESHOLD)
+               lux = si1133_calc_polynomial(high_vis, ir,
diff --git a/queue-4.19/keys-don-t-write-out-to-userspace-while-holding-key-semaphore.patch b/queue-4.19/keys-don-t-write-out-to-userspace-while-holding-key-semaphore.patch
new file mode 100644 (file)
index 0000000..a859074
--- /dev/null
@@ -0,0 +1,572 @@
+From d3ec10aa95819bff18a0d936b18884c7816d0914 Mon Sep 17 00:00:00 2001
+From: Waiman Long <longman@redhat.com>
+Date: Sat, 21 Mar 2020 21:11:24 -0400
+Subject: KEYS: Don't write out to userspace while holding key semaphore
+
+From: Waiman Long <longman@redhat.com>
+
+commit d3ec10aa95819bff18a0d936b18884c7816d0914 upstream.
+
+A lockdep circular locking dependency report was seen when running a
+keyutils test:
+
+[12537.027242] ======================================================
+[12537.059309] WARNING: possible circular locking dependency detected
+[12537.088148] 4.18.0-147.7.1.el8_1.x86_64+debug #1 Tainted: G OE    --------- -  -
+[12537.125253] ------------------------------------------------------
+[12537.153189] keyctl/25598 is trying to acquire lock:
+[12537.175087] 000000007c39f96c (&mm->mmap_sem){++++}, at: __might_fault+0xc4/0x1b0
+[12537.208365]
+[12537.208365] but task is already holding lock:
+[12537.234507] 000000003de5b58d (&type->lock_class){++++}, at: keyctl_read_key+0x15a/0x220
+[12537.270476]
+[12537.270476] which lock already depends on the new lock.
+[12537.270476]
+[12537.307209]
+[12537.307209] the existing dependency chain (in reverse order) is:
+[12537.340754]
+[12537.340754] -> #3 (&type->lock_class){++++}:
+[12537.367434]        down_write+0x4d/0x110
+[12537.385202]        __key_link_begin+0x87/0x280
+[12537.405232]        request_key_and_link+0x483/0xf70
+[12537.427221]        request_key+0x3c/0x80
+[12537.444839]        dns_query+0x1db/0x5a5 [dns_resolver]
+[12537.468445]        dns_resolve_server_name_to_ip+0x1e1/0x4d0 [cifs]
+[12537.496731]        cifs_reconnect+0xe04/0x2500 [cifs]
+[12537.519418]        cifs_readv_from_socket+0x461/0x690 [cifs]
+[12537.546263]        cifs_read_from_socket+0xa0/0xe0 [cifs]
+[12537.573551]        cifs_demultiplex_thread+0x311/0x2db0 [cifs]
+[12537.601045]        kthread+0x30c/0x3d0
+[12537.617906]        ret_from_fork+0x3a/0x50
+[12537.636225]
+[12537.636225] -> #2 (root_key_user.cons_lock){+.+.}:
+[12537.664525]        __mutex_lock+0x105/0x11f0
+[12537.683734]        request_key_and_link+0x35a/0xf70
+[12537.705640]        request_key+0x3c/0x80
+[12537.723304]        dns_query+0x1db/0x5a5 [dns_resolver]
+[12537.746773]        dns_resolve_server_name_to_ip+0x1e1/0x4d0 [cifs]
+[12537.775607]        cifs_reconnect+0xe04/0x2500 [cifs]
+[12537.798322]        cifs_readv_from_socket+0x461/0x690 [cifs]
+[12537.823369]        cifs_read_from_socket+0xa0/0xe0 [cifs]
+[12537.847262]        cifs_demultiplex_thread+0x311/0x2db0 [cifs]
+[12537.873477]        kthread+0x30c/0x3d0
+[12537.890281]        ret_from_fork+0x3a/0x50
+[12537.908649]
+[12537.908649] -> #1 (&tcp_ses->srv_mutex){+.+.}:
+[12537.935225]        __mutex_lock+0x105/0x11f0
+[12537.954450]        cifs_call_async+0x102/0x7f0 [cifs]
+[12537.977250]        smb2_async_readv+0x6c3/0xc90 [cifs]
+[12538.000659]        cifs_readpages+0x120a/0x1e50 [cifs]
+[12538.023920]        read_pages+0xf5/0x560
+[12538.041583]        __do_page_cache_readahead+0x41d/0x4b0
+[12538.067047]        ondemand_readahead+0x44c/0xc10
+[12538.092069]        filemap_fault+0xec1/0x1830
+[12538.111637]        __do_fault+0x82/0x260
+[12538.129216]        do_fault+0x419/0xfb0
+[12538.146390]        __handle_mm_fault+0x862/0xdf0
+[12538.167408]        handle_mm_fault+0x154/0x550
+[12538.187401]        __do_page_fault+0x42f/0xa60
+[12538.207395]        do_page_fault+0x38/0x5e0
+[12538.225777]        page_fault+0x1e/0x30
+[12538.243010]
+[12538.243010] -> #0 (&mm->mmap_sem){++++}:
+[12538.267875]        lock_acquire+0x14c/0x420
+[12538.286848]        __might_fault+0x119/0x1b0
+[12538.306006]        keyring_read_iterator+0x7e/0x170
+[12538.327936]        assoc_array_subtree_iterate+0x97/0x280
+[12538.352154]        keyring_read+0xe9/0x110
+[12538.370558]        keyctl_read_key+0x1b9/0x220
+[12538.391470]        do_syscall_64+0xa5/0x4b0
+[12538.410511]        entry_SYSCALL_64_after_hwframe+0x6a/0xdf
+[12538.435535]
+[12538.435535] other info that might help us debug this:
+[12538.435535]
+[12538.472829] Chain exists of:
+[12538.472829]   &mm->mmap_sem --> root_key_user.cons_lock --> &type->lock_class
+[12538.472829]
+[12538.524820]  Possible unsafe locking scenario:
+[12538.524820]
+[12538.551431]        CPU0                    CPU1
+[12538.572654]        ----                    ----
+[12538.595865]   lock(&type->lock_class);
+[12538.613737]                                lock(root_key_user.cons_lock);
+[12538.644234]                                lock(&type->lock_class);
+[12538.672410]   lock(&mm->mmap_sem);
+[12538.687758]
+[12538.687758]  *** DEADLOCK ***
+[12538.687758]
+[12538.714455] 1 lock held by keyctl/25598:
+[12538.732097]  #0: 000000003de5b58d (&type->lock_class){++++}, at: keyctl_read_key+0x15a/0x220
+[12538.770573]
+[12538.770573] stack backtrace:
+[12538.790136] CPU: 2 PID: 25598 Comm: keyctl Kdump: loaded Tainted: G
+[12538.844855] Hardware name: HP ProLiant DL360 Gen9/ProLiant DL360 Gen9, BIOS P89 12/27/2015
+[12538.881963] Call Trace:
+[12538.892897]  dump_stack+0x9a/0xf0
+[12538.907908]  print_circular_bug.isra.25.cold.50+0x1bc/0x279
+[12538.932891]  ? save_trace+0xd6/0x250
+[12538.948979]  check_prev_add.constprop.32+0xc36/0x14f0
+[12538.971643]  ? keyring_compare_object+0x104/0x190
+[12538.992738]  ? check_usage+0x550/0x550
+[12539.009845]  ? sched_clock+0x5/0x10
+[12539.025484]  ? sched_clock_cpu+0x18/0x1e0
+[12539.043555]  __lock_acquire+0x1f12/0x38d0
+[12539.061551]  ? trace_hardirqs_on+0x10/0x10
+[12539.080554]  lock_acquire+0x14c/0x420
+[12539.100330]  ? __might_fault+0xc4/0x1b0
+[12539.119079]  __might_fault+0x119/0x1b0
+[12539.135869]  ? __might_fault+0xc4/0x1b0
+[12539.153234]  keyring_read_iterator+0x7e/0x170
+[12539.172787]  ? keyring_read+0x110/0x110
+[12539.190059]  assoc_array_subtree_iterate+0x97/0x280
+[12539.211526]  keyring_read+0xe9/0x110
+[12539.227561]  ? keyring_gc_check_iterator+0xc0/0xc0
+[12539.249076]  keyctl_read_key+0x1b9/0x220
+[12539.266660]  do_syscall_64+0xa5/0x4b0
+[12539.283091]  entry_SYSCALL_64_after_hwframe+0x6a/0xdf
+
+One way to prevent this deadlock scenario from happening is to not
+allow writing to userspace while holding the key semaphore. Instead,
+an internal buffer is allocated for getting the keys out from the
+read method first before copying them out to userspace without holding
+the lock.
+
+That requires taking out the __user modifier from all the relevant
+read methods as well as additional changes to not use any userspace
+write helpers. That is,
+
+  1) The put_user() call is replaced by a direct copy.
+  2) The copy_to_user() call is replaced by memcpy().
+  3) All the fault handling code is removed.
+
+Compiling on a x86-64 system, the size of the rxrpc_read() function is
+reduced from 3795 bytes to 2384 bytes with this patch.
+
+Fixes: ^1da177e4c3f4 ("Linux-2.6.12-rc2")
+Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Signed-off-by: Waiman Long <longman@redhat.com>
+Signed-off-by: David Howells <dhowells@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/keys/big_key-type.h              |    2 
+ include/keys/user-type.h                 |    3 -
+ include/linux/key-type.h                 |    2 
+ net/dns_resolver/dns_key.c               |    2 
+ net/rxrpc/key.c                          |   27 +++--------
+ security/keys/big_key.c                  |   11 +---
+ security/keys/encrypted-keys/encrypted.c |    7 +-
+ security/keys/keyctl.c                   |   73 ++++++++++++++++++++++++-------
+ security/keys/keyring.c                  |    6 --
+ security/keys/request_key_auth.c         |    7 +-
+ security/keys/trusted.c                  |   14 -----
+ security/keys/user_defined.c             |    5 --
+ 12 files changed, 85 insertions(+), 74 deletions(-)
+
+--- a/include/keys/big_key-type.h
++++ b/include/keys/big_key-type.h
+@@ -21,6 +21,6 @@ extern void big_key_free_preparse(struct
+ extern void big_key_revoke(struct key *key);
+ extern void big_key_destroy(struct key *key);
+ extern void big_key_describe(const struct key *big_key, struct seq_file *m);
+-extern long big_key_read(const struct key *key, char __user *buffer, size_t buflen);
++extern long big_key_read(const struct key *key, char *buffer, size_t buflen);
+ #endif /* _KEYS_BIG_KEY_TYPE_H */
+--- a/include/keys/user-type.h
++++ b/include/keys/user-type.h
+@@ -45,8 +45,7 @@ extern int user_update(struct key *key,
+ extern void user_revoke(struct key *key);
+ extern void user_destroy(struct key *key);
+ extern void user_describe(const struct key *user, struct seq_file *m);
+-extern long user_read(const struct key *key,
+-                    char __user *buffer, size_t buflen);
++extern long user_read(const struct key *key, char *buffer, size_t buflen);
+ static inline const struct user_key_payload *user_key_payload_rcu(const struct key *key)
+ {
+--- a/include/linux/key-type.h
++++ b/include/linux/key-type.h
+@@ -125,7 +125,7 @@ struct key_type {
+        *   much is copied into the buffer
+        * - shouldn't do the copy if the buffer is NULL
+        */
+-      long (*read)(const struct key *key, char __user *buffer, size_t buflen);
++      long (*read)(const struct key *key, char *buffer, size_t buflen);
+       /* handle request_key() for this type instead of invoking
+        * /sbin/request-key (optional)
+--- a/net/dns_resolver/dns_key.c
++++ b/net/dns_resolver/dns_key.c
+@@ -241,7 +241,7 @@ static void dns_resolver_describe(const
+  * - the key's semaphore is read-locked
+  */
+ static long dns_resolver_read(const struct key *key,
+-                            char __user *buffer, size_t buflen)
++                            char *buffer, size_t buflen)
+ {
+       int err = PTR_ERR(key->payload.data[dns_key_error]);
+--- a/net/rxrpc/key.c
++++ b/net/rxrpc/key.c
+@@ -35,7 +35,7 @@ static void rxrpc_free_preparse_s(struct
+ static void rxrpc_destroy(struct key *);
+ static void rxrpc_destroy_s(struct key *);
+ static void rxrpc_describe(const struct key *, struct seq_file *);
+-static long rxrpc_read(const struct key *, char __user *, size_t);
++static long rxrpc_read(const struct key *, char *, size_t);
+ /*
+  * rxrpc defined keys take an arbitrary string as the description and an
+@@ -1044,12 +1044,12 @@ EXPORT_SYMBOL(rxrpc_get_null_key);
+  * - this returns the result in XDR form
+  */
+ static long rxrpc_read(const struct key *key,
+-                     char __user *buffer, size_t buflen)
++                     char *buffer, size_t buflen)
+ {
+       const struct rxrpc_key_token *token;
+       const struct krb5_principal *princ;
+       size_t size;
+-      __be32 __user *xdr, *oldxdr;
++      __be32 *xdr, *oldxdr;
+       u32 cnlen, toksize, ntoks, tok, zero;
+       u16 toksizes[AFSTOKEN_MAX];
+       int loop;
+@@ -1126,30 +1126,25 @@ static long rxrpc_read(const struct key
+       if (!buffer || buflen < size)
+               return size;
+-      xdr = (__be32 __user *) buffer;
++      xdr = (__be32 *)buffer;
+       zero = 0;
+ #define ENCODE(x)                             \
+       do {                                    \
+-              __be32 y = htonl(x);            \
+-              if (put_user(y, xdr++) < 0)     \
+-                      goto fault;             \
++              *xdr++ = htonl(x);              \
+       } while(0)
+ #define ENCODE_DATA(l, s)                                             \
+       do {                                                            \
+               u32 _l = (l);                                           \
+               ENCODE(l);                                              \
+-              if (copy_to_user(xdr, (s), _l) != 0)                    \
+-                      goto fault;                                     \
+-              if (_l & 3 &&                                           \
+-                  copy_to_user((u8 __user *)xdr + _l, &zero, 4 - (_l & 3)) != 0) \
+-                      goto fault;                                     \
++              memcpy(xdr, (s), _l);                                   \
++              if (_l & 3)                                             \
++                      memcpy((u8 *)xdr + _l, &zero, 4 - (_l & 3));    \
+               xdr += (_l + 3) >> 2;                                   \
+       } while(0)
+ #define ENCODE64(x)                                   \
+       do {                                            \
+               __be64 y = cpu_to_be64(x);              \
+-              if (copy_to_user(xdr, &y, 8) != 0)      \
+-                      goto fault;                     \
++              memcpy(xdr, &y, 8);                     \
+               xdr += 8 >> 2;                          \
+       } while(0)
+ #define ENCODE_STR(s)                         \
+@@ -1240,8 +1235,4 @@ static long rxrpc_read(const struct key
+       ASSERTCMP((char __user *) xdr - buffer, ==, size);
+       _leave(" = %zu", size);
+       return size;
+-
+-fault:
+-      _leave(" = -EFAULT");
+-      return -EFAULT;
+ }
+--- a/security/keys/big_key.c
++++ b/security/keys/big_key.c
+@@ -356,7 +356,7 @@ void big_key_describe(const struct key *
+  * read the key data
+  * - the key's semaphore is read-locked
+  */
+-long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
++long big_key_read(const struct key *key, char *buffer, size_t buflen)
+ {
+       size_t datalen = (size_t)key->payload.data[big_key_len];
+       long ret;
+@@ -395,9 +395,8 @@ long big_key_read(const struct key *key,
+               ret = datalen;
+-              /* copy decrypted data to user */
+-              if (copy_to_user(buffer, buf->virt, datalen) != 0)
+-                      ret = -EFAULT;
++              /* copy out decrypted data */
++              memcpy(buffer, buf->virt, datalen);
+ err_fput:
+               fput(file);
+@@ -405,9 +404,7 @@ error:
+               big_key_free_buffer(buf);
+       } else {
+               ret = datalen;
+-              if (copy_to_user(buffer, key->payload.data[big_key_data],
+-                               datalen) != 0)
+-                      ret = -EFAULT;
++              memcpy(buffer, key->payload.data[big_key_data], datalen);
+       }
+       return ret;
+--- a/security/keys/encrypted-keys/encrypted.c
++++ b/security/keys/encrypted-keys/encrypted.c
+@@ -895,14 +895,14 @@ out:
+ }
+ /*
+- * encrypted_read - format and copy the encrypted data to userspace
++ * encrypted_read - format and copy out the encrypted data
+  *
+  * The resulting datablob format is:
+  * <master-key name> <decrypted data length> <encrypted iv> <encrypted data>
+  *
+  * On success, return to userspace the encrypted key datablob size.
+  */
+-static long encrypted_read(const struct key *key, char __user *buffer,
++static long encrypted_read(const struct key *key, char *buffer,
+                          size_t buflen)
+ {
+       struct encrypted_key_payload *epayload;
+@@ -950,8 +950,7 @@ static long encrypted_read(const struct
+       key_put(mkey);
+       memzero_explicit(derived_key, sizeof(derived_key));
+-      if (copy_to_user(buffer, ascii_buf, asciiblob_len) != 0)
+-              ret = -EFAULT;
++      memcpy(buffer, ascii_buf, asciiblob_len);
+       kzfree(ascii_buf);
+       return asciiblob_len;
+--- a/security/keys/keyctl.c
++++ b/security/keys/keyctl.c
+@@ -743,6 +743,21 @@ error:
+ }
+ /*
++ * Call the read method
++ */
++static long __keyctl_read_key(struct key *key, char *buffer, size_t buflen)
++{
++      long ret;
++
++      down_read(&key->sem);
++      ret = key_validate(key);
++      if (ret == 0)
++              ret = key->type->read(key, buffer, buflen);
++      up_read(&key->sem);
++      return ret;
++}
++
++/*
+  * Read a key's payload.
+  *
+  * The key must either grant the caller Read permission, or it must grant the
+@@ -757,26 +772,27 @@ long keyctl_read_key(key_serial_t keyid,
+       struct key *key;
+       key_ref_t key_ref;
+       long ret;
++      char *key_data;
+       /* find the key first */
+       key_ref = lookup_user_key(keyid, 0, 0);
+       if (IS_ERR(key_ref)) {
+               ret = -ENOKEY;
+-              goto error;
++              goto out;
+       }
+       key = key_ref_to_ptr(key_ref);
+       ret = key_read_state(key);
+       if (ret < 0)
+-              goto error2; /* Negatively instantiated */
++              goto key_put_out; /* Negatively instantiated */
+       /* see if we can read it directly */
+       ret = key_permission(key_ref, KEY_NEED_READ);
+       if (ret == 0)
+               goto can_read_key;
+       if (ret != -EACCES)
+-              goto error2;
++              goto key_put_out;
+       /* we can't; see if it's searchable from this process's keyrings
+        * - we automatically take account of the fact that it may be
+@@ -784,26 +800,51 @@ long keyctl_read_key(key_serial_t keyid,
+        */
+       if (!is_key_possessed(key_ref)) {
+               ret = -EACCES;
+-              goto error2;
++              goto key_put_out;
+       }
+       /* the key is probably readable - now try to read it */
+ can_read_key:
+-      ret = -EOPNOTSUPP;
+-      if (key->type->read) {
+-              /* Read the data with the semaphore held (since we might sleep)
+-               * to protect against the key being updated or revoked.
+-               */
+-              down_read(&key->sem);
+-              ret = key_validate(key);
+-              if (ret == 0)
+-                      ret = key->type->read(key, buffer, buflen);
+-              up_read(&key->sem);
++      if (!key->type->read) {
++              ret = -EOPNOTSUPP;
++              goto key_put_out;
++      }
++
++      if (!buffer || !buflen) {
++              /* Get the key length from the read method */
++              ret = __keyctl_read_key(key, NULL, 0);
++              goto key_put_out;
++      }
++
++      /*
++       * Read the data with the semaphore held (since we might sleep)
++       * to protect against the key being updated or revoked.
++       *
++       * Allocating a temporary buffer to hold the keys before
++       * transferring them to user buffer to avoid potential
++       * deadlock involving page fault and mmap_sem.
++       */
++      key_data = kmalloc(buflen, GFP_KERNEL);
++
++      if (!key_data) {
++              ret = -ENOMEM;
++              goto key_put_out;
++      }
++      ret = __keyctl_read_key(key, key_data, buflen);
++
++      /*
++       * Read methods will just return the required length without
++       * any copying if the provided length isn't large enough.
++       */
++      if (ret > 0 && ret <= buflen) {
++              if (copy_to_user(buffer, key_data, ret))
++                      ret = -EFAULT;
+       }
++      kzfree(key_data);
+-error2:
++key_put_out:
+       key_put(key);
+-error:
++out:
+       return ret;
+ }
+--- a/security/keys/keyring.c
++++ b/security/keys/keyring.c
+@@ -432,7 +432,6 @@ static int keyring_read_iterator(const v
+ {
+       struct keyring_read_iterator_context *ctx = data;
+       const struct key *key = keyring_ptr_to_key(object);
+-      int ret;
+       kenter("{%s,%d},,{%zu/%zu}",
+              key->type->name, key->serial, ctx->count, ctx->buflen);
+@@ -440,10 +439,7 @@ static int keyring_read_iterator(const v
+       if (ctx->count >= ctx->buflen)
+               return 1;
+-      ret = put_user(key->serial, ctx->buffer);
+-      if (ret < 0)
+-              return ret;
+-      ctx->buffer++;
++      *ctx->buffer++ = key->serial;
+       ctx->count += sizeof(key->serial);
+       return 0;
+ }
+--- a/security/keys/request_key_auth.c
++++ b/security/keys/request_key_auth.c
+@@ -27,7 +27,7 @@ static int request_key_auth_instantiate(
+ static void request_key_auth_describe(const struct key *, struct seq_file *);
+ static void request_key_auth_revoke(struct key *);
+ static void request_key_auth_destroy(struct key *);
+-static long request_key_auth_read(const struct key *, char __user *, size_t);
++static long request_key_auth_read(const struct key *, char *, size_t);
+ /*
+  * The request-key authorisation key type definition.
+@@ -85,7 +85,7 @@ static void request_key_auth_describe(co
+  * - the key's semaphore is read-locked
+  */
+ static long request_key_auth_read(const struct key *key,
+-                                char __user *buffer, size_t buflen)
++                                char *buffer, size_t buflen)
+ {
+       struct request_key_auth *rka = get_request_key_auth(key);
+       size_t datalen;
+@@ -102,8 +102,7 @@ static long request_key_auth_read(const
+               if (buflen > datalen)
+                       buflen = datalen;
+-              if (copy_to_user(buffer, rka->callout_info, buflen) != 0)
+-                      ret = -EFAULT;
++              memcpy(buffer, rka->callout_info, buflen);
+       }
+       return ret;
+--- a/security/keys/trusted.c
++++ b/security/keys/trusted.c
+@@ -1135,11 +1135,10 @@ out:
+  * trusted_read - copy the sealed blob data to userspace in hex.
+  * On success, return to userspace the trusted key datablob size.
+  */
+-static long trusted_read(const struct key *key, char __user *buffer,
++static long trusted_read(const struct key *key, char *buffer,
+                        size_t buflen)
+ {
+       const struct trusted_key_payload *p;
+-      char *ascii_buf;
+       char *bufp;
+       int i;
+@@ -1148,18 +1147,9 @@ static long trusted_read(const struct ke
+               return -EINVAL;
+       if (buffer && buflen >= 2 * p->blob_len) {
+-              ascii_buf = kmalloc_array(2, p->blob_len, GFP_KERNEL);
+-              if (!ascii_buf)
+-                      return -ENOMEM;
+-
+-              bufp = ascii_buf;
++              bufp = buffer;
+               for (i = 0; i < p->blob_len; i++)
+                       bufp = hex_byte_pack(bufp, p->blob[i]);
+-              if (copy_to_user(buffer, ascii_buf, 2 * p->blob_len) != 0) {
+-                      kzfree(ascii_buf);
+-                      return -EFAULT;
+-              }
+-              kzfree(ascii_buf);
+       }
+       return 2 * p->blob_len;
+ }
+--- a/security/keys/user_defined.c
++++ b/security/keys/user_defined.c
+@@ -172,7 +172,7 @@ EXPORT_SYMBOL_GPL(user_describe);
+  * read the key data
+  * - the key's semaphore is read-locked
+  */
+-long user_read(const struct key *key, char __user *buffer, size_t buflen)
++long user_read(const struct key *key, char *buffer, size_t buflen)
+ {
+       const struct user_key_payload *upayload;
+       long ret;
+@@ -185,8 +185,7 @@ long user_read(const struct key *key, ch
+               if (buflen > upayload->datalen)
+                       buflen = upayload->datalen;
+-              if (copy_to_user(buffer, upayload->data, buflen) != 0)
+-                      ret = -EFAULT;
++              memcpy(buffer, upayload->data, buflen);
+       }
+       return ret;
diff --git a/queue-4.19/locktorture-print-ratio-of-acquisitions-not-failures.patch b/queue-4.19/locktorture-print-ratio-of-acquisitions-not-failures.patch
new file mode 100644 (file)
index 0000000..90f0de6
--- /dev/null
@@ -0,0 +1,50 @@
+From 80c503e0e68fbe271680ab48f0fe29bc034b01b7 Mon Sep 17 00:00:00 2001
+From: "Paul E. McKenney" <paulmck@kernel.org>
+Date: Thu, 23 Jan 2020 09:19:01 -0800
+Subject: locktorture: Print ratio of acquisitions, not failures
+
+From: Paul E. McKenney <paulmck@kernel.org>
+
+commit 80c503e0e68fbe271680ab48f0fe29bc034b01b7 upstream.
+
+The __torture_print_stats() function in locktorture.c carefully
+initializes local variable "min" to statp[0].n_lock_acquired, but
+then compares it to statp[i].n_lock_fail.  Given that the .n_lock_fail
+field should normally be zero, and given the initialization, it seems
+reasonable to display the maximum and minimum number acquisitions
+instead of miscomputing the maximum and minimum number of failures.
+This commit therefore switches from failures to acquisitions.
+
+And this turns out to be not only a day-zero bug, but entirely my
+own fault.  I hate it when that happens!
+
+Fixes: 0af3fe1efa53 ("locktorture: Add a lock-torture kernel module")
+Reported-by: Will Deacon <will@kernel.org>
+Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
+Acked-by: Will Deacon <will@kernel.org>
+Cc: Davidlohr Bueso <dave@stgolabs.net>
+Cc: Josh Triplett <josh@joshtriplett.org>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ kernel/locking/locktorture.c |    8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+--- a/kernel/locking/locktorture.c
++++ b/kernel/locking/locktorture.c
+@@ -710,10 +710,10 @@ static void __torture_print_stats(char *
+               if (statp[i].n_lock_fail)
+                       fail = true;
+               sum += statp[i].n_lock_acquired;
+-              if (max < statp[i].n_lock_fail)
+-                      max = statp[i].n_lock_fail;
+-              if (min > statp[i].n_lock_fail)
+-                      min = statp[i].n_lock_fail;
++              if (max < statp[i].n_lock_acquired)
++                      max = statp[i].n_lock_acquired;
++              if (min > statp[i].n_lock_acquired)
++                      min = statp[i].n_lock_acquired;
+       }
+       page += sprintf(page,
+                       "%s:  Total: %lld  Max/Min: %ld/%ld %s  Fail: %d %s\n",
diff --git a/queue-4.19/mtd-lpddr-fix-a-double-free-in-probe.patch b/queue-4.19/mtd-lpddr-fix-a-double-free-in-probe.patch
new file mode 100644 (file)
index 0000000..3ea2b58
--- /dev/null
@@ -0,0 +1,33 @@
+From 4da0ea71ea934af18db4c63396ba2af1a679ef02 Mon Sep 17 00:00:00 2001
+From: Dan Carpenter <dan.carpenter@oracle.com>
+Date: Fri, 28 Feb 2020 12:25:54 +0300
+Subject: mtd: lpddr: Fix a double free in probe()
+
+From: Dan Carpenter <dan.carpenter@oracle.com>
+
+commit 4da0ea71ea934af18db4c63396ba2af1a679ef02 upstream.
+
+This function is only called from lpddr_probe().  We free "lpddr" both
+here and in the caller, so it's a double free.  The best place to free
+"lpddr" is in lpddr_probe() so let's delete this one.
+
+Fixes: 8dc004395d5e ("[MTD] LPDDR qinfo probing.")
+Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+Link: https://lore.kernel.org/linux-mtd/20200228092554.o57igp3nqhyvf66t@kili.mountain
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/mtd/lpddr/lpddr_cmds.c |    1 -
+ 1 file changed, 1 deletion(-)
+
+--- a/drivers/mtd/lpddr/lpddr_cmds.c
++++ b/drivers/mtd/lpddr/lpddr_cmds.c
+@@ -81,7 +81,6 @@ struct mtd_info *lpddr_cmdset(struct map
+       shared = kmalloc_array(lpddr->numchips, sizeof(struct flchip_shared),
+                                               GFP_KERNEL);
+       if (!shared) {
+-              kfree(lpddr);
+               kfree(mtd);
+               return NULL;
+       }
diff --git a/queue-4.19/mtd-phram-fix-a-double-free-issue-in-error-path.patch b/queue-4.19/mtd-phram-fix-a-double-free-issue-in-error-path.patch
new file mode 100644 (file)
index 0000000..6fbb74c
--- /dev/null
@@ -0,0 +1,64 @@
+From 49c64df880570034308e4a9a49c4bc95cf8cdb33 Mon Sep 17 00:00:00 2001
+From: Wen Yang <wenyang@linux.alibaba.com>
+Date: Wed, 18 Mar 2020 23:31:56 +0800
+Subject: mtd: phram: fix a double free issue in error path
+
+From: Wen Yang <wenyang@linux.alibaba.com>
+
+commit 49c64df880570034308e4a9a49c4bc95cf8cdb33 upstream.
+
+The variable 'name' is released multiple times in the error path,
+which may cause double free issues.
+This problem is avoided by adding a goto label to release the memory
+uniformly. And this change also makes the code a bit more cleaner.
+
+Fixes: 4f678a58d335 ("mtd: fix memory leaks in phram_setup")
+Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
+Cc: Joern Engel <joern@lazybastard.org>
+Cc: Miquel Raynal <miquel.raynal@bootlin.com>
+Cc: Richard Weinberger <richard@nod.at>
+Cc: Vignesh Raghavendra <vigneshr@ti.com>
+Cc: linux-mtd@lists.infradead.org
+Cc: linux-kernel@vger.kernel.org
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+Link: https://lore.kernel.org/linux-mtd/20200318153156.25612-1-wenyang@linux.alibaba.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/mtd/devices/phram.c |   15 +++++++++------
+ 1 file changed, 9 insertions(+), 6 deletions(-)
+
+--- a/drivers/mtd/devices/phram.c
++++ b/drivers/mtd/devices/phram.c
+@@ -240,22 +240,25 @@ static int phram_setup(const char *val)
+       ret = parse_num64(&start, token[1]);
+       if (ret) {
+-              kfree(name);
+               parse_err("illegal start address\n");
++              goto error;
+       }
+       ret = parse_num64(&len, token[2]);
+       if (ret) {
+-              kfree(name);
+               parse_err("illegal device length\n");
++              goto error;
+       }
+       ret = register_device(name, start, len);
+-      if (!ret)
+-              pr_info("%s device: %#llx at %#llx\n", name, len, start);
+-      else
+-              kfree(name);
++      if (ret)
++              goto error;
++      pr_info("%s device: %#llx at %#llx\n", name, len, start);
++      return 0;
++
++error:
++      kfree(name);
+       return ret;
+ }
diff --git a/queue-4.19/mtd-spinand-explicitly-use-mtd_ops_raw-to-write-the-bad-block-marker-to-oob.patch b/queue-4.19/mtd-spinand-explicitly-use-mtd_ops_raw-to-write-the-bad-block-marker-to-oob.patch
new file mode 100644 (file)
index 0000000..24ce954
--- /dev/null
@@ -0,0 +1,38 @@
+From 621a7b780bd8b7054647d53d5071961f2c9e0873 Mon Sep 17 00:00:00 2001
+From: Frieder Schrempf <frieder.schrempf@kontron.de>
+Date: Tue, 18 Feb 2020 10:05:25 +0000
+Subject: mtd: spinand: Explicitly use MTD_OPS_RAW to write the bad block marker to OOB
+
+From: Frieder Schrempf <frieder.schrempf@kontron.de>
+
+commit 621a7b780bd8b7054647d53d5071961f2c9e0873 upstream.
+
+When writing the bad block marker to the OOB area the access mode
+should be set to MTD_OPS_RAW as it is done for reading the marker.
+Currently this only works because req.mode is initialized to
+MTD_OPS_PLACE_OOB (0) and spinand_write_to_cache_op() checks for
+req.mode != MTD_OPS_AUTO_OOB.
+
+Fix this by explicitly setting req.mode to MTD_OPS_RAW.
+
+Fixes: 7529df465248 ("mtd: nand: Add core infrastructure to support SPI NANDs")
+Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
+Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+Link: https://lore.kernel.org/linux-mtd/20200218100432.32433-3-frieder.schrempf@kontron.de
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/mtd/nand/spi/core.c |    1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/mtd/nand/spi/core.c
++++ b/drivers/mtd/nand/spi/core.c
+@@ -670,6 +670,7 @@ static int spinand_markbad(struct nand_d
+               .ooboffs = 0,
+               .ooblen = sizeof(marker),
+               .oobbuf.out = marker,
++              .mode = MTD_OPS_RAW,
+       };
+       int ret;
diff --git a/queue-4.19/net-dsa-bcm_sf2-fix-overflow-checks.patch b/queue-4.19/net-dsa-bcm_sf2-fix-overflow-checks.patch
new file mode 100644 (file)
index 0000000..e3740b0
--- /dev/null
@@ -0,0 +1,59 @@
+From d0802dc411f469569a537283b6f3833af47aece9 Mon Sep 17 00:00:00 2001
+From: Florian Fainelli <f.fainelli@gmail.com>
+Date: Mon, 30 Mar 2020 14:38:46 -0700
+Subject: net: dsa: bcm_sf2: Fix overflow checks
+
+From: Florian Fainelli <f.fainelli@gmail.com>
+
+commit d0802dc411f469569a537283b6f3833af47aece9 upstream.
+
+Commit f949a12fd697 ("net: dsa: bcm_sf2: fix buffer overflow doing
+set_rxnfc") tried to fix the some user controlled buffer overflows in
+bcm_sf2_cfp_rule_set() and bcm_sf2_cfp_rule_del() but the fix was using
+CFP_NUM_RULES, which while it is correct not to overflow the bitmaps, is
+not representative of what the device actually supports. Correct that by
+using bcm_sf2_cfp_rule_size() instead.
+
+The latter subtracts the number of rules by 1, so change the checks from
+greater than or equal to greater than accordingly.
+
+Fixes: f949a12fd697 ("net: dsa: bcm_sf2: fix buffer overflow doing set_rxnfc")
+Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/net/dsa/bcm_sf2_cfp.c |    9 +++------
+ 1 file changed, 3 insertions(+), 6 deletions(-)
+
+--- a/drivers/net/dsa/bcm_sf2_cfp.c
++++ b/drivers/net/dsa/bcm_sf2_cfp.c
+@@ -742,17 +742,14 @@ static int bcm_sf2_cfp_rule_set(struct d
+            fs->m_ext.data[1]))
+               return -EINVAL;
+-      if (fs->location != RX_CLS_LOC_ANY && fs->location >= CFP_NUM_RULES)
++      if (fs->location != RX_CLS_LOC_ANY &&
++          fs->location > bcm_sf2_cfp_rule_size(priv))
+               return -EINVAL;
+       if (fs->location != RX_CLS_LOC_ANY &&
+           test_bit(fs->location, priv->cfp.used))
+               return -EBUSY;
+-      if (fs->location != RX_CLS_LOC_ANY &&
+-          fs->location > bcm_sf2_cfp_rule_size(priv))
+-              return -EINVAL;
+-
+       /* This rule is a Wake-on-LAN filter and we must specifically
+        * target the CPU port in order for it to be working.
+        */
+@@ -839,7 +836,7 @@ static int bcm_sf2_cfp_rule_del(struct b
+       u32 next_loc = 0;
+       int ret;
+-      if (loc >= CFP_NUM_RULES)
++      if (loc > bcm_sf2_cfp_rule_size(priv))
+               return -EINVAL;
+       /* Refuse deleting unused rules, and those that are not unique since
index c61e968dcda68273686d9b201dec54ae153c546e..e8e9251046ef1d3a4cb6e480de445f07577ee09d 100644 (file)
@@ -52,3 +52,13 @@ power-supply-axp288_fuel_gauge-broaden-vendor-check-.patch
 libnvdimm-out-of-bounds-read-in-__nd_ioctl.patch
 iommu-amd-fix-the-configuration-of-gcr3-table-root-p.patch
 f2fs-fix-to-wait-all-node-page-writeback.patch
+net-dsa-bcm_sf2-fix-overflow-checks.patch
+fbdev-potential-information-leak-in-do_fb_ioctl.patch
+iio-si1133-read-24-bit-signed-integer-for-measurement.patch
+tty-evh_bytechan-fix-out-of-bounds-accesses.patch
+locktorture-print-ratio-of-acquisitions-not-failures.patch
+mtd-spinand-explicitly-use-mtd_ops_raw-to-write-the-bad-block-marker-to-oob.patch
+mtd-lpddr-fix-a-double-free-in-probe.patch
+mtd-phram-fix-a-double-free-issue-in-error-path.patch
+keys-don-t-write-out-to-userspace-while-holding-key-semaphore.patch
+bpf-fix-buggy-r0-retval-refinement-for-tracing-helpers.patch
diff --git a/queue-4.19/tty-evh_bytechan-fix-out-of-bounds-accesses.patch b/queue-4.19/tty-evh_bytechan-fix-out-of-bounds-accesses.patch
new file mode 100644 (file)
index 0000000..cc5a710
--- /dev/null
@@ -0,0 +1,111 @@
+From 3670664b5da555a2a481449b3baafff113b0ac35 Mon Sep 17 00:00:00 2001
+From: Stephen Rothwell <sfr@canb.auug.org.au>
+Date: Thu, 9 Jan 2020 18:39:12 +1100
+Subject: tty: evh_bytechan: Fix out of bounds accesses
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Stephen Rothwell <sfr@canb.auug.org.au>
+
+commit 3670664b5da555a2a481449b3baafff113b0ac35 upstream.
+
+ev_byte_channel_send() assumes that its third argument is a 16 byte
+array. Some places where it is called it may not be (or we can't
+easily tell if it is). Newer compilers have started producing warnings
+about this, so make sure we actually pass a 16 byte array.
+
+There may be more elegant solutions to this, but the driver is quite
+old and hasn't been updated in many years.
+
+The warnings (from a powerpc allyesconfig build) are:
+
+  In file included from include/linux/byteorder/big_endian.h:5,
+                   from arch/powerpc/include/uapi/asm/byteorder.h:14,
+                   from include/asm-generic/bitops/le.h:6,
+                   from arch/powerpc/include/asm/bitops.h:250,
+                   from include/linux/bitops.h:29,
+                   from include/linux/kernel.h:12,
+                   from include/asm-generic/bug.h:19,
+                   from arch/powerpc/include/asm/bug.h:109,
+                   from include/linux/bug.h:5,
+                   from include/linux/mmdebug.h:5,
+                   from include/linux/gfp.h:5,
+                   from include/linux/slab.h:15,
+                   from drivers/tty/ehv_bytechan.c:24:
+  drivers/tty/ehv_bytechan.c: In function ‘ehv_bc_udbg_putc’:
+  arch/powerpc/include/asm/epapr_hcalls.h:298:20: warning: array subscript 1 is outside array bounds of ‘const char[1]’ [-Warray-bounds]
+    298 |  r6 = be32_to_cpu(p[1]);
+  include/uapi/linux/byteorder/big_endian.h:40:51: note: in definition of macro ‘__be32_to_cpu’
+     40 | #define __be32_to_cpu(x) ((__force __u32)(__be32)(x))
+        |                                                   ^
+  arch/powerpc/include/asm/epapr_hcalls.h:298:7: note: in expansion of macro ‘be32_to_cpu’
+    298 |  r6 = be32_to_cpu(p[1]);
+        |       ^~~~~~~~~~~
+  drivers/tty/ehv_bytechan.c:166:13: note: while referencing ‘data’
+    166 | static void ehv_bc_udbg_putc(char c)
+        |             ^~~~~~~~~~~~~~~~
+
+Fixes: dcd83aaff1c8 ("tty/powerpc: introduce the ePAPR embedded hypervisor byte channel driver")
+Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
+Tested-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
+[mpe: Trim warnings from change log]
+Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
+Link: https://lore.kernel.org/r/20200109183912.5fcb52aa@canb.auug.org.au
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/tty/ehv_bytechan.c |   21 ++++++++++++++++++---
+ 1 file changed, 18 insertions(+), 3 deletions(-)
+
+--- a/drivers/tty/ehv_bytechan.c
++++ b/drivers/tty/ehv_bytechan.c
+@@ -136,6 +136,21 @@ static int find_console_handle(void)
+       return 1;
+ }
++static unsigned int local_ev_byte_channel_send(unsigned int handle,
++                                             unsigned int *count,
++                                             const char *p)
++{
++      char buffer[EV_BYTE_CHANNEL_MAX_BYTES];
++      unsigned int c = *count;
++
++      if (c < sizeof(buffer)) {
++              memcpy(buffer, p, c);
++              memset(&buffer[c], 0, sizeof(buffer) - c);
++              p = buffer;
++      }
++      return ev_byte_channel_send(handle, count, p);
++}
++
+ /*************************** EARLY CONSOLE DRIVER ***************************/
+ #ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
+@@ -154,7 +169,7 @@ static void byte_channel_spin_send(const
+       do {
+               count = 1;
+-              ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
++              ret = local_ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
+                                          &count, &data);
+       } while (ret == EV_EAGAIN);
+ }
+@@ -221,7 +236,7 @@ static int ehv_bc_console_byte_channel_s
+       while (count) {
+               len = min_t(unsigned int, count, EV_BYTE_CHANNEL_MAX_BYTES);
+               do {
+-                      ret = ev_byte_channel_send(handle, &len, s);
++                      ret = local_ev_byte_channel_send(handle, &len, s);
+               } while (ret == EV_EAGAIN);
+               count -= len;
+               s += len;
+@@ -401,7 +416,7 @@ static void ehv_bc_tx_dequeue(struct ehv
+                           CIRC_CNT_TO_END(bc->head, bc->tail, BUF_SIZE),
+                           EV_BYTE_CHANNEL_MAX_BYTES);
+-              ret = ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail);
++              ret = local_ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail);
+               /* 'len' is valid only if the return code is 0 or EV_EAGAIN */
+               if (!ret || (ret == EV_EAGAIN))