From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 03/12] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write
Date: Mon, 09 Nov 2026 00:45:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-204254@kernel.org> (raw)
In-Reply-To: <179418411197.227715.5577722703946865281.stgit@devnote2>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/probes: unaligned kflag=0 bitfields fail in
get_bitoffset_of_field()
--
commit 2e4831ec2095ef67023431da46d322fba9d204db
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>
tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write
This commit fixes BTF bitfield offset calculation, selects an unsigned fetch
type wide enough to cover the bit offset and width, and derives the
FETCH_OP_MOD_BF shift and basesize parameters from the selected fetch type.
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index a880a90642d7c..26e02929f1ffb 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
[ ... ]
> @@ -653,6 +661,12 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
> /* Add anonymous structure/union offset */
> bitoffs += anon_offs;
>
> + type = btf_type_skip_modifiers(btf, field->type, NULL);
> + if (!type) {
> + trace_probe_log_err(ctx->offset, BAD_BTF_TID);
> + return -EINVAL;
> + }
> +
> /* Accumulate the bit-offsets of the dot-connected fields */
> if (btf_type_kflag(container_type)) {
> bitoffs += BTF_MEMBER_BIT_OFFSET(field->offset);
> @@ -660,12 +674,15 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
> } else {
> bitoffs += field->offset;
> ctx->last_bitsize = 0;
> - }
> + if (BTF_INFO_KIND(type->info) == BTF_KIND_INT) {
> + u32 intdata = btf_type_int(type);
>
> - type = btf_type_skip_modifiers(btf, field->type, NULL);
> - if (!type) {
> - trace_probe_log_err(ctx->offset, BAD_BTF_TID);
> - return -EINVAL;
> + if (BTF_INT_OFFSET(intdata) ||
> + BTF_INT_BITS(intdata) != BYTES_TO_BITS(type->size)) {
> + bitoffs += BTF_INT_OFFSET(intdata);
> + ctx->last_bitsize = BTF_INT_BITS(intdata);
> + }
> + }
> }
[Severity: Medium]
Does this leave ctx->last_bitsize as 0 when a kflag=0 bitfield has a bit
width matching its underlying integer type size (such as an 8-bit bitfield
backed by a 1-byte BTF_KIND_INT with BTF_INT_OFFSET(intdata) == 0) at a
non-byte-aligned member offset (bitoffs % 8 != 0)?
When that happens, parse_btf_field() sets a non-zero ctx->last_bitoffs while
ctx->last_bitsize remains 0. fetch_type_from_btf_type() then does not widen
the fetch type to cover the unaligned field across the byte boundary, and
parse_btf_bitfield() rejects the probe with BAD_BITFIELD (-EINVAL) because
ctx->last_bitsize == 0 while ctx->last_bitoffs != 0.
Checking bitoffs % 8 != 0 alongside BTF_INT_OFFSET(intdata) and
BTF_INT_BITS(intdata) != BYTES_TO_BITS(type->size) would record
ctx->last_bitsize for unaligned byte-sized kflag=0 bitfields as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179418408457.227715.1485179201014819821.stgit@devnote2?part=3
next prev parent reply other threads:[~2026-11-09 0:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 0:28 [PATCH 00/12] tracing/probes: Fix various bugs in dynamic probe events Masami Hiramatsu (Google)
2026-11-09 0:28 ` [PATCH 01/12] tracing/probes: Check enabled and busy state before unlinking sibling probes Masami Hiramatsu (Google)
2026-11-09 0:28 ` [PATCH 02/12] tracing/probes: Enable newly appended probe when target event is enabled Masami Hiramatsu (Google)
2026-11-09 0:28 ` [PATCH 03/12] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write Masami Hiramatsu (Google)
2026-11-09 0:45 ` sashiko-bot [this message]
2026-11-09 0:28 ` [PATCH 04/12] tracing/probes: Fix missing BTF kind checks in char pointer/array helpers Masami Hiramatsu (Google)
2026-11-09 0:28 ` [PATCH 05/12] tracing/eprobe: Fix 1-byte signed field fetch in get_event_field() Masami Hiramatsu (Google)
2026-11-09 0:28 ` [PATCH 06/12] tracing/eprobe: Disallow attaching eprobes to fprobe events Masami Hiramatsu (Google)
2026-11-09 0:29 ` [PATCH 07/12] tracing/probes: Fix user-space dereference string array store type Masami Hiramatsu (Google)
2026-11-09 0:29 ` [PATCH 08/12] tracing/probes: Reject array count on non-dereference string sources Masami Hiramatsu (Google)
2026-11-09 0:41 ` sashiko-bot
2026-11-09 0:29 ` [PATCH 09/12] tracing/probes: Allow symstr type for function entry arguments in return probes Masami Hiramatsu (Google)
2026-11-09 0:29 ` [PATCH 10/12] tracing/probes: Reject empty fetch expression for %pd and %pD Masami Hiramatsu (Google)
2026-11-09 0:29 ` [PATCH 11/12] tracing/probes: Validate command prefix in kprobe, uprobe, and eprobe Masami Hiramatsu (Google)
2026-11-09 0:47 ` sashiko-bot
2026-11-09 0:29 ` [PATCH 12/12] tracing/probes: Propagate error codes in eprobe and fprobe creation Masami Hiramatsu (Google)
2026-11-09 0:46 ` sashiko-bot
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-204254@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--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