FIGETBSZ ioctl conflict
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
(forgot to add lkml to Cc)
Quoted 17 lines · Johannes Stezenbach
Hi,
in commit
19ba0559the FIGETBSZ (andFS_IOC_FIEMAP) ioctl was moved fromfile_ioctl()todo_vfs_ioctl(), so it also works for directories. The problem I'm seeing is that FIGETBSZ is defined as_IO(0x00,2)which is simply 2. so there is some potential for conflicts with character devices which do not use the_IOmacros for numbering their ioctls.
Just doing a web search for "FIGETBSZ ioctl conflict" shows that a few people already ran into this problem.Would you mind adding a check for
S_ISDIR|S_ISREG, or maybe !S_ISCHR?Thanks,
Johannes
Quoted 16 lines · Johannes Stezenbach
(forgot to add lkml to Cc)
Quoted 13 lines · Johannes Stezenbach
Hi,
in commit
19ba0559the FIGETBSZ (andFS_IOC_FIEMAP) ioctl was moved fromfile_ioctl()todo_vfs_ioctl(), so it also works for directories. The problem I'm seeing is that FIGETBSZ is defined as_IO(0x00,2)which is simply 2. so there is some potential for conflicts with character devices which do not use the_IOmacros for numbering their ioctls.
Just doing a web search for "FIGETBSZ ioctl conflict" shows that a few people already ran into this problem.Would you mind adding a check for
S_ISDIR|S_ISREG, or maybe !S_ISCHR?
Yeah, I think the right thing to do here is a check for S_ISDIR | S_ISREG | S_ISLNK.
- Ted
PATCH 1/1 Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
FIGETBSZ has an ioctl number of _IO(0x00,2) == 2, which can conflict with device driver ioctls. Let's avoid the potential for problems by only honoring the ioctl number for files where this ioctl is likely going to be useful: regular files, directories, and symlinks.
Thanks to Johannes Stezenbach for pointing this consequence of commit 19ba0559.
--- fs/compat_ioctl.c | 7 ++++++- fs/ioctl.c | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-)
fs/compat_ioctl.c +6 -1
@@ -1715,8 +1715,13 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, goto out_fput;#endif -case FIBMAP :case FIGETBSZ : +if (S_ISDIR (filp->f_path.dentry->d_inode->i_mode) || +S_ISLNK (filp->f_path.dentry->d_inode->i_mode)) +break ; +/*FALL THROUGH */ + +case FIBMAP :case FIONREAD :if (S_ISREG (filp->f_path.dentry->d_inode->i_mode))break ;
fs/ioctl.c +4 -1
@@ -597,7 +597,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, {struct inode *inode = filp->f_path.dentry->d_inode;int __user *p = (int __user *)arg; -return put_user (inode->i_sb->s_blocksize, p); + +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || +S_ISLNK (inode->i_mode)) +return put_user (inode->i_sb->s_blocksize, p); }default :
Signature · 1 line
1.7.0.4
Re: [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
Quoted 7 lines · Theodore Ts'o
FIGETBSZ has an ioctl number of
_IO(0x00,2)== 2, which can conflict with device driver ioctls. Let's avoid the potential for problems by only honoring the ioctl number for files where this ioctl is likely going to be useful: regular files, directories, and symlinks.Thanks to Johannes Stezenbach for pointing this consequence of commit
19ba0559.
ioctl operate on a file descriptor, so you never call them on symbolic links.
Quoted 6 lines
fs/ioctl.c +0
-0@@ -597,7 +597,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, {
fs/ioctl.c int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, · line 606
Quoted 10 lines
fs/ioctl.c +4
-1struct inode *inode = filp->f_path.dentry->d_inode;int __user *p = (int __user *)arg; -return put_user (inode->i_sb->s_blocksize, p); + +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || +S_ISLNK (inode->i_mode)) +return put_user (inode->i_sb->s_blocksize, p); }default :
A comment explaining why we fall through here for special files is almost required. Without that the chance of breaking it during the next random cleanup are far too high.
Re: [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Theodore Ts'o
FIGETBSZ has an ioctl number of
_IO(0x00,2)== 2, which can conflict with device driver ioctls. Let's avoid the potential for problems by only honoring the ioctl number for files where this ioctl is likely going to be useful: regular files, directories, and symlinks.Thanks to Johannes Stezenbach for pointing this consequence of commit
19ba0559.ioctl operate on a file descriptor, so you never call them on symbolic links.
Oops, good point.
Quoted 3 lines
A comment explaining why we fall through here for special files is almost required. Without that the chance of breaking it during the next random cleanup are far too high.
Sigh. I had fixed that, but I failed to save emacs buffer before creating commit. Will resend with both fixes.
- Ted
PATCH 1/1 Only honor the FIGETBSZ ioctl for regular files and directories
FIGETBSZ has an ioctl number of _IO(0x00,2) == 2, which can conflict with device driver ioctls. Let's avoid the potential for problems by only honoring the ioctl number for files where this ioctl is likely going to be useful: regular files, directories, and symlinks.
Thanks to Johannes Stezenbach for pointing this consequence of commit 19ba0559.
--- fs/compat_ioctl.c | 6 +++++- fs/ioctl.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-)
fs/compat_ioctl.c +5 -1
@@ -1715,8 +1715,12 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, goto out_fput;#endif -case FIBMAP :case FIGETBSZ : +if (S_ISDIR (filp->f_path.dentry->d_inode->i_mode)) +break ; +/*FALL THROUGH */ + +case FIBMAP :case FIONREAD :if (S_ISREG (filp->f_path.dentry->d_inode->i_mode))break ;
fs/ioctl.c +4 -1
@@ -597,7 +597,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, {struct inode *inode = filp->f_path.dentry->d_inode;int __user *p = (int __user *)arg; -return put_user (inode->i_sb->s_blocksize, p); + +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)) +return put_user (inode->i_sb->s_blocksize, p); +/* FALL THROUGH */ }default :
Signature · 1 line
1.7.0.4
PATCH 1/1 Only honor the FIGETBSZ ioctl for regular files and directories
FIGETBSZ has an ioctl number of _IO(0x00,2) == 2, which can conflict with device driver ioctls. Let's avoid the potential for problems by only honoring the ioctl number for files where this ioctl is likely going to be useful: for regular files and directories
Thanks to Johannes Stezenbach for pointing this consequence of commit 19ba0559.
---
Fixed up commit description
fs/compat_ioctl.c | 6 +++++- fs/ioctl.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-)
fs/compat_ioctl.c +5 -1
@@ -1715,8 +1715,12 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, goto out_fput;#endif -case FIBMAP :case FIGETBSZ : +if (S_ISDIR (filp->f_path.dentry->d_inode->i_mode)) +break ; +/*FALL THROUGH */ + +case FIBMAP :case FIONREAD :if (S_ISREG (filp->f_path.dentry->d_inode->i_mode))break ;
fs/ioctl.c +4 -1
@@ -597,7 +597,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, {struct inode *inode = filp->f_path.dentry->d_inode;int __user *p = (int __user *)arg; -return put_user (inode->i_sb->s_blocksize, p); + +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)) +return put_user (inode->i_sb->s_blocksize, p); +/* FALL THROUGH */ }default :
Signature · 1 line
1.7.0.4