BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chris Mason" <mason@kernel.org>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 3/4] lib/buildid: check the file type before __kernel_read()
Date: Thu, 03 Dec 2026 18:13:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-248359@kernel.org> (raw)
In-Reply-To: <20261203163126.48697-4-mason@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] lib/buildid: freader_fetch() allows __kernel_read() on
  S_IFREG stream files
--

commit 2b2bbc9fbc6dc8ab602d62d9f09a6baccfe7d1de
Author: Chris Mason <mason@kernel.org>

lib/buildid: check the file type before __kernel_read()

This commit rejects non-regular, non-block files before calling
__kernel_read() in freader_fetch() so that sleepable build ID lookups do
not read from sockets or other streams.

> diff --git a/lib/buildid.c b/lib/buildid.c
> index 22bbac1ee02f4..6ce7745507342 100644
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -99,8 +99,15 @@ const void *freader_fetch(struct freader *r, loff_t file_off, size_t sz)
>  
>  	/* use __kernel_read() for sleepable context */
>  	if (r->may_fault) {
> +		umode_t mode = file_inode(r->file)->i_mode;
>  		ssize_t ret;
>  
> +		/* ->read_iter() of a stream waits for a peer and consumes data */
> +		if (!S_ISREG(mode) && !S_ISBLK(mode)) {
> +			r->err = -EINVAL;
> +			return NULL;
> +		}

[Severity: Medium]
Can S_IFREG stream files still reach __kernel_read() here?

Inode mode alone misses regular files opened with stream_open() or
nonseekable_open().  FUSE files opened with FOPEN_STREAM still allow
mmap() in fuse_file_mmap(), so do_procmap_query() -> build_id_parse_file()
still calls fuse_file_read_iter(), which can block or consume stream data.

Rejecting files with FMODE_STREAM or without FMODE_LSEEK in
r->file->f_mode would also catch stream regular files while still allowing
seekable pseudo files like shmem and memfd.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203163126.48697-1-mason@kernel.org?part=3

  reply	other threads:[~2026-12-03 18:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:31 [PATCH bpf 0/4] lib/buildid: fix a few bugs Chris Mason
2026-12-03 16:31 ` [PATCH bpf 1/4] lib/buildid: check FMODE_READ before __kernel_read() Chris Mason
2026-12-03 16:31 ` [PATCH bpf 2/4] lib/buildid: check the offset " Chris Mason
2026-12-03 16:31 ` [PATCH bpf 3/4] lib/buildid: check the file type " Chris Mason
2026-12-03 18:13   ` sashiko-bot [this message]
2026-12-03 18:58     ` Chris Mason
2026-12-03 16:31 ` [PATCH bpf 4/4] lib/buildid: limit the number of ELF notes per parse 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=sashiko-outbox-248359@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mason@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