[RFC PATCH v2 03/30] unwind_user: Support Minimal DWARF CFI user-space unwinding

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Tue Nov 24 23:05:28 PST 2026


> unwind_user: Support Minimal DWARF CFI user-space unwinding

TL;DR:
- Possible misclassification of executable private /dev/zero mappings as ELF
  bases in user_cfi.c; likely harmless (extra user read, or CFI from
  user-written bytes if ELF-like)
- Commit message nit: explain why CFI unwinding is needed

> unwind_user: Support Minimal DWARF CFI user-space unwinding
>
> Extend the generic user-space unwinder (kernel/unwind/user.c) with
> UNWIND_USER_TYPE_CFI (CONFIG_HAVE_UNWIND_USER_CFI), resolving ELF
> PT_GNU_EH_FRAME headers across executable VMAs in kernel/unwind/user_cfi.c.
> Key design details:
>  - Find the executable VMA and its base ELF mapping (vm_pgoff == 0)
>    under mmap_read_lock_killable(), then drop mmap_read_lock() before
>    issuing any faultable copy_from_user() reads.
> [ ... ]

this isn't a bug, but could the changelog say briefly why CFI-based user
unwinding is needed, for example what fails with frame pointers alone,
before it lists the design details?

> diff --git a/kernel/unwind/user_cfi.c b/kernel/unwind/user_cfi.c
> new file mode 100644
> --- /dev/null
> +++ b/kernel/unwind/user_cfi.c
> @@ -0,0 +1,392 @@

[ ... ]

> +static bool lookup_vma_elf_base_locked(struct mm_struct *mm, unsigned long ip,
> +				       unsigned long *vma_start,
> +				       unsigned long *vma_end,
> +				       unsigned long *elf_base)
> +{
> +	struct vm_area_struct *vma = vma_lookup(mm, ip);

[ ... ]

> +	if (vma_is_anonymous(vma) || !vma->vm_file) {
> +		if (vma->vm_pgoff == 0) {
> +			/* Special mappings such as [vdso] */
> +			*elf_base = vma->vm_start;
> +			return true;
> +		}

A subsystem pattern flags this as potentially concerning: this branch is
entered for vma_is_anonymous(vma) || !vma->vm_file, and vm_pgoff == 0 is
then taken to mean a special mapping such as [vdso].

For a purely anonymous VMA, vm_pgoff equals vm_start >> PAGE_SHIFT, so that
works.  A private /dev/zero mapping is also vma_is_anonymous(), but vm_file
is set and vm_pgoff holds the file offset passed to mmap(), usually 0.

Can an executable MAP_PRIVATE /dev/zero region at offset 0 be classified as
an ELF base here, so that *elf_base = vma->vm_start is returned and
find_user_eh_frame_hdr() parses the first bytes of the region as an ELF
header instead of negative-caching it?

The guide's safe forms are to test vma_is_anonymous(vma) && !vma->vm_file,
or to use vma_start_anon_pgoff() for the anonymous offset.

On the other side, the misclassified region is the task's own memory and is
only read through copy_from_user().  JIT code at vm_start would normally
fail the ELF magic check, so parse_user_elf64_eh_hdr() or
parse_user_elf32_eh_hdr() would return -EINVAL, the slot would stay
negative-cached and unwind_user_next() would fall back to FP.  The visible
effect would be one extra user read per walk, or CFI evaluated from
user-written bytes if the region happens to start with an ELF header.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45561209846


More information about the linux-riscv mailing list