From: Peter Zijlstra <peterz@infradead.org>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jann Horn <jannh@google.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
adrian.hunter@intel.com, alexander.shishkin@linux.intel.com,
dapeng1.mi@linux.intel.com
Subject: Re: [PATCH 1/2] perf: look up address filter files without ctx->mutex held
Date: Fri, 27 Nov 2026 12:57:45 +0100 [thread overview]
Message-ID: <20261127115745.GA2883950@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261127-tonlage-pilze-demolieren-5948f82f401c@brauner>
On Fri, Nov 27, 2026 at 10:45:28AM +0100, Christian Brauner wrote:
> > @@ -12310,11 +12361,8 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
> >
> > ret = -EINVAL;
> > if (!filter->path.dentry ||
> > - !S_ISREG(d_inode(filter->path.dentry)
> > - ->i_mode))
> > + !S_ISREG(d_inode(filter->path.dentry)->i_mode))
> > goto fail;
>
> Just a thought on this. In vfs-7.5.lookup I have:
>
> file_check_backing() which is the new default way to figure out whether
> something can be a backing file for a given subsystem. Its checks are:
>
> int file_check_backing(const struct file *file, fmode_t mode, umode_t type)
> {
> fmode_t io = mode & (FMODE_READ | FMODE_WRITE);
> /* Drivers may point ->f_mapping at something else. */
> umode_t fmt = file_inode(file)->i_mode & S_IFMT;
> struct inode *real_inode;
>
> /* O_PATH files are only fine for callers that just use the path. */
> if ((file->f_mode & FMODE_PATH) && !(mode & FMODE_PATH))
> return -EBADF;
>
> if ((file->f_mode & io) != io)
> return -EBADF;
>
> if (fmt != S_IFREG && !(type == S_IFBLK && fmt == S_IFBLK))
> return -EINVAL;
>
> /* Look through stacking filesystems at the inode with the data. */
> real_inode = d_real_data_inode(file->f_path.dentry);
> if (IS_ERR(real_inode))
> return PTR_ERR(real_inode);
> if (real_inode->i_sb->s_iflags & SB_I_PSEUDO)
> return -EINVAL;
>
> if ((mode & FMODE_READ) &&
> (!(file->f_mode & FMODE_CAN_READ) || !file->f_op->read_iter))
> return -EINVAL;
>
> if ((mode & FMODE_WRITE) &&
> (!(file->f_mode & FMODE_CAN_WRITE) || !file->f_op->write_iter))
> return -EINVAL;
>
> return 0;
> }
>
> It excludes anything that is a pseudo filesystem:
>
> arch/powerpc/platforms/cell/spufs/inode.c: fc_init_pseudo(fc);
> arch/s390/hypfs/inode.c: fc_init_pseudo(fc);
> drivers/android/binder/rust_binderfs.c: fc_init_pseudo(fc);
> drivers/usb/gadget/function/f_fs.c: fc_init_pseudo(fc);
> drivers/usb/gadget/legacy/inode.c: fc_init_pseudo(fc);
> drivers/xen/xenfs/super.c: fc_init_pseudo(fc);
> fs/binfmt_misc.c: fc_init_pseudo(fc);
> fs/configfs/mount.c: fc_init_pseudo(fc);
> fs/debugfs/inode.c: fc_init_pseudo(fc);
> fs/devpts/inode.c: fc_init_pseudo(fc);
> fs/efivarfs/super.c: fc_init_pseudo(fc);
> fs/failfs.c: fc_init_pseudo(fc);
> fs/fuse/control.c: fc_init_pseudo(fsc);
> fs/kernfs/mount.c: fc_init_pseudo(fc);
> fs/libfs.c: fc_init_pseudo(fc);
> fs/nfsd/nfsctl.c: fc_init_pseudo(fc);
> fs/nullfs.c: fc_init_pseudo(fc);
> fs/ocfs2/dlmfs/dlmfs.c: fc_init_pseudo(fc);
> fs/openpromfs/inode.c: fc_init_pseudo(fc);
> fs/proc/root.c: fc_init_pseudo(fc);
> fs/pstore/inode.c: fc_init_pseudo(fc);
> fs/tracefs/inode.c: fc_init_pseudo(fc);
> include/linux/pseudo_fs.h:static inline void fc_init_pseudo(struct fs_context *fc)
> ipc/mqueue.c: fc_init_pseudo(fc);
> kernel/bpf/inode.c: fc_init_pseudo(fc);
> net/sunrpc/rpc_pipe.c: fc_init_pseudo(fc);
> security/apparmor/apparmorfs.c: fc_init_pseudo(fc);
> security/inode.c: fc_init_pseudo(fc);
> security/selinux/selinuxfs.c: fc_init_pseudo(fc);
> security/smack/smackfs.c: fc_init_pseudo(fc);
>
> I don't think anything on this list is something that you would ever
> want to use as an object file?
Very very possibly people would like /proc/kcore to self reference or
something, but I'm not sure that's a thing. Adrian?
> I think we should do an O_PATH open of the target file and then you
> call:
>
> file = filp_open(filename, O_PATH | O_REGULAR, 0)
>
> if (file_check_backing(file, FMODE_PATH, 0))
> return -EINVAL;
We must close file, or does it have __free(file) on or something?
> We had a whole bug class where various subsystems that used backing
> files just allowed arbitrary files to be used.
This seems fine to me and can go in independent of this locking stuff.
next prev parent reply other threads:[~2026-11-27 11:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:45 [PATCH 0/2] exec: two more sleepers in the way of exec Christian Brauner
2026-11-26 11:45 ` [PATCH 1/2] perf: look up address filter files without ctx->mutex held Christian Brauner
2026-11-26 15:24 ` Peter Zijlstra
2026-11-26 20:56 ` Christian Brauner
2026-11-26 21:26 ` Christian Brauner
2026-11-26 21:59 ` Christian Brauner
2026-11-27 8:13 ` Peter Zijlstra
2026-11-27 9:18 ` Peter Zijlstra
2026-11-27 9:45 ` Christian Brauner
2026-11-27 11:57 ` Peter Zijlstra [this message]
2026-11-26 11:45 ` [PATCH 2/2] proc: call task_vsize() without exec_update_lock held Christian Brauner
2026-11-26 11:54 ` [PATCH 0/2] exec: two more sleepers in the way of exec 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=20261127115745.GA2883950@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=brauner@kernel.org \
--cc=dapeng1.mi@linux.intel.com \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox