All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 07/12] bpf: Record probe name in SDT map
Date: Sat, 27 Jun 2026 15:06:41 +0000	[thread overview]
Message-ID: <20260627150641.BF2AD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <43eaa2bc686c9f8309d37b96f15646eaa9e51899.1782571533.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Strict `value_size` validation on the expanded `struct bpf_insn_array_value` breaks backwards and forwards compatibility.
- [Medium] Memory leak of `e->name` on the error path in `bpf_object__collect_sdt_notes` when a probe name exceeds `BPF_SDT_MAX_NAME_LEN`.
--

commit 33292e7627dcc830a8b1dc17788ae56ec52849c6
Author: Xu Kuohai <xukuohai@huawei.com>

bpf: Record probe name in SDT map

This commit adds a probe name field to the bpf_insn_array_value structure to
help the kernel locate target programs and probe sites. It enforces a maximum
name length of 64 characters and updates libbpf to pass the name during map
creation.

> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 773a7def0fbd3..95ca41bf75018 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
[ ... ]
> @@ -7743,6 +7744,7 @@ struct bpf_insn_array_value {
>  	__u8  nargs;		/* argument count (0..5) */
>  	__u8  arg_reg[5];	/* BPF register for each argument */
>  	__u8  pad[2];
> +	char  name[BPF_SDT_MAX_NAME_LEN]; /* probe name */
>  };

[Severity: Critical]
Does changing the size of struct bpf_insn_array_value break backwards
compatibility with older userspace applications?

It appears the kernel enforces a strict value_size check during map creation
in insn_array_alloc_check():

	if (attr->max_entries == 0 || attr->key_size != 4 ||
	    attr->value_size != value_size ||
	    attr->map_flags & ~BPF_F_INSN_ARRAY_SDT)
		return -EINVAL;

Because value_size is derived from sizeof(struct bpf_insn_array_value),
older binaries passing a smaller value_size of 16 to
bpf_map_create(BPF_MAP_TYPE_INSN_ARRAY) might now be rejected with -EINVAL.

[ ... ]
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index badac128e8adc..dbc08a1931015 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4146,6 +4146,12 @@ static int bpf_object__collect_sdt_notes(struct bpf_object *obj)
>  			err = -ENOMEM;
>  			goto out;
>  		}
> +		if (strlen(e->name) >= BPF_SDT_MAX_NAME_LEN) {
> +			pr_warn("sdt: probe name '%s' too long (max %d chars)\n",
> +				e->name, BPF_SDT_MAX_NAME_LEN - 1);
> +			err = -EINVAL;
> +			goto out;
> +		}

[Severity: Medium]
Can this goto leak the newly allocated e->name string?

Just above this snippet, e->name is allocated:

		e->name = strdup(sdt_syms[i].name + 10);
		if (!e->name) {
			err = -ENOMEM;
			goto out;
		}

If the length exceeds BPF_SDT_MAX_NAME_LEN, we jump to the out label.
However, the cleanup loop in out:

out:
	if (err) {
		for (i = 0; i < obj->sdt_entry_cnt; i++)
			free(obj->sdt_entries[i].name);

only frees up to obj->sdt_entry_cnt, which hasn't been incremented yet for
this entry, potentially causing the string to be leaked.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1782571533.git.xukuohai@huawei.com?part=7

  reply	other threads:[~2026-06-27 15:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27 22:51 [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Xu Kuohai
2026-06-27 20:51 ` [syzbot ci] " syzbot ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 01/12] libbpf: Prepare bpf SDT probe section for the linker Xu Kuohai
2026-06-27 17:05   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 02/12] libbpf: Introduce bpf SDT probe macros Xu Kuohai
2026-06-27 15:01   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 03/12] libbpf: Add bpf_sdt_notes section parser Xu Kuohai
2026-06-27 15:03   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 04/12] bpf: Create insn_array map for bpf SDT probe Xu Kuohai
2026-06-27 15:18   ` sashiko-bot
2026-06-27 15:34   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 05/12] bpf: Collect SDT probe BTF IDs from BTF decl tags Xu Kuohai
2026-06-27 15:20   ` sashiko-bot
2026-06-27 15:34   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 06/12] bpf: Add type check for SDT probe site Xu Kuohai
2026-06-27 15:04   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 07/12] bpf: Record probe name in SDT map Xu Kuohai
2026-06-27 15:06   ` sashiko-bot [this message]
2026-06-27 22:51 ` [RFC PATCH bpf-next 08/12] libbpf: Add libbpf support to load SDT observer program Xu Kuohai
2026-06-27 15:12   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 09/12] bpf: Add kernel " Xu Kuohai
2026-06-27 15:12   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 10/12] bpf: Support attach and detach for " Xu Kuohai
2026-06-27 17:12   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 11/12] bpf, x86: Add JIT support SDT for probe Xu Kuohai
2026-06-27 15:13   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 12/12] selftests/bpf: Add tests for bpf SDT probe Xu Kuohai
2026-06-27 15:25   ` 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=20260627150641.BF2AD1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xukuohai@huaweicloud.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.