1. 11 Sep, 2024 2 commits
    • Andrii Nakryiko's avatar
      lib/buildid: add single folio-based file reader abstraction · de3ec364
      Andrii Nakryiko authored
      Add freader abstraction that transparently manages fetching and local
      mapping of the underlying file page(s) and provides a simple direct data
      access interface.
      
      freader_fetch() is the only and single interface necessary. It accepts
      file offset and desired number of bytes that should be accessed, and
      will return a kernel mapped pointer that caller can use to dereference
      data up to requested size. Requested size can't be bigger than the size
      of the extra buffer provided during initialization (because, worst case,
      all requested data has to be copied into it, so it's better to flag
      wrongly sized buffer unconditionally, regardless if requested data range
      is crossing page boundaries or not).
      
      If folio is not paged in, or some of the conditions are not satisfied,
      NULL is returned and more detailed error code can be accessed through
      freader->err field. This approach makes the usage of freader_fetch()
      cleaner.
      
      To accommodate accessing file data that crosses folio boundaries, user
      has to provide an extra buffer that will be used to make a local copy,
      if necessary. This is done to maintain a simple linear pointer data
      access interface.
      
      We switch existing build ID parsing logic to it, without changing or
      lifting any of the existing constraints, yet. This will be done
      separately.
      
      Given existing code was written with the assumption that it's always
      working with a single (first) page of the underlying ELF file, logic
      passes direct pointers around, which doesn't really work well with
      freader approach and would be limiting when removing the single page (folio)
      limitation. So we adjust all the logic to work in terms of file offsets.
      
      There is also a memory buffer-based version (freader_init_from_mem())
      for cases when desired data is already available in kernel memory. This
      is used for parsing vmlinux's own build ID note. In this mode assumption
      is that provided data starts at "file offset" zero, which works great
      when parsing ELF notes sections, as all the parsing logic is relative to
      note section's start.
      Reviewed-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Reviewed-by: default avatarShakeel Butt <shakeel.butt@linux.dev>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20240829174232.3133883-3-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      de3ec364
    • Andrii Nakryiko's avatar
      lib/buildid: harden build ID parsing logic · 905415ff
      Andrii Nakryiko authored
      Harden build ID parsing logic, adding explicit READ_ONCE() where it's
      important to have a consistent value read and validated just once.
      
      Also, as pointed out by Andi Kleen, we need to make sure that entire ELF
      note is within a page bounds, so move the overflow check up and add an
      extra note_size boundaries validation.
      
      Fixes tag below points to the code that moved this code into
      lib/buildid.c, and then subsequently was used in perf subsystem, making
      this code exposed to perf_event_open() users in v5.12+.
      
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarEduard Zingerman <eddyz87@gmail.com>
      Reviewed-by: default avatarJann Horn <jannh@google.com>
      Suggested-by: default avatarAndi Kleen <ak@linux.intel.com>
      Fixes: bd7525da ("bpf: Move stack_map_get_build_id into lib")
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20240829174232.3133883-2-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      905415ff
  2. 10 Sep, 2024 3 commits
  3. 09 Sep, 2024 6 commits
  4. 06 Sep, 2024 5 commits
  5. 05 Sep, 2024 24 commits