]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
6.5-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 31 Aug 2023 07:19:23 +0000 (09:19 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 31 Aug 2023 07:19:23 +0000 (09:19 +0200)
added patches:
arm-module-use-module_init_layout_section-to-spot-init-sections.patch
arm64-module-use-module_init_layout_section-to-spot-init-sections.patch
module-decompress-use-vmalloc-for-zstd-decompression-workspace.patch
module-expose-module_init_layout_section.patch

queue-6.5/arm-module-use-module_init_layout_section-to-spot-init-sections.patch [new file with mode: 0644]
queue-6.5/arm64-module-use-module_init_layout_section-to-spot-init-sections.patch [new file with mode: 0644]
queue-6.5/module-decompress-use-vmalloc-for-zstd-decompression-workspace.patch [new file with mode: 0644]
queue-6.5/module-expose-module_init_layout_section.patch [new file with mode: 0644]
queue-6.5/series

diff --git a/queue-6.5/arm-module-use-module_init_layout_section-to-spot-init-sections.patch b/queue-6.5/arm-module-use-module_init_layout_section-to-spot-init-sections.patch
new file mode 100644 (file)
index 0000000..4c0658f
--- /dev/null
@@ -0,0 +1,46 @@
+From a6846234f45801441f0e31a8b37f901ef0abd2df Mon Sep 17 00:00:00 2001
+From: James Morse <james.morse@arm.com>
+Date: Tue, 1 Aug 2023 14:54:09 +0000
+Subject: ARM: module: Use module_init_layout_section() to spot init sections
+
+From: James Morse <james.morse@arm.com>
+
+commit a6846234f45801441f0e31a8b37f901ef0abd2df upstream.
+
+Today module_frob_arch_sections() spots init sections from their
+'init' prefix, and uses this to keep the init PLTs separate from the rest.
+
+get_module_plt() uses within_module_init() to determine if a
+location is in the init text or not, but this depends on whether
+core code thought this was an init section.
+
+Naturally the logic is different.
+
+module_init_layout_section() groups the init and exit text together if
+module unloading is disabled, as the exit code will never run. The result
+is kernels with this configuration can't load all their modules because
+there are not enough PLTs for the combined init+exit section.
+
+A previous patch exposed module_init_layout_section(), use that so the
+logic is the same.
+
+Fixes: 055f23b74b20 ("module: check for exit sections in layout_sections() instead of module_init_section()")
+Cc: stable@vger.kernel.org
+Signed-off-by: James Morse <james.morse@arm.com>
+Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/arm/kernel/module-plts.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/arch/arm/kernel/module-plts.c
++++ b/arch/arm/kernel/module-plts.c
+@@ -251,7 +251,7 @@ int module_frob_arch_sections(Elf_Ehdr *
+               /* sort by type and symbol index */
+               sort(rels, numrels, sizeof(Elf32_Rel), cmp_rel, NULL);
+-              if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0)
++              if (!module_init_layout_section(secstrings + dstsec->sh_name))
+                       core_plts += count_plts(syms, dstsec->sh_addr, rels,
+                                               numrels, s->sh_info);
+               else
diff --git a/queue-6.5/arm64-module-use-module_init_layout_section-to-spot-init-sections.patch b/queue-6.5/arm64-module-use-module_init_layout_section-to-spot-init-sections.patch
new file mode 100644 (file)
index 0000000..81294e9
--- /dev/null
@@ -0,0 +1,72 @@
+From f928f8b1a2496e7af95b860f9acf553f20f68f16 Mon Sep 17 00:00:00 2001
+From: James Morse <james.morse@arm.com>
+Date: Tue, 1 Aug 2023 14:54:08 +0000
+Subject: arm64: module: Use module_init_layout_section() to spot init sections
+
+From: James Morse <james.morse@arm.com>
+
+commit f928f8b1a2496e7af95b860f9acf553f20f68f16 upstream.
+
+Today module_frob_arch_sections() spots init sections from their
+'init' prefix, and uses this to keep the init PLTs separate from the rest.
+
+module_emit_plt_entry() uses within_module_init() to determine if a
+location is in the init text or not, but this depends on whether
+core code thought this was an init section.
+
+Naturally the logic is different.
+
+module_init_layout_section() groups the init and exit text together if
+module unloading is disabled, as the exit code will never run. The result
+is kernels with this configuration can't load all their modules because
+there are not enough PLTs for the combined init+exit section.
+
+This results in the following:
+| WARNING: CPU: 2 PID: 51 at arch/arm64/kernel/module-plts.c:99 module_emit_plt_entry+0x184/0x1cc
+| Modules linked in: crct10dif_common
+| CPU: 2 PID: 51 Comm: modprobe Not tainted 6.5.0-rc4-yocto-standard-dirty #15208
+| Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
+| pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
+| pc : module_emit_plt_entry+0x184/0x1cc
+| lr : module_emit_plt_entry+0x94/0x1cc
+| sp : ffffffc0803bba60
+[...]
+| Call trace:
+|  module_emit_plt_entry+0x184/0x1cc
+|  apply_relocate_add+0x2bc/0x8e4
+|  load_module+0xe34/0x1bd4
+|  init_module_from_file+0x84/0xc0
+|  __arm64_sys_finit_module+0x1b8/0x27c
+|  invoke_syscall.constprop.0+0x5c/0x104
+|  do_el0_svc+0x58/0x160
+|  el0_svc+0x38/0x110
+|  el0t_64_sync_handler+0xc0/0xc4
+|  el0t_64_sync+0x190/0x194
+
+A previous patch exposed module_init_layout_section(), use that so the
+logic is the same.
+
+Reported-by: Adam Johnston <adam.johnston@arm.com>
+Tested-by: Adam Johnston <adam.johnston@arm.com>
+Fixes: 055f23b74b20 ("module: check for exit sections in layout_sections() instead of module_init_section()")
+Cc: <stable@vger.kernel.org> # 5.15.x: 60a0aab7463ee69 arm64: module-plts: inline linux/moduleloader.h
+Cc: <stable@vger.kernel.org> # 5.15.x
+Signed-off-by: James Morse <james.morse@arm.com>
+Acked-by: Catalin Marinas <catalin.marinas@arm.com>
+Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/arm64/kernel/module-plts.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/arch/arm64/kernel/module-plts.c
++++ b/arch/arm64/kernel/module-plts.c
+@@ -339,7 +339,7 @@ int module_frob_arch_sections(Elf_Ehdr *
+               if (nents)
+                       sort(rels, nents, sizeof(Elf64_Rela), cmp_rela, NULL);
+-              if (!str_has_prefix(secstrings + dstsec->sh_name, ".init"))
++              if (!module_init_layout_section(secstrings + dstsec->sh_name))
+                       core_plts += count_plts(syms, rels, numrels,
+                                               sechdrs[i].sh_info, dstsec);
+               else
diff --git a/queue-6.5/module-decompress-use-vmalloc-for-zstd-decompression-workspace.patch b/queue-6.5/module-decompress-use-vmalloc-for-zstd-decompression-workspace.patch
new file mode 100644 (file)
index 0000000..7f29836
--- /dev/null
@@ -0,0 +1,73 @@
+From a419beac4a070aff63c520f36ebf7cb8a76a8ae5 Mon Sep 17 00:00:00 2001
+From: Andrea Righi <andrea.righi@canonical.com>
+Date: Tue, 29 Aug 2023 14:05:08 +0200
+Subject: module/decompress: use vmalloc() for zstd decompression workspace
+
+From: Andrea Righi <andrea.righi@canonical.com>
+
+commit a419beac4a070aff63c520f36ebf7cb8a76a8ae5 upstream.
+
+Using kmalloc() to allocate the decompression workspace for zstd may
+trigger the following warning when large modules are loaded (i.e., xfs):
+
+[    2.961884] WARNING: CPU: 1 PID: 254 at mm/page_alloc.c:4453 __alloc_pages+0x2c3/0x350
+...
+[    2.989033] Call Trace:
+[    2.989841]  <TASK>
+[    2.990614]  ? show_regs+0x6d/0x80
+[    2.991573]  ? __warn+0x89/0x160
+[    2.992485]  ? __alloc_pages+0x2c3/0x350
+[    2.993520]  ? report_bug+0x17e/0x1b0
+[    2.994506]  ? handle_bug+0x51/0xa0
+[    2.995474]  ? exc_invalid_op+0x18/0x80
+[    2.996469]  ? asm_exc_invalid_op+0x1b/0x20
+[    2.997530]  ? module_zstd_decompress+0xdc/0x2a0
+[    2.998665]  ? __alloc_pages+0x2c3/0x350
+[    2.999695]  ? module_zstd_decompress+0xdc/0x2a0
+[    3.000821]  __kmalloc_large_node+0x7a/0x150
+[    3.001920]  __kmalloc+0xdb/0x170
+[    3.002824]  module_zstd_decompress+0xdc/0x2a0
+[    3.003857]  module_decompress+0x37/0xc0
+[    3.004688]  init_module_from_file+0xd0/0x100
+[    3.005668]  idempotent_init_module+0x11c/0x2b0
+[    3.006632]  __x64_sys_finit_module+0x64/0xd0
+[    3.007568]  do_syscall_64+0x59/0x90
+[    3.008373]  ? ksys_read+0x73/0x100
+[    3.009395]  ? exit_to_user_mode_prepare+0x30/0xb0
+[    3.010531]  ? syscall_exit_to_user_mode+0x37/0x60
+[    3.011662]  ? do_syscall_64+0x68/0x90
+[    3.012511]  ? do_syscall_64+0x68/0x90
+[    3.013364]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
+
+However, continuous physical memory does not seem to be required in
+module_zstd_decompress(), so use vmalloc() instead, to prevent the
+warning and avoid potential failures at loading compressed modules.
+
+Fixes: 169a58ad824d ("module/decompress: Support zstd in-kernel decompression")
+Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
+Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/module/decompress.c |    4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/kernel/module/decompress.c
++++ b/kernel/module/decompress.c
+@@ -241,7 +241,7 @@ static ssize_t module_zstd_decompress(st
+       }
+       wksp_size = zstd_dstream_workspace_bound(header.windowSize);
+-      wksp = kmalloc(wksp_size, GFP_KERNEL);
++      wksp = vmalloc(wksp_size);
+       if (!wksp) {
+               retval = -ENOMEM;
+               goto out;
+@@ -284,7 +284,7 @@ static ssize_t module_zstd_decompress(st
+       retval = new_size;
+  out:
+-      kfree(wksp);
++      vfree(wksp);
+       return retval;
+ }
+ #else
diff --git a/queue-6.5/module-expose-module_init_layout_section.patch b/queue-6.5/module-expose-module_init_layout_section.patch
new file mode 100644 (file)
index 0000000..6d16942
--- /dev/null
@@ -0,0 +1,85 @@
+From 2abcc4b5a64a65a2d2287ba0be5c2871c1552416 Mon Sep 17 00:00:00 2001
+From: James Morse <james.morse@arm.com>
+Date: Tue, 1 Aug 2023 14:54:07 +0000
+Subject: module: Expose module_init_layout_section()
+
+From: James Morse <james.morse@arm.com>
+
+commit 2abcc4b5a64a65a2d2287ba0be5c2871c1552416 upstream.
+
+module_init_layout_section() choses whether the core module loader
+considers a section as init or not. This affects the placement of the
+exit section when module unloading is disabled. This code will never run,
+so it can be free()d once the module has been initialised.
+
+arm and arm64 need to count the number of PLTs they need before applying
+relocations based on the section name. The init PLTs are stored separately
+so they can be free()d. arm and arm64 both use within_module_init() to
+decide which list of PLTs to use when applying the relocation.
+
+Because within_module_init()'s behaviour changes when module unloading
+is disabled, both architecture would need to take this into account when
+counting the PLTs.
+
+Today neither architecture does this, meaning when module unloading is
+disabled there are insufficient PLTs in the init section to load some
+modules, resulting in warnings:
+| WARNING: CPU: 2 PID: 51 at arch/arm64/kernel/module-plts.c:99 module_emit_plt_entry+0x184/0x1cc
+| Modules linked in: crct10dif_common
+| CPU: 2 PID: 51 Comm: modprobe Not tainted 6.5.0-rc4-yocto-standard-dirty #15208
+| Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
+| pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
+| pc : module_emit_plt_entry+0x184/0x1cc
+| lr : module_emit_plt_entry+0x94/0x1cc
+| sp : ffffffc0803bba60
+[...]
+| Call trace:
+|  module_emit_plt_entry+0x184/0x1cc
+|  apply_relocate_add+0x2bc/0x8e4
+|  load_module+0xe34/0x1bd4
+|  init_module_from_file+0x84/0xc0
+|  __arm64_sys_finit_module+0x1b8/0x27c
+|  invoke_syscall.constprop.0+0x5c/0x104
+|  do_el0_svc+0x58/0x160
+|  el0_svc+0x38/0x110
+|  el0t_64_sync_handler+0xc0/0xc4
+|  el0t_64_sync+0x190/0x194
+
+Instead of duplicating module_init_layout_section()s logic, expose it.
+
+Reported-by: Adam Johnston <adam.johnston@arm.com>
+Fixes: 055f23b74b20 ("module: check for exit sections in layout_sections() instead of module_init_section()")
+Cc: stable@vger.kernel.org
+Signed-off-by: James Morse <james.morse@arm.com>
+Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/moduleloader.h |    5 +++++
+ kernel/module/main.c         |    2 +-
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+--- a/include/linux/moduleloader.h
++++ b/include/linux/moduleloader.h
+@@ -42,6 +42,11 @@ bool module_init_section(const char *nam
+  */
+ bool module_exit_section(const char *name);
++/* Describes whether within_module_init() will consider this an init section
++ * or not. This behaviour changes with CONFIG_MODULE_UNLOAD.
++ */
++bool module_init_layout_section(const char *sname);
++
+ /*
+  * Apply the given relocation to the (simplified) ELF.  Return -error
+  * or 0.
+--- a/kernel/module/main.c
++++ b/kernel/module/main.c
+@@ -1484,7 +1484,7 @@ long module_get_offset_and_type(struct m
+       return offset | mask;
+ }
+-static bool module_init_layout_section(const char *sname)
++bool module_init_layout_section(const char *sname)
+ {
+ #ifndef CONFIG_MODULE_UNLOAD
+       if (module_exit_section(sname))
index 1f56db43702c6ce3462e0dd65363716c4e0c62e1..427d571aad4231d5582a8e0b5c7f4285a2ffa76a 100644 (file)
@@ -1 +1,5 @@
 acpi-thermal-drop-nocrt-parameter.patch
+module-expose-module_init_layout_section.patch
+arm64-module-use-module_init_layout_section-to-spot-init-sections.patch
+arm-module-use-module_init_layout_section-to-spot-init-sections.patch
+module-decompress-use-vmalloc-for-zstd-decompression-workspace.patch