lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <lhu7bvd6u03.fsf_-_@oldenburg.str.redhat.com>
Date: Wed, 26 Nov 2025 10:08:44 +0100
From: Florian Weimer <fweimer@...hat.com>
To: Christian Brauner <brauner@...nel.org>
Cc: Jan Kara <jack@...e.cz>,  Amir Goldstein <amir73il@...il.com>,
 linux-fsdevel@...r.kernel.org,  Josef Bacik <josef@...icpanda.com>,
 Jeff Layton <jlayton@...nel.org>,  Mike Yuan <me@...dnzj.com>,
 Zbigniew Jędrzejewski-Szmek <zbyszek@...waw.pl>,
 Lennart Poettering <mzxreary@...inter.de>,
 Daan De Meyer <daan.j.demeyer@...il.com>,
 Aleksa Sarai <cyphar@...har.com>,
 Alexander Viro <viro@...iv.linux.org.uk>,
 Jens Axboe <axboe@...nel.dk>,  Tejun Heo <tj@...nel.org>,
 Johannes Weiner <hannes@...xchg.org>,
 Michal Koutný <mkoutny@...e.com>,  Eric Dumazet
 <edumazet@...gle.com>,
 Jakub Kicinski <kuba@...nel.org>,  Paolo Abeni <pabeni@...hat.com>,
 Simon Horman <horms@...nel.org>,
 Chuck Lever <chuck.lever@...cle.com>,  linux-nfs@...r.kernel.org,
 linux-kselftest@...r.kernel.org,  linux-block@...r.kernel.org,
 linux-kernel@...r.kernel.org,  cgroups@...r.kernel.org,
 netdev@...r.kernel.org, libc-alpha@...rceware.org, Dmitry V. Levin
 <ldv@...ace.io>, address-sanitizer <address-sanitizer@...glegroups.com>,
 strace-devel@...ts.strace.io
Subject: Stability of ioctl constants in the UAPI (Re: [PATCH 01/32] pidfs:
 validate extensible ioctls)

* Christian Brauner:

> Validate extensible ioctls stricter than we do now.
>
> Signed-off-by: Christian Brauner <brauner@...nel.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);
>  	}
>  
>  	return false;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index d7ab4f96d705..2f2edc53bf3c 100644
> --- 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 */

Is this really the right direction?  This implies that the ioctl
constants change as the structs get extended.  At present, this impacts
struct pidfd_info and PIDFD_GET_INFO.

I think this is a deparature from the previous design, where (low-level)
userspace did not have not worry about the internal structure of ioctl
commands and could treat them as opaque bit patterns.  With the new
approach, we have to dissect some of the commands in the same way
extensible_ioctl_valid does it above.

So far, this impacts glibc ABI tests.  Looking at the strace sources, it
doesn't look to me as if the ioctl handler is prepared to deal with this
situation, either, because it uses the full ioctl command for lookups.

The sanitizers could implement generic ioctl checking with the embedded
size information in the ioctl command, but the current code structure is
not set up to handle this because it's indexed by the full ioctl
command, not the type.  I think in some cases, the size is required to
disambiguate ioctl commands because the type field is not unique across
devices.  In some cases, the sanitizers would have to know the exact
command (not just the size), to validate points embedded in the struct
passed to the ioctl.  So I don't think changing ioctl constants when
extensible structs change is obviously beneficial to the sanitizers,
either.

I would prefer if the ioctl commands could be frozen and decoupled from
the structs.  As far as I understand it, there is no requirement that
the embedded size matches what the kernel deals with.

Thanks,
Florian


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ