From: sashiko-bot@kernel.org
To: "Hungyu Lin" <dennylin0707@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 2/2] selftests/bpf: Dump unaligned enums and a zeroed fs_context
Date: Mon, 16 Nov 2026 08:20:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-216524@kernel.org> (raw)
In-Reply-To: <20261116080151.44860-3-dennylin0707@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/bpf: enum bitfield OOB read in
btf_dump_type_data_check_zero()
--
commit b08982c8f9a5f24d9685e27855c93f8136d3ee81
Author: Hungyu Lin <dennylin0707@gmail.com>
selftests/bpf: Dump unaligned enums and a zeroed fs_context
This commit extends the BTF dump selftests to dump a signed enum from an
unaligned address and a zeroed struct fs_context without emit_zeroes.
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> index b5c90f7293398..d6fd9933ff258 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
[ ... ]
> @@ -1182,6 +1184,12 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
> type_sz = btf__resolve_size(btf, type_id);
> str[0] = '\0';
>
> + /* 'phase' is an enum bitfield 3 bytes before the end */
> + ret = btf_dump__dump_type_data(d, type_id, zero_data, type_sz, &opts);
> + ASSERT_EQ(ret, type_sz,
> + "unexpected return value dumping zeroed fs_context");
> +
> + str[0] = '\0';
> opts.emit_zeroes = true;
> ret = btf_dump__dump_type_data(d, type_id, zero_data, type_sz, &opts);
> ASSERT_EQ(ret, type_sz,
[Severity: Medium]
Does dumping struct fs_context with emit_zeroes unset read 1 byte past
zero_data + type_sz when checking the phase enum bitfield?
In struct fs_context, phase is an 8-bit enum bitfield at byte offset
type_sz - 3 whose underlying enum type has t->size == 4.
btf_dump_type_data_check_overflow() only checks that the 1 byte covering
bit_sz fits before data_end, but btf_dump_type_data_check_zero() ignores
bit_sz for BTF_KIND_ENUM and reads a full t->size (4-byte) enum via
btf_dump_get_enum_value():
tools/lib/bpf/btf_dump.c:btf_dump_type_data_check_zero() {
case BTF_KIND_INT:
if (bit_sz)
return btf_dump_bitfield_check_zero(d, t, data, bits_offset, bit_sz);
return btf_dump_base_type_check_zero(d, t, id, data);
...
case BTF_KIND_ENUM:
case BTF_KIND_ENUM64:
err = btf_dump_get_enum_value(d, t, data, id, &value);
}
Because data is unaligned at offset type_sz - 3, btf_dump_get_enum_value()
calls memcpy(buf, data, t->size), reading 1 byte past data_end and mixing
adjacent bitfields (such as need_free) and trailing bytes into the zero
check. Even if btf_dump_bitfield_check_zero() were used,
btf_dump_get_bitfield_value() bounds-checks nr_bytes (1) against data_end
before looping over t->size (4) bytes, which also reads 1 byte past
data_end. Passing the 512-byte zero_data stack buffer here masks the
out-of-bounds read from AddressSanitizer and from the return-value check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116080151.44860-1-dennylin0707@gmail.com?part=2
prev parent reply other threads:[~2026-11-16 8:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 8:01 [PATCH bpf-next v3 0/2] Fix unaligned enum values in btf_dump Hungyu Lin
2026-11-16 8:01 ` [PATCH bpf-next v3 1/2] libbpf: Fix sign extension of unaligned enums in btf_dump_get_enum_value() Hungyu Lin
2026-11-16 8:01 ` [PATCH bpf-next v3 2/2] selftests/bpf: Dump unaligned enums and a zeroed fs_context Hungyu Lin
2026-11-16 8:20 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-216524@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dennylin0707@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox