mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] sched/mm_cid: NULL pointer dereference in sched_mm_cid_fork on ARM64
@ 2025-12-26 19:25 Artur Sultangirov
  2025-12-26 20:03 ` Artur Sultangirov
  0 siblings, 1 reply; 2+ messages in thread
From: Artur Sultangirov @ 2025-12-26 19:25 UTC (permalink / raw)
  To: peterz, mingo
  Cc: Artur Sultangirov, mathieu.desnoyers, juri.lelli,
	vincent.guittot, linux-kernel

Hi,

I encountered a kernel panic on ARM64 (Apple M4 via QEMU in TCG mode) when executing a binary with a wrong architecture (x86_64 on aarch64).

Instead of returning -ENOEXEC and exiting gracefully, the kernel crashes with a NULL pointer dereference in mutex_lock(), called from sched_mm_cid_fork().

**Analysis:**
The crash happens because `sched_mm_cid_fork()` checks for `!mm` using `WARN_ON_ONCE()`, but does NOT return if `mm` is NULL. It proceeds to dereference `mm` to access `mm->mm_cid.mutex`, leading to a panic.

Code snippet (kernel/sched/core.c:10572):
    WARN_ON_ONCE(!mm || t->mm_cid.cid != MM_CID_UNSET);
    guard(mutex)(&mm->mm_cid.mutex); // <--- Dereference happens here

**Steps to reproduce:**
1. Boot an ARM64 kernel (reproduced on 6.19-rc2, master branch).
2. Attempt to execute an x86_64 binary as init (or via execve).
3. The execve fails, `mm` becomes NULL (or uninitialized), but the scheduler hook is called.

**Stack trace:**
[    0.911926] Run /bad_init as init process
[    0.916411] ------------[ cut here ]------------
[    0.916480] WARNING: kernel/sched/core.c:10569 at sched_mm_cid_fork+0x3c/0x35c, CPU#3: swapper/0/1
[    0.917233] Modules linked in:
[    0.917704] CPU: 3 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.19.0-rc2-00055-gccd1cdca5cd4-dirty #7 PREEMPT 
[    0.917866] Hardware name: linux,dummy-virt (DT)
[    0.918118] pc : sched_mm_cid_fork+0x3c/0x35c
[    0.918185] lr : sched_mm_cid_after_execve+0x10/0x1c
...
[    0.919284] Call trace:
[    0.919387]  sched_mm_cid_fork+0x3c/0x35c (P)
[    0.919522]  sched_mm_cid_after_execve+0x10/0x1c
[    0.919588]  bprm_execve+0x32c/0x470
[    0.919641]  kernel_execve+0x25c/0x274
...
[    0.920548] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000e0
[    0.921346] Internal error: Oops: 000000009600006b [#1]  SMP
...
[    0.923475] Call trace:
[    0.923503]  mutex_lock+0x18/0x54 (P)
[    0.923552]  sched_mm_cid_fork+0x4c/0x35c
[    0.923610]  sched_mm_cid_after_execve+0x10/0x1c
[    0.923662]  bprm_execve+0x32c/0x470
...
[    0.925595] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---

**Suggestion:**
The function should probably return immediately if `mm` is NULL, similar to how it is handled in other scheduler hooks.

Best regards,
Artur Sultangirov

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] sched/mm_cid: NULL pointer dereference in sched_mm_cid_fork on ARM64
  2025-12-26 19:25 [BUG] sched/mm_cid: NULL pointer dereference in sched_mm_cid_fork on ARM64 Artur Sultangirov
@ 2025-12-26 20:03 ` Artur Sultangirov
  0 siblings, 0 replies; 2+ messages in thread
From: Artur Sultangirov @ 2025-12-26 20:03 UTC (permalink / raw)
  To: peterz, mingo
  Cc: Artur Sultangirov, mathieu.desnoyers, juri.lelli,
	vincent.guittot, linux-kernel

Hi,

I noticed that Mathieu Desnoyers already posted a fix for this issue here:
https://lore.kernel.org/all/d6ac8fe9-5fc0-4042-9592-cde3db82b65e@efficios.com/

I have applied this patch and verified that it fixes the panic on ARM64 (Apple M4 via QEMU in TCG mode).

Feel free to add:
Tested-by: Artur Sultangirov <za4emsu@gmail.com>

Best regards,
Artur

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-26 20:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-26 19:25 [BUG] sched/mm_cid: NULL pointer dereference in sched_mm_cid_fork on ARM64 Artur Sultangirov
2025-12-26 20:03 ` Artur Sultangirov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®