]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.14-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jan 2024 10:37:08 +0000 (11:37 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jan 2024 10:37:08 +0000 (11:37 +0100)
added patches:
dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch
selftests-ftrace-add-new-test-case-which-checks-non-unique-symbol.patch
tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch

queue-4.14/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch [new file with mode: 0644]
queue-4.14/selftests-ftrace-add-new-test-case-which-checks-non-unique-symbol.patch [new file with mode: 0644]
queue-4.14/series
queue-4.14/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch [new file with mode: 0644]

diff --git a/queue-4.14/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch b/queue-4.14/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch
new file mode 100644 (file)
index 0000000..774110f
--- /dev/null
@@ -0,0 +1,66 @@
+From b86f4b790c998afdbc88fe1aa55cfe89c4068726 Mon Sep 17 00:00:00 2001
+From: Mikulas Patocka <mpatocka@redhat.com>
+Date: Tue, 5 Dec 2023 16:39:16 +0100
+Subject: dm-integrity: don't modify bio's immutable bio_vec in integrity_metadata()
+
+From: Mikulas Patocka <mpatocka@redhat.com>
+
+commit b86f4b790c998afdbc88fe1aa55cfe89c4068726 upstream.
+
+__bio_for_each_segment assumes that the first struct bio_vec argument
+doesn't change - it calls "bio_advance_iter_single((bio), &(iter),
+(bvl).bv_len)" to advance the iterator. Unfortunately, the dm-integrity
+code changes the bio_vec with "bv.bv_len -= pos". When this code path
+is taken, the iterator would be out of sync and dm-integrity would
+report errors. This happens if the machine is out of memory and
+"kmalloc" fails.
+
+Fix this bug by making a copy of "bv" and changing the copy instead.
+
+Fixes: 7eada909bfd7 ("dm: add integrity target")
+Cc: stable@vger.kernel.org     # v4.12+
+Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
+Signed-off-by: Mike Snitzer <snitzer@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/md/dm-integrity.c |   11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+--- a/drivers/md/dm-integrity.c
++++ b/drivers/md/dm-integrity.c
+@@ -1257,11 +1257,12 @@ static void integrity_metadata(struct wo
+                       checksums = checksums_onstack;
+               __bio_for_each_segment(bv, bio, iter, dio->orig_bi_iter) {
++                      struct bio_vec bv_copy = bv;
+                       unsigned pos;
+                       char *mem, *checksums_ptr;
+ again:
+-                      mem = (char *)kmap_atomic(bv.bv_page) + bv.bv_offset;
++                      mem = (char *)kmap_atomic(bv_copy.bv_page) + bv_copy.bv_offset;
+                       pos = 0;
+                       checksums_ptr = checksums;
+                       do {
+@@ -1270,7 +1271,7 @@ again:
+                               sectors_to_process -= ic->sectors_per_block;
+                               pos += ic->sectors_per_block << SECTOR_SHIFT;
+                               sector += ic->sectors_per_block;
+-                      } while (pos < bv.bv_len && sectors_to_process && checksums != checksums_onstack);
++                      } while (pos < bv_copy.bv_len && sectors_to_process && checksums != checksums_onstack);
+                       kunmap_atomic(mem);
+                       r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset,
+@@ -1290,9 +1291,9 @@ again:
+                       if (!sectors_to_process)
+                               break;
+-                      if (unlikely(pos < bv.bv_len)) {
+-                              bv.bv_offset += pos;
+-                              bv.bv_len -= pos;
++                      if (unlikely(pos < bv_copy.bv_len)) {
++                              bv_copy.bv_offset += pos;
++                              bv_copy.bv_len -= pos;
+                               goto again;
+                       }
+               }
diff --git a/queue-4.14/selftests-ftrace-add-new-test-case-which-checks-non-unique-symbol.patch b/queue-4.14/selftests-ftrace-add-new-test-case-which-checks-non-unique-symbol.patch
new file mode 100644 (file)
index 0000000..eba0fc5
--- /dev/null
@@ -0,0 +1,44 @@
+From stable+bounces-4746-greg=kroah.com@vger.kernel.org Tue Dec  5 19:29:59 2023
+From: Francis Laniel <flaniel@linux.microsoft.com>
+Date: Tue,  5 Dec 2023 19:29:23 +0100
+Subject: selftests/ftrace: Add new test case which checks non unique symbol
+To: stable@vger.kernel.org
+Cc: Greg KH <gregkh@linuxfoundation.org>, Francis Laniel <flaniel@linux.microsoft.com>, Masami Hiramatsu <mhiramat@kernel.org>
+Message-ID: <20231205182923.128898-2-flaniel@linux.microsoft.com>
+
+From: Francis Laniel <flaniel@linux.microsoft.com>
+
+Commit 03b80ff8023adae6780e491f66e932df8165e3a0 upstream.
+
+If name_show() is non unique, this test will try to install a kprobe on this
+function which should fail returning EADDRNOTAVAIL.
+On kernel where name_show() is not unique, this test is skipped.
+
+Link: https://lore.kernel.org/all/20231020104250.9537-3-flaniel@linux.microsoft.com/
+
+Cc: stable@vger.kernel.org
+Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
+Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc |   13 ++++++++++
+ 1 file changed, 13 insertions(+)
+ create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc
+
+--- /dev/null
++++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc
+@@ -0,0 +1,13 @@
++#!/bin/sh
++# SPDX-License-Identifier: GPL-2.0
++# description: Test failure of registering kprobe on non unique symbol
++# requires: kprobe_events
++
++SYMBOL='name_show'
++
++# We skip this test on kernel where SYMBOL is unique or does not exist.
++if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then
++      exit_unsupported
++fi
++
++! echo "p:test_non_unique ${SYMBOL}" > kprobe_events
index 476f6d3ae5ea8a1d75a3ec0a7d4fc4acc0f07f2a..c197a06808536d17f4142e1815dd8ca424978daf 100644 (file)
@@ -17,3 +17,6 @@ usb-serial-option-add-quectel-rm500q-r13-firmware-support.patch
 bluetooth-hci_event-fix-not-checking-if-hci_op_inquiry-has-been-sent.patch
 net-9p-avoid-freeing-uninit-memory-in-p9pdu_vreadf.patch
 net-rfkill-gpio-set-gpio-direction.patch
+dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch
+tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch
+selftests-ftrace-add-new-test-case-which-checks-non-unique-symbol.patch
diff --git a/queue-4.14/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch b/queue-4.14/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch
new file mode 100644 (file)
index 0000000..526228a
--- /dev/null
@@ -0,0 +1,102 @@
+From stable+bounces-4745-greg=kroah.com@vger.kernel.org Tue Dec  5 19:29:57 2023
+From: Francis Laniel <flaniel@linux.microsoft.com>
+Date: Tue,  5 Dec 2023 19:29:22 +0100
+Subject: tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols
+To: stable@vger.kernel.org
+Cc: Greg KH <gregkh@linuxfoundation.org>, Francis Laniel <flaniel@linux.microsoft.com>, Masami Hiramatsu <mhiramat@kernel.org>
+Message-ID: <20231205182923.128898-1-flaniel@linux.microsoft.com>
+
+From: Francis Laniel <flaniel@linux.microsoft.com>
+
+Commit b022f0c7e404887a7c5229788fc99eff9f9a80d5 upstream.
+
+When a kprobe is attached to a function that's name is not unique (is
+static and shares the name with other functions in the kernel), the
+kprobe is attached to the first function it finds. This is a bug as the
+function that it is attaching to is not necessarily the one that the
+user wants to attach to.
+
+Instead of blindly picking a function to attach to what is ambiguous,
+error with EADDRNOTAVAIL to let the user know that this function is not
+unique, and that the user must use another unique function with an
+address offset to get to the function they want to attach to.
+
+Link: https://lore.kernel.org/all/20231020104250.9537-2-flaniel@linux.microsoft.com/
+
+Cc: stable@vger.kernel.org
+Fixes: 413d37d1eb69 ("tracing: Add kprobe-based event tracer")
+Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
+Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
+Link: https://lore.kernel.org/lkml/20230819101105.b0c104ae4494a7d1f2eea742@kernel.org/
+Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
+(cherry picked from commit b022f0c7e404887a7c5229788fc99eff9f9a80d5)
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/trace/trace_kprobe.c |   48 ++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 48 insertions(+)
+
+--- a/kernel/trace/trace_kprobe.c
++++ b/kernel/trace/trace_kprobe.c
+@@ -617,6 +617,36 @@ static inline void sanitize_event_name(c
+                       *name = '_';
+ }
++struct count_symbols_struct {
++      const char *func_name;
++      unsigned int count;
++};
++
++static int count_symbols(void *data, const char *name, struct module *unused0,
++                       unsigned long unused1)
++{
++      struct count_symbols_struct *args = data;
++
++      if (strcmp(args->func_name, name))
++              return 0;
++
++      args->count++;
++
++      return 0;
++}
++
++static unsigned int number_of_same_symbols(char *func_name)
++{
++      struct count_symbols_struct args = {
++              .func_name = func_name,
++              .count = 0,
++      };
++
++      kallsyms_on_each_symbol(count_symbols, &args);
++
++      return args.count;
++}
++
+ static int create_trace_kprobe(int argc, char **argv)
+ {
+       /*
+@@ -746,6 +776,24 @@ static int create_trace_kprobe(int argc,
+       }
+       argc -= 2; argv += 2;
++      if (symbol && !strchr(symbol, ':')) {
++              unsigned int count;
++
++              count = number_of_same_symbols(symbol);
++              if (count > 1)
++                      /*
++                       * Users should use ADDR to remove the ambiguity of
++                       * using KSYM only.
++                       */
++                      return -EADDRNOTAVAIL;
++              else if (count == 0)
++                      /*
++                       * We can return ENOENT earlier than when register the
++                       * kprobe.
++                       */
++                      return -ENOENT;
++      }
++
+       /* setup a probe */
+       if (!event) {
+               /* Make a new event name */