Skip to content

Commit 0a06174

Browse files
committed
compat_ioctl: fix FIONREAD on devices
My final cleanup patch for sys_compat_ioctl() introduced a regression on the FIONREAD ioctl command, which is used for both regular and special files, but only works on regular files after my patch, as I had missed the warning that Al Viro put into a comment right above it. Change it back so it can work on any file again by moving the implementation to do_vfs_ioctl() instead. Fixes: 77b9040 ("compat_ioctl: simplify the implementation") Reported-and-tested-by: Christian Zigotzky <[email protected]> Reported-and-tested-by: youling257 <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 77b9040 commit 0a06174

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/ioctl.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,9 @@ static int compat_ioctl_preallocate(struct file *file, int mode,
523523

524524
static int file_ioctl(struct file *filp, unsigned int cmd, int __user *p)
525525
{
526-
struct inode *inode = file_inode(filp);
527-
528526
switch (cmd) {
529527
case FIBMAP:
530528
return ioctl_fibmap(filp, p);
531-
case FIONREAD:
532-
return put_user(i_size_read(inode) - filp->f_pos, p);
533529
case FS_IOC_RESVSP:
534530
case FS_IOC_RESVSP64:
535531
return ioctl_preallocate(filp, 0, p);
@@ -721,6 +717,13 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
721717
case FIDEDUPERANGE:
722718
return ioctl_file_dedupe_range(filp, argp);
723719

720+
case FIONREAD:
721+
if (!S_ISREG(inode->i_mode))
722+
return vfs_ioctl(filp, cmd, arg);
723+
724+
return put_user(i_size_read(inode) - filp->f_pos,
725+
(int __user *)argp);
726+
724727
default:
725728
if (S_ISREG(inode->i_mode))
726729
return file_ioctl(filp, cmd, argp);

0 commit comments

Comments
 (0)