<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/tools/lib/bpf/linker.c, branch linux-6.12.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.12.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.12.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2025-06-19T13:31:45Z</updated>
<entry>
<title>libbpf: Use proper errno value in linker</title>
<updated>2025-06-19T13:31:45Z</updated>
<author>
<name>Anton Protopopov</name>
</author>
<published>2025-04-30T12:08:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=277f9ffe873a76be46ddda3c59addfe16dab5bec'/>
<id>urn:sha1:277f9ffe873a76be46ddda3c59addfe16dab5bec</id>
<content type='text'>
[ Upstream commit 358b1c0f56ebb6996fcec7dcdcf6bae5dcbc8b6c ]

Return values of the linker_append_sec_data() and the
linker_append_elf_relos() functions are propagated all the
way up to users of libbpf API. In some error cases these
functions return -1 which will be seen as -EPERM from user's
point of view. Instead, return a more reasonable -EINVAL.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Anton Protopopov &lt;a.s.protopopov@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20250430120820.2262053-1-a.s.protopopov@gmail.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix hypothetical STT_SECTION extern NULL deref case</title>
<updated>2025-04-10T12:39:18Z</updated>
<author>
<name>Andrii Nakryiko</name>
</author>
<published>2025-02-20T00:28:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=652a3dfd8c2bfeff26f56325a44b666258a2062d'/>
<id>urn:sha1:652a3dfd8c2bfeff26f56325a44b666258a2062d</id>
<content type='text'>
[ Upstream commit e0525cd72b5979d8089fe524a071ea93fd011dc9 ]

Fix theoretical NULL dereference in linker when resolving *extern*
STT_SECTION symbol against not-yet-existing ELF section. Not sure if
it's possible in practice for valid ELF object files (this would require
embedded assembly manipulations, at which point BTF will be missing),
but fix the s/dst_sym/dst_sec/ typo guarding this condition anyways.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Fixes: a46349227cd8 ("libbpf: Add linker extern resolution support for functions and global variables")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/r/20250220002821.834400-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix segfault due to libelf functions not setting errno</title>
<updated>2025-02-08T08:57:27Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2024-12-05T13:59:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a230cd305198491b67a19d6cfd442319340333ba'/>
<id>urn:sha1:a230cd305198491b67a19d6cfd442319340333ba</id>
<content type='text'>
[ Upstream commit e10500b69c3f3378f3dcfc8c2fe4cdb74fc844f5 ]

Libelf functions do not set errno on failure. Instead, it relies on its
internal _elf_errno value, that can be retrieved via elf_errno (or the
corresponding message via elf_errmsg()). From "man libelf":

    If a libelf function encounters an error it will set an internal
    error code that can be retrieved with elf_errno. Each thread
    maintains its own separate error code. The meaning of each error
    code can be determined with elf_errmsg, which returns a string
    describing the error.

As a consequence, libbpf should not return -errno when a function from
libelf fails, because an empty value will not be interpreted as an error
and won't prevent the program to stop. This is visible in
bpf_linker__add_file(), for example, where we call a succession of
functions that rely on libelf:

    err = err ?: linker_load_obj_file(linker, filename, opts, &amp;obj);
    err = err ?: linker_append_sec_data(linker, &amp;obj);
    err = err ?: linker_append_elf_syms(linker, &amp;obj);
    err = err ?: linker_append_elf_relos(linker, &amp;obj);
    err = err ?: linker_append_btf(linker, &amp;obj);
    err = err ?: linker_append_btf_ext(linker, &amp;obj);

If the object file that we try to process is not, in fact, a correct
object file, linker_load_obj_file() may fail with errno not being set,
and return 0. In this case we attempt to run linker_append_elf_sysms()
and may segfault.

This can happen (and was discovered) with bpftool:

    $ bpftool gen object output.o sample_ret0.bpf.c
    libbpf: failed to get ELF header for sample_ret0.bpf.c: invalid `Elf' handle
    zsh: segmentation fault (core dumped)  bpftool gen object output.o sample_ret0.bpf.c

Fix the issue by returning a non-null error code (-EINVAL) when libelf
functions fail.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20241205135942.65262-1-qmo@kernel.org
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Fix output .symtab byte-order during linking</title>
<updated>2024-12-05T13:01:40Z</updated>
<author>
<name>Tony Ambardar</name>
</author>
<published>2024-09-16T08:37:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d0125c0c83494f9cbe1e07a8d76f70ffb1f4860e'/>
<id>urn:sha1:d0125c0c83494f9cbe1e07a8d76f70ffb1f4860e</id>
<content type='text'>
[ Upstream commit f896b4a5399e97af0b451fcf04754ed316935674 ]

Object linking output data uses the default ELF_T_BYTE type for '.symtab'
section data, which disables any libelf-based translation. Explicitly set
the ELF_T_SYM type for output to restore libelf's byte-order conversion,
noting that input '.symtab' data is already correctly translated.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Tony Ambardar &lt;tony.ambardar@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/87868bfeccf3f51aec61260073f8778e9077050a.1726475448.git.tony.ambardar@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: fix some typos in libbpf</title>
<updated>2024-09-05T20:07:47Z</updated>
<author>
<name>Lin Yikai</name>
</author>
<published>2024-09-05T11:03:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bd4d67f8ae55d42273c6cd661b622ed713d20350'/>
<id>urn:sha1:bd4d67f8ae55d42273c6cd661b622ed713d20350</id>
<content type='text'>
Hi, fix some spelling errors in libbpf, the details are as follows:

-in the code comments:
	termintaing-&gt;terminating
	architecutre-&gt;architecture
	requring-&gt;requiring
	recored-&gt;recoded
	sanitise-&gt;sanities
	allowd-&gt;allowed
	abover-&gt;above
	see bpf_udst_arg()-&gt;see bpf_usdt_arg()

Signed-off-by: Lin Yikai &lt;yikai.lin@vivo.com&gt;
Link: https://lore.kernel.org/r/20240905110354.3274546-3-yikai.lin@vivo.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>libbpf: Checking the btf_type kind when fixing variable offsets</title>
<updated>2024-06-21T18:00:17Z</updated>
<author>
<name>Donglin Peng</name>
</author>
<published>2024-06-19T12:23:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cc5083d1f3881624ad2de1f3cbb3a07e152cb254'/>
<id>urn:sha1:cc5083d1f3881624ad2de1f3cbb3a07e152cb254</id>
<content type='text'>
I encountered an issue when building the test_progs from the repository [1]:

  $ pwd
  /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/

  $ make test_progs V=1
  [...]
  ./tools/sbin/bpftool gen object ./ip_check_defrag.bpf.linked2.o ./ip_check_defrag.bpf.linked1.o
  libbpf: failed to find symbol for variable 'bpf_dynptr_slice' in section '.ksyms'
  Error: failed to link './ip_check_defrag.bpf.linked1.o': No such file or directory (2)
  [...]

Upon investigation, I discovered that the btf_types referenced in the '.ksyms'
section had a kind of BTF_KIND_FUNC instead of BTF_KIND_VAR:

  $ bpftool btf dump file ./ip_check_defrag.bpf.linked1.o
  [...]
  [2] DATASEC '.ksyms' size=0 vlen=2
        type_id=16 offset=0 size=0 (FUNC 'bpf_dynptr_from_skb')
        type_id=17 offset=0 size=0 (FUNC 'bpf_dynptr_slice')
  [...]
  [16] FUNC 'bpf_dynptr_from_skb' type_id=82 linkage=extern
  [17] FUNC 'bpf_dynptr_slice' type_id=85 linkage=extern
  [...]

For a detailed analysis, please refer to [2]. We can add a kind checking to
fix the issue.

  [1] https://github.com/eddyz87/bpf/tree/binsort-btf-dedup
  [2] https://lore.kernel.org/all/0c0ef20c-c05e-4db9-bad7-2cbc0d6dfae7@oracle.com/

Fixes: 8fd27bf69b86 ("libbpf: Add BPF static linker BTF and BTF.ext support")
Signed-off-by: Donglin Peng &lt;dolinux.peng@gmail.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Reviewed-by: Alan Maguire &lt;alan.maguire@oracle.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20240619122355.426405-1-dolinux.peng@gmail.com
</content>
</entry>
<entry>
<title>libbpf: Make use of BTF field iterator in BPF linker code</title>
<updated>2024-06-05T14:54:32Z</updated>
<author>
<name>Andrii Nakryiko</name>
</author>
<published>2024-06-05T00:16:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2bce2c1cb2f0acbf619737a10575f99df0c43984'/>
<id>urn:sha1:2bce2c1cb2f0acbf619737a10575f99df0c43984</id>
<content type='text'>
Switch all BPF linker code dealing with iterating BTF type ID and string
offset fields to new btf_field_iter facilities.

Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Tested-by: Alan Maguire &lt;alan.maguire@oracle.com&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Acked-by: Jiri Olsa &lt;jolsa@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240605001629.4061937-3-andrii@kernel.org
</content>
</entry>
<entry>
<title>libbpf: Add missed btf_ext__raw_data() API</title>
<updated>2024-02-01T21:16:12Z</updated>
<author>
<name>Andrii Nakryiko</name>
</author>
<published>2024-02-01T17:20:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b9551da8cf3ade01a50316df8a618fd945723ee0'/>
<id>urn:sha1:b9551da8cf3ade01a50316df8a618fd945723ee0</id>
<content type='text'>
Another API that was declared in libbpf.map but actual implementation
was missing. btf_ext__get_raw_data() was intended as a discouraged alias
to consistently-named btf_ext__raw_data(), so make this an actuality.

Fixes: 20eccf29e297 ("libbpf: hide and discourage inconsistently named getters")
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20240201172027.604869-5-andrii@kernel.org
</content>
</entry>
<entry>
<title>libbpf: Skip DWARF sections in linker sanity check</title>
<updated>2023-12-21T09:05:15Z</updated>
<author>
<name>Alyssa Ross</name>
</author>
<published>2023-12-19T11:03:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=812d8bf87678f77055b575d20636fdbbbf15edaf'/>
<id>urn:sha1:812d8bf87678f77055b575d20636fdbbbf15edaf</id>
<content type='text'>
clang can generate (with -g -Wa,--compress-debug-sections) 4-byte
aligned DWARF sections that declare themselves to be 8-byte aligned in
the section header.  Since DWARF sections are dropped during linking
anyway, just skip running the sanity checks on them.

Reported-by: Sergei Trofimovich &lt;slyich@gmail.com&gt;
Suggested-by: Andrii Nakryiko &lt;andrii.nakryiko@gmail.com&gt;
Signed-off-by: Alyssa Ross &lt;hi@alyssa.is&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Closes: https://lore.kernel.org/bpf/ZXcFRJVKbKxtEL5t@nz.home/
Link: https://lore.kernel.org/bpf/20231219110324.8989-1-hi@alyssa.is
</content>
</entry>
<entry>
<title>libbpf: Add pr_warn() for EINVAL cases in linker_sanity_check_elf</title>
<updated>2023-12-09T01:11:18Z</updated>
<author>
<name>Sergei Trofimovich</name>
</author>
<published>2023-12-08T21:51:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=32fa058398624166dd04ff4af49cfef69c94abbc'/>
<id>urn:sha1:32fa058398624166dd04ff4af49cfef69c94abbc</id>
<content type='text'>
Before the change on `i686-linux` `systemd` build failed as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

After the change it fails as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    libbpf: ELF section #9 has inconsistent alignment addr=8 != d=4 in src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

Now it's slightly easier to figure out what is wrong with an ELF file.

Signed-off-by: Sergei Trofimovich &lt;slyich@gmail.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Eduard Zingerman &lt;eddyz87@gmail.com&gt;
Link: https://lore.kernel.org/bpf/20231208215100.435876-1-slyich@gmail.com
</content>
</entry>
</feed>
