* Re: FIGETBSZ ioctl conflict
[not found] <20100614110252.GB32224@sig21.net>
@ 2010-06-14 12:36 ` Johannes Stezenbach
2010-06-14 13:42 ` tytso
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Stezenbach @ 2010-06-14 12:36 UTC (permalink / raw)
To: Aneesh Kumar K.V; +Cc: Theodore Ts'o, linux-kernel
(forgot to add lkml to Cc)
On Mon, Jun 14, 2010 at 01:02:52PM +0200, Johannes Stezenbach wrote:
> Hi,
>
> in commit 19ba0559 the FIGETBSZ (and FS_IOC_FIEMAP) ioctl was moved
> from file_ioctl() to do_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 _IO macros 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: FIGETBSZ ioctl conflict
2010-06-14 12:36 ` FIGETBSZ ioctl conflict Johannes Stezenbach
@ 2010-06-14 13:42 ` tytso
2010-06-14 14:05 ` [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks Theodore Ts'o
0 siblings, 1 reply; 7+ messages in thread
From: tytso @ 2010-06-14 13:42 UTC (permalink / raw)
To: Johannes Stezenbach; +Cc: Aneesh Kumar K.V, linux-kernel
On Mon, Jun 14, 2010 at 02:36:52PM +0200, Johannes Stezenbach wrote:
> (forgot to add lkml to Cc)
>
> On Mon, Jun 14, 2010 at 01:02:52PM +0200, Johannes Stezenbach wrote:
> > Hi,
> >
> > in commit 19ba0559 the FIGETBSZ (and FS_IOC_FIEMAP) ioctl was moved
> > from file_ioctl() to do_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 _IO macros 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
2010-06-14 13:42 ` tytso
@ 2010-06-14 14:05 ` Theodore Ts'o
2010-06-14 14:07 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Theodore Ts'o @ 2010-06-14 14:05 UTC (permalink / raw)
To: Linux Kernel Developers List; +Cc: Theodore Ts'o, Al Viro, Aneesh Kumar K.V
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.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
---
fs/compat_ioctl.c | 7 ++++++-
fs/ioctl.c | 5 ++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 641640d..81d646b 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -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;
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 2d140a7..5c61d69 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -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:
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
2010-06-14 14:05 ` [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks Theodore Ts'o
@ 2010-06-14 14:07 ` Christoph Hellwig
2010-06-14 14:12 ` tytso
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2010-06-14 14:07 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Linux Kernel Developers List, Al Viro, Aneesh Kumar K.V
On Mon, Jun 14, 2010 at 10:05:10AM -0400, Theodore Ts'o wrote:
> 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.
> diff --git a/fs/ioctl.c b/fs/ioctl.c
> index 2d140a7..5c61d69 100644
> --- a/fs/ioctl.c
> +++ b/fs/ioctl.c
> @@ -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:
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks
2010-06-14 14:07 ` Christoph Hellwig
@ 2010-06-14 14:12 ` tytso
2010-06-14 14:15 ` [PATCH -v2] Only honor the FIGETBSZ ioctl for regular files and directories Theodore Ts'o
0 siblings, 1 reply; 7+ messages in thread
From: tytso @ 2010-06-14 14:12 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Linux Kernel Developers List, Al Viro, Aneesh Kumar K.V
On Mon, Jun 14, 2010 at 10:07:30AM -0400, Christoph Hellwig wrote:
> On Mon, Jun 14, 2010 at 10:05:10AM -0400, Theodore Ts'o wrote:
> > 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.
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH -v2] Only honor the FIGETBSZ ioctl for regular files and directories
2010-06-14 14:12 ` tytso
@ 2010-06-14 14:15 ` Theodore Ts'o
2010-06-14 14:17 ` [PATCH -v3] " Theodore Ts'o
0 siblings, 1 reply; 7+ messages in thread
From: Theodore Ts'o @ 2010-06-14 14:15 UTC (permalink / raw)
To: Linux Kernel Developers List
Cc: Theodore Ts'o, Al Viro, Aneesh Kumar K.V, Johannes Stezenbach
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.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Stezenbach <js@sig21.net>
---
fs/compat_ioctl.c | 6 +++++-
fs/ioctl.c | 5 ++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 641640d..b8607fe 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -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;
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 2d140a7..e578dab 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -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:
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH -v3] Only honor the FIGETBSZ ioctl for regular files and directories
2010-06-14 14:15 ` [PATCH -v2] Only honor the FIGETBSZ ioctl for regular files and directories Theodore Ts'o
@ 2010-06-14 14:17 ` Theodore Ts'o
0 siblings, 0 replies; 7+ messages in thread
From: Theodore Ts'o @ 2010-06-14 14:17 UTC (permalink / raw)
To: Linux Kernel Developers List
Cc: Theodore Ts'o, Al Viro, Aneesh Kumar K.V, Johannes Stezenbach
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.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Stezenbach <js@sig21.net>
---
Fixed up commit description
fs/compat_ioctl.c | 6 +++++-
fs/ioctl.c | 5 ++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 641640d..b8607fe 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -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;
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 2d140a7..e578dab 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -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:
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-06-14 14:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20100614110252.GB32224@sig21.net>
2010-06-14 12:36 ` FIGETBSZ ioctl conflict Johannes Stezenbach
2010-06-14 13:42 ` tytso
2010-06-14 14:05 ` [PATCH] Only honor the FIGETBSZ ioctl for regular files, directories, and symlinks Theodore Ts'o
2010-06-14 14:07 ` Christoph Hellwig
2010-06-14 14:12 ` tytso
2010-06-14 14:15 ` [PATCH -v2] Only honor the FIGETBSZ ioctl for regular files and directories Theodore Ts'o
2010-06-14 14:17 ` [PATCH -v3] " Theodore Ts'o
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.