Thread (78 messages) 78 messages, 12 authors, 2025-10-24

Re: [PATCH 01/32] pidfs: validate extensible ioctls

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2025-10-23 10:46:53
Also in: cgroups, linux-block, linux-fsdevel, linux-kselftest, linux-nfs, lkml

On 10. 09. 25, 16:36, Christian Brauner wrote:
quoted hunk ↗ jump to hunk
Validate extensible ioctls stricter than we do now.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
  fs/pidfs.c         |  2 +-
  include/linux/fs.h | 14 ++++++++++++++
  2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/pidfs.c b/fs/pidfs.c
index edc35522d75c..0a5083b9cce5 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -440,7 +440,7 @@ static bool pidfs_ioctl_valid(unsigned int cmd)
  		 * erronously mistook the file descriptor for a pidfd.
  		 * This is not perfect but will catch most cases.
  		 */
-		return (_IOC_TYPE(cmd) == _IOC_TYPE(PIDFD_GET_INFO));
+		return extensible_ioctl_valid(cmd, PIDFD_GET_INFO, PIDFD_INFO_SIZE_VER0);
Hi,

this turned EINVAL (from pidfd_info()) into ENOTTY (from pidfd_ioctl()) 
for at least LTP's:
struct pidfd_info_invalid {
	uint32_t dummy;
};

#define PIDFD_GET_INFO_SHORT _IOWR(PIDFS_IOCTL_MAGIC, 11, struct 
pidfd_info_invalid)

ioctl(pidfd, PIDFD_GET_INFO_SHORT, info_invalid) == EINVAL

at:
https://github.com/linux-test-project/ltp/blob/9bb94efa39bb1b08f37e56c7437db5fa13ddcae2/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c#L46

Is this expected?
quoted hunk ↗ jump to hunk
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -4023,4 +4023,18 @@ static inline bool vfs_empty_path(int dfd, const char __user *path)
  
  int generic_atomic_write_valid(struct kiocb *iocb, struct iov_iter *iter);
  
+static inline bool extensible_ioctl_valid(unsigned int cmd_a,
+					  unsigned int cmd_b, size_t min_size)
+{
+	if (_IOC_DIR(cmd_a) != _IOC_DIR(cmd_b))
+		return false;
+	if (_IOC_TYPE(cmd_a) != _IOC_TYPE(cmd_b))
+		return false;
+	if (_IOC_NR(cmd_a) != _IOC_NR(cmd_b))
+		return false;
+	if (_IOC_SIZE(cmd_a) < min_size)
+		return false;
+	return true;
+}
+
  #endif /* _LINUX_FS_H */
thanks,
-- 
js
suse labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help