Make uprobe attachment APK aware
Status from this message: This series was applied to bpf/bpf-next.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest3 patches 0 repliesApplied 3/3
- v33 patches 2 repliesSuperseded
- v23 patches 5 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 3 patches | 12 replies | Superseded |
Changes in v4 from the cover letter
- use ERR_PTR instead of libbpf_err_ptr() in zip_archive_open()
- eliminated err variable from elf_find_func_offset_from_archive()
Patches in v4 All 3 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | libbpf: Implement basic zip archive parsing supporttools/ tools/ tools/ | +376 | 0 replies | Applied |
| 2/3 | libbpf: Introduce elf_find_func_offset_from_file() functiontools/ | +36 | 0 replies | Applied |
| 3/3 | libbpf: Add support for attaching uprobes to shared objects in APKstools/ | +84 | 0 replies | Applied |
Reviews trailers per patch
1 of 3 patches has a Reviewed-by or Acked-by.
| Patch | Michał Gregorczyk |
|---|---|
| 1/3 | A-b |
| 2/3 | |
| 3/3 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v4 0/3] Make uprobe attachment APK aware
On Android, APKs (android packages; zip packages with somewhat prescriptive contents) are first class citizens in the system: the shared objects contained in them don't exist in unpacked form on the file system. Rather, they are mmaped directly from within the archive and the archive is also what the kernel is aware of.
For users that complicates the process of attaching a uprobe to a function contained in a shared object in one such APK: they'd have to find the byte offset of said function from the beginning of the archive. That is cumbersome to do manually and can be fragile, because various changes could invalidate said offset.
That is why for uprobes inside ELF files (not inside an APK), commit d112c9ce249b ("libbpf: Support function name-based attach uprobes") added support for attaching to symbols by name. On Android, that mechanism currently does not work, because this logic is not APK aware.
This patch set introduces first class support for attaching uprobes to functions inside ELF objects contained in APKs via function names. We add support for recognizing the following syntax for a binary path:
<archive>!/<binary-in-archive>
(e.g., /system/app/test-app.apk!/lib/arm64-v8a/libc++.so)
This syntax is common in the Android eco system and used by tools such as simpleperf. It is also what is being proposed for bcc [0].
If the user provides such a binary path, we find <binary-in-archive> (lib/arm64-v8a/libc++.so in the example) inside of <archive> (/system/app/test-app.apk). We perform the regular ELF offset search inside the binary and add that to the offset within the archive itself, to retrieve the offset at which to attach the uprobe.
[0] https://github.com/iovisor/bcc/pull/4440
Changelog
---------v3->v4:
- use ERR_PTR instead of libbpf_err_ptr() in zip_archive_open()
- eliminated err variable from elf_find_func_offset_from_archive()
v2->v3:
- adjusted zip_archive_open() to report errno
- fixed provided libbpf_strlcpy() buffer size argument
- adjusted find_cd() to handle errors better
- use fewer local variables in get_entry_at_offset()
v1->v2:
- removed unaligned_* types
- switched to using __u32 and __u16
- switched to using errno constants instead of hard-coded negative values
- added another pr_debug() message
- shortened central_directory_* to cd_*
- inlined cd_file_header_at_offset() function
- bunch of syntactical changes
Daniel Müller (3):
libbpf: Implement basic zip archive parsing support
libbpf: Introduce elf_find_func_offset_from_file() function
libbpf: Add support for attaching uprobes to shared objects in APKs
tools/lib/bpf/Build | 2 +- tools/lib/bpf/libbpf.c | 146 ++++++++++++++---- tools/lib/bpf/zip.c | 328 +++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/zip.h | 47 ++++++ 4 files changed, 495 insertions(+), 28 deletions(-) create mode 100644 tools/lib/bpf/zip.c create mode 100644 tools/lib/bpf/zip.h
Signature · 1 line
2.39.2