[Bug 273956] KERN_PROC_VMMAP does not read all mapped files

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 20 Sep 2023 05:45:28 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273956

            Bug ID: 273956
           Summary: KERN_PROC_VMMAP does not read all mapped files
           Product: Base System
           Version: 14.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: pjfloyd@wanadoo.fr

This issue affects Valgrind. Early in startup Valgrind reads its own file
mapping in order to parse its own debuginfo. That means that if Valgrind
encounters an internal error it can print its own callstack.

This uses a function called parse_procselfmaps. Originally for Linux and, as
the name implies, parsing /proc/self/maps, the FreeBSD version uses sysctl
KERN_PROC_VMMAP.

procstat -v gives me

paulf> /usr/bin/procstat -v 12168
  PID              START                END PRT  RES PRES REF SHD FLAG  TP PATH
12168         0x38000000         0x380c5000 r--  197 2558  15   1 CN--- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
12168         0x380c5000         0x38277000 r-x  434    0   1   0 C---- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
12168         0x38277000         0x38278000 rw-    1 2558  15   1 CN--- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
12168         0x38278000         0x3a855000 rw-   10   10   1   0 ----- df 
12168     0x7fffdffff000     0x7ffffffdf000 ---    0    0   0   0 ----- gd 
12168     0x7ffffffdf000     0x7ffffffff000 rw-    1    1   1   0 ---D- df 
12168     0x7ffffffff000     0x800000000000 r-x    1    1  90   0 ----- p

so I'm expecting to read at least those first 3 mappings.

On FreeBSD 13.2 the Valgrind mapping that I see it

--12922:2: aspacem   (0,4,5)
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
--12922:2: aspacem     0: RSVN 0000000000-0003ffffff     64m ----- SmFixed
--12922:2: aspacem     1:      0004000000-0037ffffff    832m
--12922:2: aspacem     2: FILE 0038000000-00380c5fff  811008 r---- d=0x696e301b
i=381975  o=0       (0,4)
--12922:2: aspacem     3: FILE 00380c6000-0038276fff 1773568 r-x-- d=0x696e301b
i=381975  o=806912  (0,4)
--12922:2: aspacem     4: FILE 0038277000-0038277fff    4096 rw--- d=0x696e301b
i=381975  o=2576384 (0,4)


But on 14.0-ALPHA3 I get

--7771:2: aspacem   (0,4,3)
/home/paulf/valgrind/memcheck/memcheck-amd64-freebsd
--7771:2: aspacem     0: RSVN 0000000000-0003ffffff     64m ----- SmFixed
--7771:2: aspacem     1:      0004000000-0037ffffff    832m
--7771:2: aspacem     2: FILE 0038000000-00380c3fff  802816 r---- d=0x05a
i=2491810 o=0       (0,4)
--7771:2: aspacem     3: FILE 00380c4000-0038272fff 1765376 r-x-- d=0x05a
i=2491810 o=798720  (0,4)

The third rw mapping of 1 page has gone.

Beacause it is no longer seeing a "full" elf mapping it no longer tries to read
its own debug symbols. And when it cashes, no callstack.

That's a pain for a Valgrind developer.

-- 
You are receiving this mail because:
You are the assignee for the bug.