From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/13] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write
Date: Thu, 12 Nov 2026 01:57:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-210125@kernel.org> (raw)
In-Reply-To: <179444682679.345731.13247927117747302891.stgit@devnote2>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/probes: wrong bitfield lshift on big-endian in
parse_btf_bitfield()
--
commit e5cd5bf4ce18aa0d644893f624a1f1a581f88aeb
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>
tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write
This commit updates BTF bitfield parsing in trace_probe.c to compute byte
and bit offsets consistently, select a matching unsigned fetch type, and
size FETCH_OP_MOD_BF shifts to the selected fetch type.
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index a880a90642d7c..3a57fe6b67cce 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
[ ... ]
> @@ -858,13 +876,22 @@ static const struct fetch_type *find_fetch_type_from_btf_type(
> }
>
> static int parse_btf_bitfield(struct fetch_insn **pcode,
> + const struct fetch_type *t,
> struct traceprobe_parse_context *ctx)
> {
> struct fetch_insn *code = *pcode;
>
> - if ((ctx->last_bitsize % 8 == 0) && ctx->last_bitoffs == 0)
> + if ((ctx->last_bitsize == 0 ||
> + ctx->last_bitsize == BYTES_TO_BITS(t->size)) &&
> + ctx->last_bitoffs == 0)
> return 0;
>
> + if (ctx->last_bitsize == 0 ||
> + BYTES_TO_BITS(t->size) < (ctx->last_bitsize + ctx->last_bitoffs)) {
> + trace_probe_log_err(ctx->offset, BAD_BITFIELD);
> + return -EINVAL;
> + }
> +
> code++;
> if (code->op != FETCH_OP_NOP) {
> trace_probe_log_err(ctx->offset, TOO_MANY_OPS);
> @@ -873,9 +900,9 @@ static int parse_btf_bitfield(struct fetch_insn **pcode,
> *pcode = code;
>
> code->op = FETCH_OP_MOD_BF;
> - code->lshift = 64 - (ctx->last_bitsize + ctx->last_bitoffs);
> - code->rshift = 64 - ctx->last_bitsize;
> - code->basesize = 64 / 8;
> + code->lshift = BYTES_TO_BITS(t->size) - (ctx->last_bitsize + ctx->last_bitoffs);
> + code->rshift = BYTES_TO_BITS(t->size) - ctx->last_bitsize;
> + code->basesize = t->size;
> return 0;
> }
[Severity: Medium]
Does this calculate the wrong code->lshift on __BIG_ENDIAN_BITFIELD
architectures?
At runtime, FETCH_OP_ST_MEM copies t->size bytes starting at bitoffs / 8
into buf, and fetch_apply_bitfield() shifts that native-endian integer left
by code->lshift and right by code->rshift. On big-endian systems, BTF bit
offsets are numbered from the most significant bit of the first byte, which
is loaded into the most significant byte of the integer in buf, so there
are ctx->last_bitoffs bits above the bitfield rather than
BYTES_TO_BITS(t->size) - (ctx->last_bitsize + ctx->last_bitoffs). Using
the little-endian formula shifts out the bitfield bits and records
corrupted values in the trace buffer on big-endian architectures.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179444679892.345731.5271591537517106679.stgit@devnote2?part=3
next prev parent reply other threads:[~2026-11-12 1:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 1:26 [PATCH v2 00/13] tracing/probes: Fix various bugs in dynamic probe events Masami Hiramatsu (Google)
2026-11-12 1:26 ` [PATCH v2 01/13] tracing/probes: Check enabled and busy state before unlinking sibling probes Masami Hiramatsu (Google)
2026-11-12 1:26 ` [PATCH v2 02/13] tracing/probes: Enable newly appended probe when target event is enabled Masami Hiramatsu (Google)
2026-11-12 1:27 ` [PATCH v2 03/13] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write Masami Hiramatsu (Google)
2026-11-12 1:57 ` sashiko-bot [this message]
2026-11-12 1:27 ` [PATCH v2 04/13] tracing/probes: Fix missing BTF kind checks in char pointer/array helpers Masami Hiramatsu (Google)
2026-11-12 1:27 ` [PATCH v2 05/13] tracing/eprobe: Fix 1-byte signed field fetch in get_event_field() Masami Hiramatsu (Google)
2026-11-12 1:27 ` [PATCH v2 06/13] tracing/eprobe: Disallow attaching eprobes to fprobe events Masami Hiramatsu (Google)
2026-11-12 1:27 ` [PATCH v2 07/13] tracing/probes: Fix user-space dereference string array store type Masami Hiramatsu (Google)
2026-11-12 1:27 ` [PATCH v2 08/13] tracing/probes: Reject array count on non-dereference string sources Masami Hiramatsu (Google)
2026-11-12 1:28 ` [PATCH v2 09/13] tracing/uprobes: Fix memory leak of tail in __trace_uprobe_create() Masami Hiramatsu (Google)
2026-11-12 1:28 ` [PATCH v2 10/13] tracing/probes: Allow symstr type for function entry arguments in return probes Masami Hiramatsu (Google)
2026-11-12 1:28 ` [PATCH v2 11/13] tracing/probes: Reject empty fetch expression for %pd and %pD Masami Hiramatsu (Google)
2026-11-12 1:28 ` [PATCH v2 12/13] tracing/probes: Validate command prefix in kprobe, uprobe, and eprobe Masami Hiramatsu (Google)
2026-11-12 1:28 ` [PATCH v2 13/13] tracing/probes: Propagate error codes in eprobe and fprobe creation Masami Hiramatsu (Google)
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-210125@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