All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Chris Mason" <mason@kernel.org>, <bpf@vger.kernel.org>
Cc: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
	<eddyz87@gmail.com>, <brauner@kernel.org>
Subject: Re: [PATCH RFC 1/2] bpf: fix UAF via trusted BTF walk after release
Date: Wed, 16 Sep 2026 20:46:30 +0200	[thread overview]
Message-ID: <DLGYPZAL708V.3GFLANAPH2L8O@gmail.com> (raw)
In-Reply-To: <20260916183303.3504885-2-mason@kernel.org>

On Wed Sep 16, 2026 at 8:33 PM CEST, Chris Mason wrote:
> A BPF program can keep dereferencing a trusted pointer that it loaded
> from a referenced object after it has released that reference. With a
> file from bpf_get_task_exe_file(), f->f_inode stays usable after
> bpf_put_file(), and loads through it read freed or reused inode memory.
>
> A pointer derived from a referenced object is only valid while the
> reference is held. release_reference() enforces that by invalidating
> every register whose id or parent_id matches the released id. However,
> check_ptr_to_btf_access() builds the loaded register with
> mark_btf_ld_reg(), which is not given the source register and zeroes
> both fields. The verifier state for the f_inode case:
>
>     file = bpf_get_task_exe_file(task)   file:  id=N, referenced
>     inode = file->f_inode                inode: trusted, id=0,
>                                                 parent_id=0
>     bpf_put_file(file)                   release_reference(N)
>                                            skips inode
>     inode->i_ino                         accepted, unprobed load
>
> Reproduced by reading inode->i_ino after bpf_put_file() once the task
> owning the file had exited and new fds were created.
>
> Fix this by recording the source's reference id in the parent_id of a
> trusted PTR_TO_BTF_ID load. A program that dereferences such a pointer
> after the release is now rejected with "invalid mem access 'scalar'".
>
> Assisted-by: kres
> Fixes: 57539b1c0ac2 ("bpf: Enable annotating trusted nested pointers")
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---

Thanks for the report. I have a fix for this locally in the queue. The diagnosis
is correct, but there are more places that would require changes. For instance,
bpf_real_data_inode() should, but does not, propagate the lifetime of the input
argument to the returned inode. That would require some sort of annotation so
that we are aware of the lifetime relationship between the input and the
returned pointer.

I will send it out and will handle this case as well.

  reply	other threads:[~2026-09-16 18:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 18:33 [PATCH RFC 0/2] Fix use-after-free related to binfmt-misc-bpf.c Chris Mason
2026-09-16 18:33 ` [PATCH RFC 1/2] bpf: fix UAF via trusted BTF walk after release Chris Mason
2026-09-16 18:46   ` Kumar Kartikeya Dwivedi [this message]
2026-09-16 19:19     ` Chris Mason
2026-09-16 18:33 ` [PATCH RFC 2/2] selftests/bpf: test f_inode walk around bpf_put_file() Chris Mason

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=DLGYPZAL708V.3GFLANAPH2L8O@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=mason@kernel.org \
    /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.