1. 02 Mar, 2023 6 commits
    • Andrii Nakryiko's avatar
      Merge branch 'Make uprobe attachment APK aware' · b1d462bc
      Andrii Nakryiko authored
      Daniel Müller says:
      
      ====================
      
      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
      ====================
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      b1d462bc
    • Daniel Müller's avatar
      libbpf: Add support for attaching uprobes to shared objects in APKs · c44fd845
      Daniel Müller authored
      This change adds support for attaching uprobes to shared objects located
      in APKs, which is relevant for Android systems where various libraries
      may reside in APKs. To make that happen, we extend the syntax for the
      "binary path" argument to attach to with that supported by various
      Android tools:
        <archive>!/<binary-in-archive>
      
      For example:
        /system/app/test-app/test-app.apk!/lib/arm64-v8a/libc++_shared.so
      
      APKs need to be specified via full path, i.e., we do not attempt to
      resolve mere file names by searching system directories.
      
      We cannot currently test this functionality end-to-end in an automated
      fashion, because it relies on an Android system being present, but there
      is no support for that in CI. I have tested the functionality manually,
      by creating a libbpf program containing a uretprobe, attaching it to a
      function inside a shared object inside an APK, and verifying the sanity
      of the returned values.
      Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20230301212308.1839139-4-deso@posteo.net
      c44fd845
    • Daniel Müller's avatar
      libbpf: Introduce elf_find_func_offset_from_file() function · 434fdcea
      Daniel Müller authored
      This change splits the elf_find_func_offset() function in two:
      elf_find_func_offset(), which now accepts an already opened Elf object
      instead of a path to a file that is to be opened, as well as
      elf_find_func_offset_from_file(), which opens a binary based on a
      path and then invokes elf_find_func_offset() on the Elf object. Having
      this split in responsibilities will allow us to call
      elf_find_func_offset() from other code paths on Elf objects that did not
      necessarily come from a file on disk.
      Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20230301212308.1839139-3-deso@posteo.net
      434fdcea
    • Daniel Müller's avatar
      libbpf: Implement basic zip archive parsing support · 1eebcb60
      Daniel Müller authored
      This change implements support for reading zip archives, including
      opening an archive, finding an entry based on its path and name in it,
      and closing it.
      The code was copied from https://github.com/iovisor/bcc/pull/4440, which
      implements similar functionality for bcc. The author confirmed that he
      is fine with this usage and the corresponding relicensing. I adjusted it
      to adhere to libbpf coding standards.
      Signed-off-by: default avatarDaniel Müller <deso@posteo.net>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarMichał Gregorczyk <michalgr@meta.com>
      Link: https://lore.kernel.org/bpf/20230301212308.1839139-2-deso@posteo.net
      1eebcb60
    • David Vernet's avatar
      bpf, docs: Fix __uninit kfunc doc section · db52b587
      David Vernet authored
      In commit d96d937d ("bpf: Add __uninit kfunc annotation"), the
      __uninit kfunc annotation was documented in kfuncs.rst. You have to
      fully underline a section in rst, or the build will issue a warning that
      the title underline is too short:
      
      ./Documentation/bpf/kfuncs.rst:104: WARNING: Title underline too short.
      
      2.2.2 __uninit Annotation
      --------------------
      
      This patch fixes that title underline.
      
      Fixes: d96d937d ("bpf: Add __uninit kfunc annotation")
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20230301194910.602738-2-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      db52b587
    • David Vernet's avatar
      bpf: Fix doxygen comments for dynptr slice kfuncs · 7ce60b11
      David Vernet authored
      In commit 66e3a13e ("bpf: Add bpf_dynptr_slice and
      bpf_dynptr_slice_rdwr"), the bpf_dynptr_slice() and
      bpf_dynptr_slice_rdwr() kfuncs were added to BPF. These kfuncs included
      doxygen headers, but unfortunately those headers are not properly
      formatted according to [0], and causes the following warnings during the
      docs build:
      
      ./kernel/bpf/helpers.c:2225: warning: \
          Excess function parameter 'returns' description in 'bpf_dynptr_slice'
      ./kernel/bpf/helpers.c:2303: warning: \
          Excess function parameter 'returns' description in 'bpf_dynptr_slice_rdwr'
      ...
      
      This patch fixes those doxygen comments.
      
      [0]: https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation
      
      Fixes: 66e3a13e ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr")
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/r/20230301194910.602738-1-void@manifault.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      7ce60b11
  2. 01 Mar, 2023 22 commits
  3. 28 Feb, 2023 4 commits
  4. 27 Feb, 2023 7 commits
  5. 25 Feb, 2023 1 commit