ANDROID: 16K: Remove ELF padding entry from map_file ranges

Symbolization techniques use address ranges as reported in /proc/*/maps
to infer the corresponding /proc/*/map_files/ entry.

Per Daniel, this is done because the path in /proc/*/maps is problematic
for at least two reasons:

    1. The file could have been deleted from the file system (this is
       indicated with the  (deleted) suffix), meaning that you can't
       actually open it through the "regular" file system. However,
       while the mapping is alive, the kernel keeps the inode accessible
       via the corresponding /proc/*/map_files entry, allowing for
       access after all.

    2. It makes dealing with changed root and file system namespaces
       much more painful. The /proc/*/maps path is relative, and so now
       you need to concatenate paths etc. Accessing file through
       /proc/*/map_files just works (assuming necessary permissions), as
       the kernel redirects the request to the proper inode,
       irrespective of how it is exposed through the non-proc
       filesystem.

Android extends ELF padding regions to be contiguously mapped in memory
to mitigate increase in unreclaimable VMA slab memory usage.

Commit 8c2a805a85 [1] emulates the padding
region of such extended mappings to be outputted as PROT_NONE
[page size compat] entries from /proc/*/[s]maps. This breaks the use
case of /proc/*/maps_files/, as the ranges in /proc/*/map_files/ are
the true ranges of the actual underlying VMA layout; while those in
/proc/*/[s]maps are the emulated (shortened) ranges.

Remove the padding (extended) ranges from /proc/*/maps_files entries.

====== Example Output ======

=== maps ===

❯ adb shell cat /proc/1/maps | grep -A1 libdl_android.so | sed '$d'

7f76663df000-7f76663e0000 r--p 00000000 fe:09 1911                       /system/lib64/bootstrap/libdl_android.so
7f76663e0000-7f76663e3000 ---p 00000000 00:00 0                          [page size compat]
7f76663e3000-7f76663e4000 r-xp 00004000 fe:09 1911                       /system/lib64/bootstrap/libdl_android.so
7f76663e4000-7f76663e7000 ---p 00000000 00:00 0                          [page size compat]
7f76663e7000-7f76663e8000 r--p 00008000 fe:09 1911                       /system/lib64/bootstrap/libdl_android.s

=== map_files - Before patch ===

❯ adb shell ls /proc/1/map_files | grep -A2 7f76663df000

7f76663df000-7f76663e3000
7f76663e3000-7f76663e7000
7f76663e7000-7f76663e8000

=== map_files - After patch ===

❯ adb shell ls /proc/1/map_files | grep -A2 7f76663df000

7f76663df000-7f76663e0000
7f76663e3000-7f76663e4000
7f76663e7000-7f76663e8000

[1] 8c2a805a85

Bug: 418042003
Change-Id: I0f6d703715a0e709fa1d4bd52241b5fd913dd55e
Reported-by: Daniel Müller <deso@posteo.net>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
Kalesh Singh
2025-05-19 11:10:04 -07:00
parent f8de2aa994
commit a15483adeb

View File

@@ -65,6 +65,7 @@
#include <linux/namei.h>
#include <linux/mnt_namespace.h>
#include <linux/mm.h>
#include <linux/pgsize_migration.h>
#include <linux/swap.h>
#include <linux/rcupdate.h>
#include <linux/kallsyms.h>
@@ -2476,7 +2477,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
}
p->start = vma->vm_start;
p->end = vma->vm_end;
p->end = VMA_PAD_START(vma);
p->mode = vma->vm_file->f_mode;
}
mmap_read_unlock(mm);