<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/tools/bpf/bpftool/main.c, branch linux-6.16.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.16.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.16.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2025-08-20T16:41:18Z</updated>
<entry>
<title>bpftool: Fix JSON writer resource leak in version command</title>
<updated>2025-08-20T16:41:18Z</updated>
<author>
<name>Yuan Chen</name>
</author>
<published>2025-06-17T13:24:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=04059932fb1edc02a2660196ccbbe95562246e40'/>
<id>urn:sha1:04059932fb1edc02a2660196ccbbe95562246e40</id>
<content type='text'>
[ Upstream commit 85cd83fed8267cde0dd1cea719808aad95ae4de7 ]

When using `bpftool --version -j/-p`, the JSON writer object
created in do_version() was not properly destroyed after use.
This caused a memory leak each time the version command was
executed with JSON output.

Fix: 004b45c0e51a (tools: bpftool: provide JSON output for all possible commands)

Suggested-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Signed-off-by: Yuan Chen &lt;chenyuan@kylinos.cn&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20250617132442.9998-1-chenyuan_fl@163.com
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Using the right format specifiers</title>
<updated>2025-02-11T00:08:13Z</updated>
<author>
<name>Jiayuan Chen</name>
</author>
<published>2025-02-07T12:37:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=17c3dc50294ba445ddc7d50020df6452e93d38b2'/>
<id>urn:sha1:17c3dc50294ba445ddc7d50020df6452e93d38b2</id>
<content type='text'>
Fixed some formatting specifiers errors, such as using %d for int and %u
for unsigned int, as well as other byte-length types.

Signed-off-by: Jiayuan Chen &lt;mrpre@163.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20250207123706.727928-2-mrpre@163.com
</content>
</entry>
<entry>
<title>bpftool: clean-up usage of libbpf_get_error()</title>
<updated>2022-11-21T00:17:46Z</updated>
<author>
<name>Sahid Orentino Ferdjaoui</name>
</author>
<published>2022-11-20T11:26:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d1313e01271d2d8f33d6c82f1afb77e820a3540d'/>
<id>urn:sha1:d1313e01271d2d8f33d6c82f1afb77e820a3540d</id>
<content type='text'>
bpftool is now totally compliant with libbpf 1.0 mode and is not
expected to be compiled with pre-1.0, let's clean-up the usage of
libbpf_get_error().

The changes stay aligned with returned errors always negative.

- In tools/bpf/bpftool/btf.c This fixes an uninitialized local
variable `err` in function do_dump() because it may now be returned
without having been set.
- This also removes the checks on NULL pointers before calling
btf__free() because that function already does the check.

Signed-off-by: Sahid Orentino Ferdjaoui &lt;sahid.ferdjaoui@industrialdiscipline.com&gt;
Link: https://lore.kernel.org/r/20221120112515.38165-5-sahid.ferdjaoui@industrialdiscipline.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: remove support of --legacy option for bpftool</title>
<updated>2022-11-21T00:17:46Z</updated>
<author>
<name>Sahid Orentino Ferdjaoui</name>
</author>
<published>2022-11-20T11:25:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9b8107553424fd87955fed257a807672c2097297'/>
<id>urn:sha1:9b8107553424fd87955fed257a807672c2097297</id>
<content type='text'>
Following:
  commit bd054102a8c7 ("libbpf: enforce strict libbpf 1.0 behaviors")
  commit 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")

The --legacy option is no longer relevant as libbpf no longer supports
it. libbpf_set_strict_mode() is a no-op operation.

Signed-off-by: Sahid Orentino Ferdjaoui &lt;sahid.ferdjaoui@industrialdiscipline.com&gt;
Acked-by: Yonghong Song &lt;yhs@fb.com&gt;
Reviewed-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Link: https://lore.kernel.org/r/20221120112515.38165-2-sahid.ferdjaoui@industrialdiscipline.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Check argc first before "file" in do_batch()</title>
<updated>2022-11-16T05:36:24Z</updated>
<author>
<name>Tiezhu Yang</name>
</author>
<published>2022-11-15T13:00:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=df9c41e9db2d0fc9feba0423c21e4319d8acd033'/>
<id>urn:sha1:df9c41e9db2d0fc9feba0423c21e4319d8acd033</id>
<content type='text'>
If the parameters for batch are more than 2, check argc first can
return immediately, no need to use is_prefix() to check "file" with
a little overhead and then check argc, it is better to check "file"
only when the parameters for batch are 2.

Signed-off-by: Tiezhu Yang &lt;yangtiezhu@loongson.cn&gt;
Acked-by: Stanislav Fomichev &lt;sdf@google.com&gt;
Reviewed-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Link: https://lore.kernel.org/r/1668517207-11822-1-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Add llvm feature to "bpftool version"</title>
<updated>2022-10-25T17:11:57Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-10-25T15:03:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=08b8191ba7f99cd1444001e9f4800ff27607d054'/>
<id>urn:sha1:08b8191ba7f99cd1444001e9f4800ff27607d054</id>
<content type='text'>
Similarly to "libbfd", add a "llvm" feature to the output of command
"bpftool version" to indicate that LLVM is used for disassembling JIT-ed
programs. This feature is mutually exclusive (from Makefile definitions)
with "libbfd".

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Tested-by: Niklas Söderlund &lt;niklas.soderlund@corigine.com&gt;
Acked-by: Yonghong Song &lt;yhs@fb.com&gt;
Link: https://lore.kernel.org/r/20221025150329.97371-9-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Add "bootstrap" feature to version output</title>
<updated>2022-10-21T21:41:13Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-10-20T10:03:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2c76238eaddd7c519f6b5a7ed80f7da6f4e11373'/>
<id>urn:sha1:2c76238eaddd7c519f6b5a7ed80f7da6f4e11373</id>
<content type='text'>
Along with the version number, "bpftool version" displays a list of
features that were selected at compilation time for bpftool. It would be
useful to indicate in that list whether a binary is a bootstrap version
of bpftool. Given that an increasing number of components rely on
bootstrap versions for generating skeletons, this could help understand
what a binary is capable of if it has been copied outside of the usual
"bootstrap" directory.

To detect a bootstrap version, we simply rely on the absence of
implementation for the do_prog() function. To do this, we must move the
(unchanged) list of commands before do_version(), which in turn requires
renaming this "cmds" array to avoid shadowing it with the "cmds"
argument in cmd_select().

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20221020100332.69563-1-quentin@isovalent.com
</content>
</entry>
<entry>
<title>bpftool: Set binary name to "bpftool" in help and version output</title>
<updated>2022-10-21T21:37:46Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-10-20T10:03:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7e5eb725cf0a0a8f85e6b96e062bbd0d5d90c94e'/>
<id>urn:sha1:7e5eb725cf0a0a8f85e6b96e062bbd0d5d90c94e</id>
<content type='text'>
Commands "bpftool help" or "bpftool version" use argv[0] to display the
name of the binary. While it is a convenient way to retrieve the string,
it does not always produce the most readable output. For example,
because of the way bpftool is currently packaged on Ubuntu (using a
wrapper script), the command displays the absolute path for the binary:

    $ bpftool version | head -n 1
    /usr/lib/linux-tools/5.15.0-50-generic/bpftool v5.15.60

More generally, there is no apparent reason for keeping the whole path
and exact binary name in this output. If the user wants to understand
what binary is being called, there are other ways to do so. This commit
replaces argv[0] with "bpftool", to simply reflect what the tool is
called. This is aligned on what "ip" or "tc" do, for example.

As an additional benefit, this seems to help with integration with
Meson for packaging [0].

[0] https://github.com/NixOS/nixpkgs/pull/195934

Suggested-by: Vladimír Čunát &lt;vladimir.cunat@nic.cz&gt;
Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20221020100300.69328-1-quentin@isovalent.com
</content>
</entry>
<entry>
<title>bpftool: Clear errno after libcap's checks</title>
<updated>2022-08-15T18:37:33Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-08-15T16:22:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cea558855c39b7f1f02ff50dcf701ca6596bc964'/>
<id>urn:sha1:cea558855c39b7f1f02ff50dcf701ca6596bc964</id>
<content type='text'>
When bpftool is linked against libcap, the library runs a "constructor"
function to compute the number of capabilities of the running kernel
[0], at the beginning of the execution of the program. As part of this,
it performs multiple calls to prctl(). Some of these may fail, and set
errno to a non-zero value:

    # strace -e prctl ./bpftool version
    prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
    prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
    prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1
    prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
    prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
    prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
    ** fprintf added at the top of main(): we have errno == 1
    ./bpftool v7.0.0
    using libbpf v1.0
    features: libbfd, libbpf_strict, skeletons
    +++ exited with 0 +++

This has been addressed in libcap 2.63 [1], but until this version is
available everywhere, we can fix it on bpftool side.

Let's clean errno at the beginning of the main() function, to make sure
that these checks do not interfere with the batch mode, where we error
out if errno is set after a bpftool command.

  [0] https://git.kernel.org/pub/scm/libs/libcap/libcap.git/tree/libcap/cap_alloc.c?h=libcap-2.65#n20
  [1] https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=f25a1b7e69f7b33e6afb58b3e38f3450b7d2d9a0

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20220815162205.45043-1-quentin@isovalent.com
</content>
</entry>
<entry>
<title>bpftool: Do not check return value from libbpf_set_strict_mode()</title>
<updated>2022-06-14T20:18:56Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-06-10T11:26:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=93270357daa949e4bed375b40d0a100ce04f3399'/>
<id>urn:sha1:93270357daa949e4bed375b40d0a100ce04f3399</id>
<content type='text'>
The function always returns 0, so we don't need to check whether the
return value is 0 or not.

This change was first introduced in commit a777e18f1bcd ("bpftool: Use
libbpf 1.0 API mode instead of RLIMIT_MEMLOCK"), but later reverted to
restore the unconditional rlimit bump in bpftool. Let's re-add it.

Co-developed-by: Yafang Shao &lt;laoar.shao@gmail.com&gt;
Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Link: https://lore.kernel.org/bpf/20220610112648.29695-3-quentin@isovalent.com
</content>
</entry>
</feed>
