mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pidfs: handle FS_IOC32_GETVERSION in compat ioctl
@ 2026-07-16  5:28 Li Chen
  2026-07-16 11:15 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Li Chen @ 2026-07-16  5:28 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Alexander Viro, Jan Kara, linux-fsdevel, linux-kernel, Li Chen

FS_IOC32_GETVERSION has a distinct compat command encoding. Passing it
through compat_ptr_ioctl() leaves pidfd_ioctl() unable to recognize the
otherwise architecture-independent inode generation query.

Translate the compat command to FS_IOC_GETVERSION before dispatching it
through the native pidfd ioctl implementation.

Signed-off-by: Li Chen <me@linux.beauty>
---
 fs/pidfs.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index c20ffd747ff51..c55f46c32801d 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>
@@ -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)
-- 
2.52.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] pidfs: handle FS_IOC32_GETVERSION in compat ioctl
  2026-07-16  5:28 [PATCH] pidfs: handle FS_IOC32_GETVERSION in compat ioctl Li Chen
@ 2026-07-16 11:15 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2026-07-16 11:15 UTC (permalink / raw)
  To: Li Chen
  Cc: Christian Brauner, Alexander Viro, Jan Kara, linux-fsdevel, linux-kernel

On Thu 16-07-26 13:28:20, Li Chen wrote:
> FS_IOC32_GETVERSION has a distinct compat command encoding. Passing it
> through compat_ptr_ioctl() leaves pidfd_ioctl() unable to recognize the
> otherwise architecture-independent inode generation query.
> 
> Translate the compat command to FS_IOC_GETVERSION before dispatching it
> through the native pidfd ioctl implementation.
> 
> Signed-off-by: Li Chen <me@linux.beauty>

It's a bit sad we have to do this but you seem to be right. Feel free to
add:

Reviewed-by: Jan Kara <jack@suse.cz>


> ---
>  fs/pidfs.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index c20ffd747ff51..c55f46c32801d 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>
> @@ -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)
> -- 
> 2.52.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-16 11:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-16  5:28 [PATCH] pidfs: handle FS_IOC32_GETVERSION in compat ioctl Li Chen
2026-07-16 11:15 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox