All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Maguire" <alan.maguire@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v14 bpf-next 06/10] libbpf: Support sanitization of BTF layout for older kernels
Date: Thu, 13 Aug 2026 21:54:57 +0000	[thread overview]
Message-ID: <20260813215501.548B21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260318132927.1142388-7-alan.maguire@oracle.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Sanitization produces invalid or truncated BTF if `type_off` is non-zero due to an incorrect size calculation.
--

--- Patch [6]: [PATCH v14 bpf-next 06/10] libbpf: Support sanitization of BTF layout for older kernels ---
commit fb06581dbb776e3aedd4935e88818d62fe25f19f
Author: Alan Maguire <alan.maguire@oracle.com>

libbpf: Support sanitization of BTF layout for older kernels

This patch introduces a FEAT_BTF_LAYOUT feature check to see if the kernel
supports BTF layout information. It also adds a BTF sanitization step
to remove the layout section for older kernels that don't support it.

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 0662d72bad207..5d392fff76bdd 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c

[ ... ]

> @@ -3153,9 +3155,55 @@ static int bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)
>  	bool has_type_tag = kernel_supports(obj, FEAT_BTF_TYPE_TAG);
>  	bool has_enum64 = kernel_supports(obj, FEAT_BTF_ENUM64);
>  	bool has_qmark_datasec = kernel_supports(obj, FEAT_BTF_QMARK_DATASEC);
> +	bool has_layout = kernel_supports(obj, FEAT_BTF_LAYOUT);
>  	int enum64_placeholder_id = 0;
> +	const struct btf_header *hdr;
> +	struct btf *btf = NULL;
> +	const void *raw_data;
>  	struct btf_type *t;
>  	int i, j, vlen;
> +	__u32 sz;
> +	int err;
> +
> +	/* clone BTF to sanitize a copy and leave the original intact */
> +	raw_data = btf__raw_data(orig_btf, &sz);
> +	hdr = raw_data;
> +
> +	if (!has_layout && hdr->hdr_len >= sizeof(struct btf_header) &&
> +	    (hdr->layout_len != 0 || hdr->layout_off != 0)) {
> +		struct btf_header *new_hdr;
> +		void *new_raw_data;
> +
> +		/*
> +		 * Need to rewrite BTF to exclude layout information and
> +		 * move string section to immediately after types.
> +		 */
> +		new_raw_data = malloc(sz);
> +		if (!new_raw_data)
> +			return ERR_PTR(-ENOMEM);
> +
> +		memcpy(new_raw_data, raw_data, sz);
> +		new_hdr = new_raw_data;
> +		new_hdr->layout_off = 0;
> +		new_hdr->layout_len = 0;
> +		new_hdr->str_off = hdr->type_off + hdr->type_len;
> +
> +		memmove(new_raw_data + hdr->hdr_len + new_hdr->str_off,
> +			new_raw_data + hdr->hdr_len + hdr->str_off,
> +			hdr->str_len);
> +		sz = hdr->hdr_len + hdr->type_len + hdr->str_len;

[Severity: Medium]
Since new_hdr->str_off correctly includes hdr->type_off, should the size
calculation for sz also include hdr->type_off?

If hdr->type_off is non-zero, this sz calculation would be smaller than the
required space (hdr->hdr_len + new_hdr->str_off + hdr->str_len). Could this
result in a truncated string section when loading valid BTF on older kernels?

> +
> +		btf = btf__new(new_raw_data, sz);
> +		free(new_raw_data);
> +	} else {
> +		btf = btf__new(raw_data, sz);
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260318132927.1142388-1-alan.maguire@oracle.com?part=6

  reply	other threads:[~2026-08-13 21:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 13:29 [PATCH v14 bpf-next 00/10] Add BTF layout to BTF Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 01/10] btf: Add BTF kind layout encoding to UAPI Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 02/10] libbpf: Support layout section handling in BTF Alan Maguire
2026-03-18 14:45   ` bot+bpf-ci
2026-03-18 14:52     ` Alexei Starovoitov
2026-03-18 13:29 ` [PATCH v14 bpf-next 03/10] libbpf: Use layout to compute an unknown kind size Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 04/10] libbpf: Add layout encoding support Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 05/10] libbpf: BTF validation can use layout for unknown kinds Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 06/10] libbpf: Support sanitization of BTF layout for older kernels Alan Maguire
2026-08-13 21:54   ` sashiko-bot [this message]
2026-03-18 13:29 ` [PATCH v14 bpf-next 07/10] btf: support kernel parsing of BTF with layout info Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 08/10] selftests/bpf: test kind encoding/decoding Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 09/10] selftests/bpf: Add feature test for FEAT_BTF_LAYOUT Alan Maguire
2026-03-18 13:29 ` [PATCH v14 bpf-next 10/10] kbuild, bpf: Specify "layout" optional feature Alan Maguire

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=20260813215501.548B21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=bpf@vger.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 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.