Skip to content

Comments

module: allow for module error injection#52

Closed
modules-kpd-app[bot] wants to merge 3 commits intomodules-next_basefrom
series/927532=>modules-next
Closed

module: allow for module error injection#52
modules-kpd-app[bot] wants to merge 3 commits intomodules-next_basefrom
series/927532=>modules-next

Conversation

@modules-kpd-app
Copy link

Pull request for series with
subject: module: allow for module error injection
version: 1
url: https://patchwork.kernel.org/project/linux-modules/list/?series=927532

@modules-kpd-app
Copy link
Author

Upstream branch: f3b9354
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

@modules-kpd-app
Copy link
Author

Upstream branch: 48ecfdd
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

@modules-kpd-app modules-kpd-app bot force-pushed the series/927532=>modules-next branch from 77716c4 to 374a92e Compare January 30, 2025 13:44
@modules-kpd-app
Copy link
Author

Upstream branch: 053842e
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

@modules-kpd-app modules-kpd-app bot force-pushed the series/927532=>modules-next branch from 374a92e to 23a43a9 Compare February 4, 2025 12:19
@modules-kpd-app
Copy link
Author

Upstream branch: afa9286
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

@modules-kpd-app modules-kpd-app bot force-pushed the series/927532=>modules-next branch from 23a43a9 to d2475a8 Compare February 17, 2025 10:02
@modules-kpd-app
Copy link
Author

Upstream branch: 085c5e3
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

@modules-kpd-app modules-kpd-app bot force-pushed the series/927532=>modules-next branch from d2475a8 to 76b6ba2 Compare March 18, 2025 22:57
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from 7c2b408 to 2996654 Compare April 7, 2025 01:58
@modules-kpd-app
Copy link
Author

Upstream branch: 897c0b4
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

Allow to test kernel module initialization with eBPF error injection
by forcing errors when any of the below annotated functions with
ALLOW_ERROR_INJECTION() return.

Allow to debug and test module load error behaviour when:

complete_formation(): when module initialization switches from
MODULE_STATE_UNFORMED to MODULE_STATE_COMING stage.

do_init_module(): when an error occurs during module initialization and
before we switch from MODULE_STATE_COMING to MODULE_STATE_LIVE stage.

module_enable_rodata_ro_after_init(): when an error occurs while
setting memory to RO after module initialization. This is when module
initialization reaches MODULE_STATE_LIVE stage.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
Add support for a module error injection tool. The tool
can inject errors in the annotated module kernel functions
such as complete_formation(), do_init_module() and
module_enable_rodata_after_init(). Module name and module function are
required parameters to have control over the error injection.

Example: Inject error -22 to module_enable_rodata_ro_after_init for
brd module:

sudo moderr --modname=brd --modfunc=module_enable_rodata_ro_after_init \
--error=-22 --trace
Monitoring module error injection... Hit Ctrl-C to end.
MODULE     ERROR FUNCTION
brd        -22   module_enable_rodata_after_init()

Kernel messages:
[   89.463690] brd: module loaded
[   89.463855] brd: module_enable_rodata_ro_after_init() returned -22,
ro_after_init data might still be writable

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
@modules-kpd-app modules-kpd-app bot force-pushed the series/927532=>modules-next branch from 76b6ba2 to 33a50be Compare April 7, 2025 02:00
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from 2996654 to d4037eb Compare April 7, 2025 14:12
@modules-kpd-app
Copy link
Author

Upstream branch: b464e57
series: https://patchwork.kernel.org/project/linux-modules/list/?series=927532
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-modules/list/?series=927532
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: module: allow for module error injection
Using index info to reconstruct a base tree...
M	kernel/module/main.c
M	kernel/module/strict_rwx.c
Falling back to patching base and 3-way merge...
Auto-merging kernel/module/strict_rwx.c
CONFLICT (content): Merge conflict in kernel/module/strict_rwx.c
Auto-merging kernel/module/main.c
Patch failed at 0001 module: allow for module error injection'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"'

conflict:

diff --cc kernel/module/strict_rwx.c
index 8fd438529fbc,21936f5cc1e6..000000000000
--- a/kernel/module/strict_rwx.c
+++ b/kernel/module/strict_rwx.c
@@@ -9,7 -9,7 +9,11 @@@
  #include <linux/mm.h>
  #include <linux/vmalloc.h>
  #include <linux/set_memory.h>
++<<<<<<< HEAD
 +#include <linux/execmem.h>
++=======
+ #include <linux/bpf.h>
++>>>>>>> module: allow for module error injection
  #include "internal.h"
  
  static int module_set_memory(const struct module *mod, enum mod_mem_type type,

@modules-kpd-app
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/linux-modules/list/?series=927532 irrelevant now. Closing PR.

1 similar comment
@modules-kpd-app
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/linux-modules/list/?series=927532 irrelevant now. Closing PR.

@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from d6fb02c to b788ac1 Compare June 2, 2025 09:03
@modules-kpd-app
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/linux-modules/list/?series=927532 irrelevant now. Closing PR.

1 similar comment
@modules-kpd-app
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/linux-modules/list/?series=927532 irrelevant now. Closing PR.

@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from cbdca0b to 6a1a12c Compare June 25, 2025 20:39
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 2 times, most recently from 6381fa5 to aaa7ece Compare June 26, 2025 18:03
@dagomez137 dagomez137 force-pushed the modules-next_base branch 2 times, most recently from b4d1c4e to 61dc34e Compare July 4, 2025 19:48
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 2 times, most recently from 1df8185 to 9aab33d Compare July 8, 2025 19:00
@dagomez137 dagomez137 force-pushed the modules-next_base branch from 9aab33d to 99d099e Compare July 8, 2025 19:46
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from 99d099e to 3aed49d Compare July 8, 2025 19:56
dagomez137 pushed a commit that referenced this pull request Sep 8, 2025
When there are memory-only nodes (nodes without CPUs), these nodes are not
properly initialized, causing kernel panic during boot.

of_numa_init
	of_numa_parse_cpu_nodes
		node_set(nid, numa_nodes_parsed);
	of_numa_parse_memory_nodes

In of_numa_parse_cpu_nodes, numa_nodes_parsed gets updated only for nodes
containing CPUs.  Memory-only nodes should have been updated in
of_numa_parse_memory_nodes, but they weren't.

Subsequently, when free_area_init() attempts to access NODE_DATA() for
these uninitialized memory nodes, the kernel panics due to NULL pointer
dereference.

This can be reproduced on ARM64 QEMU with 1 CPU and 2 memory nodes:

qemu-system-aarch64 \
-cpu host -nographic \
-m 4G -smp 1 \
-machine virt,accel=kvm,gic-version=3,iommu=smmuv3 \
-object memory-backend-ram,size=2G,id=mem0 \
-object memory-backend-ram,size=2G,id=mem1 \
-numa node,nodeid=0,memdev=mem0 \
-numa node,nodeid=1,memdev=mem1 \
-kernel $IMAGE \
-hda $DISK \
-append "console=ttyAMA0 root=/dev/vda rw earlycon"

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x481fd010]
[    0.000000] Linux version 6.17.0-rc1-00001-gabb4b3daf18c-dirty (yintirui@local) (gcc (GCC) 12.3.1, GNU ld (GNU Binutils) 2.41) #52 SMP PREEMPT Mon Aug 18 09:49:40 CST 2025
[    0.000000] KASLR enabled
[    0.000000] random: crng init done
[    0.000000] Machine model: linux,dummy-virt
[    0.000000] efi: UEFI not found.
[    0.000000] earlycon: pl11 at MMIO 0x0000000009000000 (options '')
[    0.000000] printk: legacy bootconsole [pl11] enabled
[    0.000000] OF: reserved mem: Reserved memory: No reserved-memory node in the DT
[    0.000000] NODE_DATA(0) allocated [mem 0xbfffd9c0-0xbfffffff]
[    0.000000] node 1 must be removed before remove section 23
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000040000000-0x00000000ffffffff]
[    0.000000]   DMA32    empty
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000013fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040000000-0x00000000bfffffff]
[    0.000000]   node   1: [mem 0x00000000c0000000-0x000000013fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x00000000bfffffff]
[    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000a0
[    0.000000] Mem abort info:
[    0.000000]   ESR = 0x0000000096000004
[    0.000000]   EC = 0x25: DABT (current EL), IL = 32 bits
[    0.000000]   SET = 0, FnV = 0
[    0.000000]   EA = 0, S1PTW = 0
[    0.000000]   FSC = 0x04: level 0 translation fault
[    0.000000] Data abort info:
[    0.000000]   ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
[    0.000000]   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[    0.000000]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[    0.000000] [00000000000000a0] user address but active_mm is swapper
[    0.000000] Internal error: Oops: 0000000096000004 [#1]  SMP
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.17.0-rc1-00001-g760c6dabf762-dirty #54 PREEMPT
[    0.000000] Hardware name: linux,dummy-virt (DT)
[    0.000000] pstate: 800000c5 (Nzcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[    0.000000] pc : free_area_init+0x50c/0xf9c
[    0.000000] lr : free_area_init+0x5c0/0xf9c
[    0.000000] sp : ffffa02ca0f33c00
[    0.000000] x29: ffffa02ca0f33cb0 x28: 0000000000000000 x27: 0000000000000000
[    0.000000] x26: 4ec4ec4ec4ec4ec5 x25: 00000000000c0000 x24: 00000000000c0000
[    0.000000] x23: 0000000000040000 x22: 0000000000000000 x21: ffffa02ca0f3b368
[    0.000000] x20: ffffa02ca14c7b98 x19: 0000000000000000 x18: 0000000000000002
[    0.000000] x17: 000000000000cacc x16: 0000000000000001 x15: 0000000000000001
[    0.000000] x14: 0000000080000000 x13: 0000000000000018 x12: 0000000000000002
[    0.000000] x11: ffffa02ca0fd4f00 x10: ffffa02ca14bab20 x9 : ffffa02ca14bab38
[    0.000000] x8 : 00000000000c0000 x7 : 0000000000000001 x6 : 0000000000000002
[    0.000000] x5 : 0000000140000000 x4 : ffffa02ca0f33c90 x3 : ffffa02ca0f33ca0
[    0.000000] x2 : ffffa02ca0f33c98 x1 : 0000000080000000 x0 : 0000000000000001
[    0.000000] Call trace:
[    0.000000]  free_area_init+0x50c/0xf9c (P)
[    0.000000]  bootmem_init+0x110/0x1dc
[    0.000000]  setup_arch+0x278/0x60c
[    0.000000]  start_kernel+0x70/0x748
[    0.000000]  __primary_switched+0x88/0x90
[    0.000000] Code: d503201f b98093e0 52800016 f8607a93 (f9405260)
[    0.000000] ---[ end trace 0000000000000000 ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---

Link: https://lkml.kernel.org/r/20250819075510.2079961-1-yintirui@huawei.com
Fixes: 7675076 ("arch_numa: switch over to numa_memblks")
Signed-off-by: Yin Tirui <yintirui@huawei.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Chen Jun <chenjun102@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joanthan Cameron <Jonathan.Cameron@huawei.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 3 times, most recently from 0299e02 to cdc6b9e Compare October 22, 2025 10:27
@modules-kpd-app
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/linux-modules/list/?series=927532 irrelevant now. Closing PR.

@modules-kpd-app modules-kpd-app bot closed this Oct 22, 2025
@modules-kpd-app modules-kpd-app bot deleted the series/927532=>modules-next branch October 22, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant