summaryrefslogtreecommitdiff
path: root/fs/pidfs.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2026-08-20 10:58:44 +1000
committerDave Airlie <airlied@redhat.com>2026-08-20 10:58:44 +1000
commitc44e278ce02efd0c4be79a8eda1ea6885c1ce5ec (patch)
treeb6b7324a56fb1869a094da177d6a41f4d2efe8e0 /fs/pidfs.c
parent65b92bc671db7c222f8de1146c88e40fe8764d95 (diff)
parent8d3ae59288f1e7d58d76558a6ee96d533bc5019f (diff)
downloadlinux-next-c44e278ce02efd0c4be79a8eda1ea6885c1ce5ec.tar.gz
linux-next-c44e278ce02efd0c4be79a8eda1ea6885c1ce5ec.zip
BackMerge tag 'v7.2' into drm-next
Linux 7.2 There was a lot of conflicts this round between fixes and next, and I'd like to get the merge resolutions that we have in drm-tip. Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'fs/pidfs.c')
-rw-r--r--fs/pidfs.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/fs/pidfs.c b/fs/pidfs.c
index aaa609ddab04..b57ecc96e967 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/anon_inodes.h>
+#include <linux/compat.h>
#include <linux/exportfs.h>
#include <linux/file.h>
#include <linux/fs.h>
@@ -107,7 +108,7 @@ struct pidfs_attr {
#if BITS_PER_LONG == 32
-DEFINE_SPINLOCK(pidfs_ino_lock);
+static DEFINE_SPINLOCK(pidfs_ino_lock);
static u64 pidfs_ino_nr = 1;
static inline unsigned long pidfs_ino(u64 ino)
@@ -659,6 +660,17 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return open_namespace(ns_common);
}
+#ifdef CONFIG_COMPAT
+static long pidfd_compat_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ if (cmd == FS_IOC32_GETVERSION)
+ cmd = FS_IOC_GETVERSION;
+
+ return pidfd_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
static int pidfs_file_release(struct inode *inode, struct file *file)
{
struct pid *pid = inode->i_private;
@@ -686,7 +698,9 @@ static const struct file_operations pidfs_file_operations = {
.show_fdinfo = pidfd_show_fdinfo,
#endif
.unlocked_ioctl = pidfd_ioctl,
- .compat_ioctl = compat_ptr_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = pidfd_compat_ioctl,
+#endif
};
struct pid *pidfd_pid(const struct file *file)
@@ -915,6 +929,20 @@ static struct dentry *pidfs_fh_to_dentry(struct super_block *sb,
return path.dentry;
}
+static struct file *pidfs_dentry_open(const struct path *path,
+ unsigned int flags,
+ const struct cred *cred)
+{
+ struct file *file;
+
+ /* pidfds are always O_RDWR. */
+ file = dentry_open(path, flags | O_RDWR, cred);
+ /* do_dentry_open() strips O_EXCL and O_TRUNC. */
+ if (!IS_ERR(file))
+ file->f_flags |= flags & (PIDFD_THREAD | PIDFD_AUTOKILL);
+ return file;
+}
+
/*
* Make sure that we reject any nonsensical flags that users pass via
* open_by_handle_at(). Note that PIDFD_THREAD is defined as O_EXCL, and
@@ -940,11 +968,13 @@ static int pidfs_export_permission(struct handle_to_path_ctx *ctx,
static struct file *pidfs_export_open(const struct path *path, unsigned int oflags)
{
/*
- * Clear O_LARGEFILE as open_by_handle_at() forces it and raise
- * O_RDWR as pidfds always are.
+ * Opening via file handle may never raise PIDFD_AUTOKILL. That can
+ * only be done at task creation!
*/
- oflags &= ~O_LARGEFILE;
- return dentry_open(path, oflags | O_RDWR, current_cred());
+ if (WARN_ON_ONCE(oflags & PIDFD_AUTOKILL))
+ return ERR_PTR(-EINVAL);
+ /* Clear O_LARGEFILE as open_by_handle_at() forces it. */
+ return pidfs_dentry_open(path, oflags & ~O_LARGEFILE, current_cred());
}
static const struct export_operations pidfs_export_operations = {
@@ -1108,7 +1138,6 @@ static struct file_system_type pidfs_type = {
struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
{
- struct file *pidfd_file;
struct path path __free(path_put) = {};
int ret;
@@ -1126,16 +1155,7 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
VFS_WARN_ON_ONCE(!pid->attr);
flags &= ~PIDFD_STALE;
- flags |= O_RDWR;
- pidfd_file = dentry_open(&path, flags, current_cred());
- /*
- * Raise PIDFD_THREAD and PIDFD_AUTOKILL explicitly as
- * do_dentry_open() strips O_EXCL and O_TRUNC.
- */
- if (!IS_ERR(pidfd_file))
- pidfd_file->f_flags |= (flags & (PIDFD_THREAD | PIDFD_AUTOKILL));
-
- return pidfd_file;
+ return pidfs_dentry_open(&path, flags, current_cred());
}
void __init pidfs_init(void)