All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Tw <tw19881113@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] libpf: Fix for the compiler sanity checking
Date: Mon, 24 Aug 2026 14:24:46 +0000	[thread overview]
Message-ID: <20260824142447.035571F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260824141532.604269-1-tw19881113@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Medium] Latent undefined behavior due to signed left-shift overflow in the `BTF_INFO_ENC()` macro.
- [Medium] Latent undefined behavior due to signed left-shift when setting retprobe bit in `attr.config`.
--

--- Patch [1]: [PATCH] libpf: Fix for the compiler sanity checking ---
commit 6bb550337600fb1ee129a0b5ed1c50e66620bbc5
Author: Tw <tw19881113@gmail.com>

libpf: Fix for the compiler sanity checking

This patch fixes an undefined behavior issue during libbpf compilation.
It resolves a ubsan warning about left shifting 1 by 31 places in an int
by casting the integer to a u32 before performing the shift.

> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 4c46d34fc055d..222d2f1c0ed3a 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -259,7 +259,7 @@ static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
>  
>  static inline __u32 btf_type_info(int kind, int vlen, int kflag)
>  {
> -	return (kflag << 31) | (kind << 24) | vlen;
> +	return ((__u32)kflag << 31) | (kind << 24) | vlen;
>  }

[Severity: Medium]
This isn't a bug introduced by this patch, but since you are fixing the
shift in btf_type_info(), should we also apply this fix to the BTF_INFO_ENC
macro in this same file?

tools/lib/bpf/libbpf_internal.h:
#define BTF_INFO_ENC(kind, kind_flag, vlen) \
	((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))

The !! operator results in a signed int. If a caller provides a non-zero
kind_flag, shifting it left by 31 places into the sign bit will also result
in undefined behavior. Would it make sense to cast to __u32 here as well?

[Severity: Medium]
This is another pre-existing issue, but I noticed a similar left-shift
that could cause undefined behavior when setting the retprobe bit:

tools/lib/bpf/libbpf.c:perf_event_open_probe()
	if (retprobe) {
		int bit = uprobe ? determine_uprobe_retprobe_bit()
				 : determine_kprobe_retprobe_bit();

		if (bit < 0) {
[ ... ]
			return bit;
		}
		attr.config |= 1 << bit;
	}

Since bit is read from sysfs, if a future kernel update returns a bit index
of 31 or higher, would 1 << bit overflow and incorrectly configure
attr.config? Should this use 1ULL << bit to safely set the 64-bit config
field?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824141532.604269-1-tw19881113@gmail.com?part=1

  reply	other threads:[~2026-08-24 14:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 14:15 [PATCH] libpf: Fix for the compiler sanity checking Tw
2026-08-24 14:24 ` sashiko-bot [this message]
2026-08-25 20:17   ` Andrii Nakryiko

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=20260824142447.035571F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tw19881113@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.