From d87631c337258a90e10ffa76eb76bb5b5d559a40 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Sat, 31 Oct 2026 09:22:09 +0200 Subject: [PATCH] fs: clamp FIONREAD result to int range FIONREAD returns the difference between the file size and the current position in an int. When the difference is outside the int range, the result wraps, so a file with 4 GiB remaining can be reported as empty. Clamp the result to the signed int range before returning it to userspace. Preserve negative counts for file positions past EOF. Signed-off-by: Avi Weiss Link: https://patch.msgid.link/20261031072208.3096100-2-thnkslprpt@gmail.com Reviewed-by: Jan Kara Signed-off-by: Christian Brauner (Amutable) --- fs/ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 1c152c2b1b67..ecc2a4cfe610 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -550,8 +551,8 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd, if (!S_ISREG(inode->i_mode) || IS_ANON_FILE(inode)) return vfs_ioctl(filp, cmd, arg); - return put_user(i_size_read(inode) - filp->f_pos, - (int __user *)argp); + return put_user(clamp_t(loff_t, i_size_read(inode) - filp->f_pos, + INT_MIN, INT_MAX), (int __user *)argp); case FS_IOC_GETFLAGS: return ioctl_getflags(filp, argp);