From: sashiko-bot@kernel.org
To: "Mukesh Ojha" <mukesh.ojha@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 01/26] kernel: Introduce meminspect
Date: Wed, 08 Jul 2026 07:21:41 +0000 [thread overview]
Message-ID: <20260708072141.B21811F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260708-meminspect-v3-v3-1-7aa5a0a74d5c@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Integer truncation in memory allocation size causes an undersized CMA block, leading to a heap buffer overflow during ELF header initialization.
- [High] Invalid use of `virt_to_phys()` on statically allocated kernel symbols causes boot panics or returns bogus physical addresses.
- [High] Missing bounds checking on the `id` field leads to out-of-bounds accesses on the `inspect_entries` array.
- [Medium] ELF core dump file layout will be corrupted because physical traversal order diverges from chronological ELF header offsets.
- [Medium] Missing padding for unaligned region sizes causes cumulative offset mismatches in the dumped core file.
- [Medium] `meminspect_prepare_table` issues duplicate `MEMINSPECT_NOTIFIER_ADD` notifications for dynamic entries registered before the late initcall.
- [Low] `meminspect_notifier_list` is defined as an `ATOMIC_NOTIFIER_HEAD`, pointlessly forcing driver callbacks into an atomic context.
--
--- Patch [1]: [PATCH v3 01/26] kernel: Introduce meminspect ---
commit 62611e2ce3f1357bd155ab67d8e06e76e5461779
Author: Eugen Hristev <ehristev@kernel.org>
kernel: Introduce meminspect
This commit introduces a mechanism to register memory areas into an inspection
table for later use by drivers. The inspection table can be requested and
analyzed for purposes such as memory dumping or debugging.
> diff --git a/kernel/meminspect/meminspect.c b/kernel/meminspect/meminspect.c
> new file mode 100644
> index 0000000000000..d9d38f484f1f4
> --- /dev/null
> +++ b/kernel/meminspect/meminspect.c
> @@ -0,0 +1,474 @@
[ ... ]
> +static DEFINE_MUTEX(meminspect_lock);
> +static struct inspect_entry inspect_entries[MEMINSPECT_ID_MAX];
> +
> +static ATOMIC_NOTIFIER_HEAD(meminspect_notifier_list);
[Severity: Low]
Since the notifier events are dispatched while holding a sleepable mutex
(meminspect_lock), does using an ATOMIC_NOTIFIER_HEAD unnecessarily force all
consumer callbacks into a non-sleepable atomic context?
[ ... ]
> +static void update_elfheader(const struct inspect_entry *e)
> +{
> + struct elf_phdr *phdr;
> +
> + phdr = elf_phdr_entry_addr(ehdr, ehdr->e_phnum++);
> +
> + phdr->p_type = PT_LOAD;
> + phdr->p_offset = elf_offset;
[Severity: Medium]
If dynamic regions are registered out of chronological order, will
meminspect_traverse() yielding entries in strict numerical ID order cause the
physical data layout dumped by firmware to mismatch the chronologically
assigned p_offset values in the ELF headers?
> + phdr->p_vaddr = (elf_addr_t)e->va;
> + if (e->pa)
> + phdr->p_paddr = (elf_addr_t)e->pa;
> + else
> + phdr->p_paddr = (elf_addr_t)virt_to_phys(e->va);
> +
> + phdr->p_filesz = ALIGN(e->size, 4);
> + phdr->p_memsz = ALIGN(e->size, 4);
> + phdr->p_flags = PF_R | PF_W;
> + elf_offset += ALIGN(e->size, 4);
[Severity: Medium]
If an unaligned region is registered, update_elfheader() advances the global
elf_offset and header sizes with 4-byte padding, but the base table retains
the unaligned size.
When firmware iterates the table to dump the memory exactly by e->size, won't
this missing padding cause a cumulative drift between the actual file offsets
and the p_offset recorded in the ELF headers?
> +}
[ ... ]
> +static int init_elfheader(void)
> +{
[ ... ]
> + buf_sz = elfh_size + note_len - ALIGN(vmcoreinfo_size, 4);
> +
> + /* Never freed */
> + p = dma_alloc_from_contiguous(NULL, buf_sz >> PAGE_SHIFT,
> + get_order(buf_sz), true);
[Severity: High]
Does the expression buf_sz >> PAGE_SHIFT truncate the fractional page
remainder for unaligned sizes?
If buf_sz requires multiple pages but the shift truncates the count, could
this allocate an undersized CMA block and lead to a heap buffer overflow when
mapping the memory?
> + if (!p)
> + return -ENOMEM;
[ ... ]
> +void meminspect_unregister_id(enum meminspect_uid id)
> +{
> + struct inspect_entry *e;
> +
> + WARN_ON(!mutex_is_locked(&meminspect_lock));
> +
> + e = &inspect_entries[id];
[Severity: High]
Does this function lack bounds checking on the id argument?
If a caller passes an ID greater than or equal to MEMINSPECT_ID_MAX, could
this result in an out-of-bounds access and corruption of adjacent kernel
memory?
> + if (!e->id)
> + return;
[ ... ]
> +static int __init meminspect_prepare_table(void)
> +{
> + const struct inspect_entry *e;
> + enum meminspect_uid i;
> + int ret;
> +
> + meminspect_table_lock();
> + /*
> + * First, copy all entries from the compiler built table
> + * In case some entries are registered multiple times,
> + * the last chronological entry will be stored.
> + * Previously registered entries will be dropped.
> + */
> + for_each_meminspect_entry(e) {
> + inspect_entries[e->id] = *e;
[Severity: High]
Does this lack bounds checking on e->id?
If a statically compiled entry provides an invalid ID, could this result in
an out-of-bounds write?
> + if (!inspect_entries[e->id].pa && inspect_entries[e->id].va)
> + inspect_entries[e->id].pa = virt_to_phys(inspect_entries[e->id].va);
[Severity: High]
Is it safe to use virt_to_phys() on statically allocated kernel symbols parsed
from the linker section here?
Since these symbols reside in the kernel image map (which is outside the
linear map on architectures like arm64), could this cause a panic on boot or
return incorrect physical addresses?
> + }
> +#ifdef CONFIG_CRASH_DUMP
> + ret = meminspect_prepare_crashdump();
> + if (ret)
> + pr_warn("meminspect: failed to prepare crashdump ELF header: %d\n", ret);
> +#endif
> + /* if we have early notifiers registered, call them now */
> + for (i = MEMINSPECT_ID_ELF; i < MEMINSPECT_ID_MAX; i++)
> + if (inspect_entries[i].id)
> + atomic_notifier_call_chain(&meminspect_notifier_list,
> + MEMINSPECT_NOTIFIER_ADD,
> + &inspect_entries[i]);
[Severity: Medium]
If a dynamic region is registered via meminspect_register_pa() before this
late_initcall runs, will this loop blindly issue a duplicate
MEMINSPECT_NOTIFIER_ADD notification for that region?
> + meminspect_table_unlock();
> +
> + pr_debug("Memory inspection table initialized\n");
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-meminspect-v3-v3-0-7aa5a0a74d5c@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-07-08 7:21 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 5:31 [PATCH v3 00/26] Introduce meminspect Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 01/26] kernel: " Mukesh Ojha
2026-07-08 7:21 ` sashiko-bot [this message]
2026-07-08 7:38 ` Lorenzo Stoakes
2026-07-08 13:33 ` Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 02/26] init/version: Annotate static information into meminspect Mukesh Ojha
2026-07-08 7:21 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 03/26] mm/percpu: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 04/26] cpu: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 05/26] genirq/irqdesc: " Mukesh Ojha
2026-07-08 7:20 ` sashiko-bot
2026-07-08 7:46 ` Lorenzo Stoakes
2026-07-08 5:31 ` [PATCH v3 06/26] timers: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 07/26] timekeeping: Register tk_data " Mukesh Ojha
2026-07-08 7:18 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 08/26] kernel/fork: Annotate static information " Mukesh Ojha
2026-07-08 7:16 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 09/26] mm/page_alloc: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 10/26] mm/show_mem: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 11/26] mm/swapfile: " Mukesh Ojha
2026-07-08 7:47 ` Lorenzo Stoakes
2026-07-08 19:05 ` Mukesh Ojha
2026-07-09 14:53 ` Lorenzo Stoakes
2026-07-10 4:09 ` Christoph Hellwig
2026-07-08 5:31 ` [PATCH v3 12/26] kernel/vmcore_info: Register dynamic " Mukesh Ojha
2026-07-08 7:25 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 13/26] kernel/configs: " Mukesh Ojha
2026-07-08 7:20 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 14/26] mm/init-mm: Annotate static " Mukesh Ojha
2026-07-08 7:23 ` sashiko-bot
2026-07-08 7:52 ` Lorenzo Stoakes
2026-07-08 5:31 ` [PATCH v3 15/26] panic: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 16/26] kallsyms: " Mukesh Ojha
2026-07-08 7:23 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 17/26] mm/mm_init: " Mukesh Ojha
2026-07-08 5:31 ` [PATCH v3 18/26] sched/core: Annotate runqueues " Mukesh Ojha
2026-07-08 7:22 ` sashiko-bot
2026-07-08 5:31 ` [PATCH v3 19/26] mm/numa: Register node data information " Mukesh Ojha
2026-07-08 7:29 ` sashiko-bot
2026-07-08 7:55 ` Lorenzo Stoakes
2026-07-08 5:31 ` [PATCH v3 20/26] mm/sparse: Register " Mukesh Ojha
2026-07-08 7:27 ` sashiko-bot
2026-07-08 5:32 ` [PATCH v3 21/26] printk: " Mukesh Ojha
2026-07-08 7:24 ` sashiko-bot
2026-07-08 7:59 ` Lorenzo Stoakes
2026-07-08 18:53 ` Mukesh Ojha
2026-07-09 8:16 ` Petr Mladek
2026-07-08 5:32 ` [PATCH v3 22/26] remoteproc: qcom: Move minidump data structures into its own header Mukesh Ojha
2026-07-08 7:23 ` sashiko-bot
2026-07-08 5:32 ` [PATCH v3 23/26] soc: qcom: Add minidump backend driver Mukesh Ojha
2026-07-08 7:26 ` sashiko-bot
2026-07-08 5:32 ` [PATCH v3 24/26] soc: qcom: smem: Add minidump platform device Mukesh Ojha
2026-07-08 5:32 ` [PATCH v3 25/26] dt-bindings: reserved-memory: Add Google Kinfo Pixel reserved memory Mukesh Ojha
2026-07-08 7:08 ` [PATCH v3 26/26] meminspect: Add debug kinfo compatible driver Mukesh Ojha
2026-07-08 7:37 ` sashiko-bot
2026-07-08 8:06 ` Lorenzo Stoakes
2026-07-08 18:46 ` Mukesh Ojha
2026-07-09 13:24 ` Petr Pavlu
2026-07-08 7:11 ` [PATCH v3 00/26] Introduce meminspect Lorenzo Stoakes
2026-07-08 8:18 ` Lorenzo Stoakes
2026-07-09 20:42 ` Mukesh Ojha
2026-07-10 1:51 ` Liam R. Howlett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708072141.B21811F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=mukesh.ojha@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox