X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fioctl.c;h=f6903106d434c2814126b6306d55d558f779f64e;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=9737a0fa881c598c890617bca80bb34b86268b8a;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/fs/ioctl.c b/fs/ioctl.c index 9737a0fa8..f6903106d 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -4,20 +4,59 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#include +#include #include #include +#include #include #include #include +#include +#include +#include +#include #include #include -static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg) + +#ifdef CONFIG_VSERVER_LEGACY +extern int vx_proc_ioctl(struct inode *, struct file *, + unsigned int, unsigned long); +#endif + +static long do_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + int error = -ENOTTY; + + if (!filp->f_op) + goto out; + + if (filp->f_op->unlocked_ioctl) { + error = filp->f_op->unlocked_ioctl(filp, cmd, arg); + if (error == -ENOIOCTLCMD) + error = -EINVAL; + goto out; + } else if (filp->f_op->ioctl) { + lock_kernel(); + error = filp->f_op->ioctl(filp->f_dentry->d_inode, + filp, cmd, arg); + unlock_kernel(); + } + + out: + return error; +} + +static int file_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) { int error; int block; struct inode * inode = filp->f_dentry->d_inode; + int __user *p = (int __user *)arg; switch (cmd) { case FIBMAP: @@ -29,42 +68,37 @@ static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg) return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; - if ((error = get_user(block, (int *) arg)) != 0) + if ((error = get_user(block, p)) != 0) return error; + lock_kernel(); res = mapping->a_ops->bmap(mapping, block); - return put_user(res, (int *) arg); + unlock_kernel(); + return put_user(res, p); } case FIGETBSZ: if (inode->i_sb == NULL) return -EBADF; - return put_user(inode->i_sb->s_blocksize, (int *) arg); + return put_user(inode->i_sb->s_blocksize, p); case FIONREAD: - return put_user(i_size_read(inode) - filp->f_pos, (int *) arg); + return put_user(i_size_read(inode) - filp->f_pos, p); } - if (filp->f_op && filp->f_op->ioctl) - return filp->f_op->ioctl(inode, filp, cmd, arg); - return -ENOTTY; -} + return do_ioctl(filp, cmd, arg); +} -asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) -{ - struct file * filp; +/* + * When you add any new common ioctls to the switches above and below + * please update compat_sys_ioctl() too. + * + * vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d. + * It's just a simple helper for sys_ioctl and compat_sys_ioctl. + */ +int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned long arg) +{ unsigned int flag; - int on, error = -EBADF; - - filp = fget(fd); - if (!filp) - goto out; - - error = security_file_ioctl(filp, cmd, arg); - if (error) { - fput(filp); - goto out; - } + int on, error = 0; - lock_kernel(); switch (cmd) { case FIOCLEX: set_close_on_exec(fd, 1); @@ -96,8 +130,11 @@ asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) /* Did FASYNC state change ? */ if ((flag ^ filp->f_flags) & FASYNC) { - if (filp->f_op && filp->f_op->fasync) + if (filp->f_op && filp->f_op->fasync) { + lock_kernel(); error = filp->f_op->fasync(fd, filp, on); + unlock_kernel(); + } else error = -ENOTTY; } if (error != 0) @@ -119,16 +156,83 @@ asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) else error = -ENOTTY; break; - default: +#ifdef CONFIG_VSERVER_LEGACY +#ifndef CONFIG_INOXID_NONE + case FIOC_GETXID: { + struct inode *inode = filp->f_dentry->d_inode; + + /* fixme: if stealth, return -ENOTTY */ + error = -EPERM; + if (capable(CAP_CONTEXT)) + error = put_user(inode->i_xid, (int __user *) arg); + break; + } + case FIOC_SETXID: { + struct inode *inode = filp->f_dentry->d_inode; + int xid; + + /* fixme: if stealth, return -ENOTTY */ + error = -EPERM; + if (!capable(CAP_CONTEXT)) + break; + error = -EROFS; + if (IS_RDONLY(inode)) + break; + error = -ENOSYS; + if (!(inode->i_sb->s_flags & MS_TAGXID)) + break; + error = -EFAULT; + if (get_user(xid, (int __user *) arg)) + break; + error = 0; + inode->i_xid = (xid & 0xFFFF); + inode->i_ctime = CURRENT_TIME; + mark_inode_dirty(inode); + break; + } +#endif + case FIOC_GETXFLG: + case FIOC_SETXFLG: error = -ENOTTY; + if (filp->f_dentry->d_inode->i_sb->s_magic == PROC_SUPER_MAGIC) + error = vx_proc_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); + break; +#endif + default: if (S_ISREG(filp->f_dentry->d_inode->i_mode)) error = file_ioctl(filp, cmd, arg); - else if (filp->f_op && filp->f_op->ioctl) - error = filp->f_op->ioctl(filp->f_dentry->d_inode, filp, cmd, arg); + else + error = do_ioctl(filp, cmd, arg); + break; } - unlock_kernel(); - fput(filp); + return error; +} + +asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) +{ + struct file * filp; + int error = -EBADF; + int fput_needed; + + filp = fget_light(fd, &fput_needed); + if (!filp) + goto out; + + error = security_file_ioctl(filp, cmd, arg); + if (error) + goto out_fput; -out: + error = vfs_ioctl(filp, fd, cmd, arg); + out_fput: + fput_light(filp, fput_needed); + out: return error; } + +/* + * Platforms implementing 32 bit compatibility ioctl handlers in + * modules need this exported + */ +#ifdef CONFIG_COMPAT +EXPORT_SYMBOL(sys_ioctl); +#endif