]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.19-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jan 2024 10:36:22 +0000 (11:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Jan 2024 10:36:22 +0000 (11:36 +0100)
added patches:
dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch
tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch

queue-4.19/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch [new file with mode: 0644]
queue-4.19/series
queue-4.19/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch [new file with mode: 0644]

diff --git a/queue-4.19/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch b/queue-4.19/dm-integrity-don-t-modify-bio-s-immutable-bio_vec-in-integrity_metadata.patch
new file mode 100644 (file)
index 0000000..6c76b27
--- /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
+@@ -1379,11 +1379,12 @@ static void integrity_metadata(struct wo
+                       checksums = checksums_onstack;
+               __bio_for_each_segment(bv, bio, iter, dio->bio_details.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 {
+@@ -1392,7 +1393,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,
+@@ -1412,9 +1413,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;
+                       }
+               }
index 2df37ee435e3bfbaf20f246ba5fa5aa7b3b208d2..7c738aae0beb8eb5e5933f8fd158032d648e7995 100644 (file)
@@ -37,3 +37,5 @@ x86-alternatives-sync-core-before-enabling-interrupts.patch
 usb-musb-fix-musb_quirk_b_disconnect_99-handling.patch
 usb-fotg210-hcd-delete-an-incorrect-bounds-test.patch
 smb-client-fix-oob-in-smbcalcsize.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
diff --git a/queue-4.19/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch b/queue-4.19/tracing-kprobes-return-eaddrnotavail-when-func-matches-several-symbols.patch
new file mode 100644 (file)
index 0000000..c28089d
--- /dev/null
@@ -0,0 +1,98 @@
+From b022f0c7e404887a7c5229788fc99eff9f9a80d5 Mon Sep 17 00:00:00 2001
+From: Francis Laniel <flaniel@linux.microsoft.com>
+Date: Fri, 20 Oct 2023 13:42:49 +0300
+Subject: tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols
+
+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>
+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
+@@ -715,6 +715,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)
+ {
+       /*
+@@ -845,6 +875,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 */