lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAP_z_Cj-v+h6giXb4W3NuVEN5+QMJwTQgqWO7cQHMgPxzSCZ=Q@mail.gmail.com>
Date: Tue, 3 Jun 2025 13:36:21 -0700
From: Blake Jones <blakejones@...gle.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Jiri Olsa <olsajiri@...il.com>, Alexei Starovoitov <ast@...nel.org>, 
	Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>, 
	Martin KaFai Lau <martin.lau@...ux.dev>, Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
	Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>, 
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, 
	Mykola Lysenko <mykolal@...com>, Shuah Khan <shuah@...nel.org>, 
	Ihor Solodrai <ihor.solodrai@...ux.dev>, Namhyung Kim <namhyung@...nel.org>, 
	Ian Rogers <irogers@...gle.com>, bpf@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 1/2] libbpf: add support for printing BTF character
 arrays as strings

Hi Andrii,

On Tue, Jun 3, 2025 at 11:39 AM Andrii Nakryiko
<andrii.nakryiko@...il.com> wrote:
> > Good question. That E2BIG error would happen, for example, if we tried
> > to print the array "{ 'a', 'b', 'c' }" when the type was "char[4]".
>
> Exactly, data is truncated, we have to return E2BIG. But I think that
> is checked earlier with btf_dump_type_data_check_overflow(), so we
> probably don't need to do this here?

btf_dump_type_data_check_overflow() only looks at INT, FLOAT, PTR, ENUM,
and ENUM64 types:
https://elixir.bootlin.com/linux/v6.15/source/tools/lib/bpf/btf_dump.c#L2304-L2315

So we still need to do this manually for this ARRAY type.

> Please add tests with truncated data so we know for sure?

I've added tests; see below.

> > I'd say your proposed behavior would be consistent with the semantic of
> > ".emit_strings should display strings in an intuitively useful way",
>
> It still should follow the overall contract, so I think E2BIG is
> justified for truncated data.
>
> But there is also a bit of a quirk. If a string is not
> zero-terminated, we actually don't distinguish it in any way. Would it
> make sense to detect this and still print it as an array of individual
> characters? It's clearly not a valid C string at that point, so
> emit_strings doesn't have to apply. WDYT? The implementation would be
> simple -- find zero in an array, if found - emit everything up to that
> point as string, if not - emit character array?

I don't have strong feelings one way or another, so I've just implemented
this.  btf_dump_array_data() now keeps going and does its current behavior
if btf_dump_string_data() hit an error. In practice, btf_dump_array_data()
does *not* return E2BIG if the provided array is too big for the type; it
just displays the first N elements of the array and then returns. I don't
plan to change this behavior.

Updated patches coming shortly.

Blake

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ