BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Brauner" <brauner@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC POC 2/4] binfmt_misc: add binfmt_misc_ops bpf struct_ops
Date: Tue, 07 Jul 2026 19:49:42 +0000	[thread overview]
Message-ID: <20260707194942.E7A391F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-work-bpf-binfmt_misc-v1-2-74b995c84ec1@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TOCTOU race in bpf_binprm_set_interp allows bypassing the absolute path check.
--

--- Patch [2]: [PATCH RFC POC 2/4] binfmt_misc: add binfmt_misc_ops bpf struct_ops ---
commit dcb835dea31af56f46fb0ad454883c437389225a
Author: Christian Brauner <brauner@kernel.org>

binfmt_misc: add binfmt_misc_ops bpf struct_ops

This commit adds a BPF struct_ops backend for binfmt_misc. It allows
computing the interpreter programmatically for matching binaries instead of
relying on fixed strings.

Link: https://lore.kernel.org/20260704211409.1978485-1-farid.m.zakaria@gmail.com

> diff --git a/fs/binfmt_misc_bpf.c b/fs/binfmt_misc_bpf.c
> new file mode 100644
> index 0000000000000..72da0964d9491
> --- /dev/null
> +++ b/fs/binfmt_misc_bpf.c
[ ... ]
> +__bpf_kfunc int bpf_binprm_set_interp(struct linux_binprm *bprm,
> +				      const char *path, size_t path__sz)
> +{
> +	size_t len;
> +	char *interp;
> +
> +	if (!path__sz)
> +		return -EINVAL;
> +	len = strnlen(path, path__sz);
> +	if (len == path__sz)
> +		return -EINVAL;
> +	if (path[0] != '/')

[Severity: Medium]
Does this create a Time-of-Check to Time-of-Use (TOCTOU) race if path
points to a BPF map value?

If a BPF program passes a pointer to a map value as the path argument,
userspace could concurrently modify that map value after this check for '/'
but before the path is copied below. This would allow bypassing the
absolute path validation.

Should the string be copied via kmemdup_nul() first, and then the
absolute path check performed on the newly allocated interp buffer?

> +		return -EINVAL;
> +	if (len >= PATH_MAX)
> +		return -ENAMETOOLONG;
> +
> +	interp = kmemdup_nul(path, len, GFP_KERNEL);
> +	if (!interp)
> +		return -ENOMEM;
> +
> +	kfree(bprm->bpf_interp);
> +	bprm->bpf_interp = interp;
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-work-bpf-binfmt_misc-v1-0-74b995c84ec1@kernel.org?part=2

  reply	other threads:[~2026-07-07 19:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 19:36 [PATCH RFC POC 0/4] binfmt_misc: bpf-backed binary type handlers Christian Brauner
2026-07-07 19:36 ` [PATCH RFC POC 1/4] exec: stash a bpf-selected interpreter in struct linux_binprm Christian Brauner
2026-07-07 19:36 ` [PATCH RFC POC 2/4] binfmt_misc: add binfmt_misc_ops bpf struct_ops Christian Brauner
2026-07-07 19:49   ` sashiko-bot [this message]
2026-07-07 19:36 ` [PATCH RFC POC 3/4] binfmt_misc: wire up bpf-backed 'B' entries Christian Brauner
2026-07-07 19:36 ` [PATCH RFC POC 4/4] bpf: allow fs kfuncs for binfmt_misc_ops programs Christian Brauner

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=20260707194942.E7A391F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@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