[PATCH] WE : Add missing auth compat-ioctl
[pandora-kernel.git] / fs / compat_ioctl.c
index 65643de..37310b0 100644 (file)
@@ -63,6 +63,7 @@
 #include <linux/wireless.h>
 #include <linux/atalk.h>
 #include <linux/blktrace_api.h>
+#include <linux/loop.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci.h>
 #include <linux/dvb/video.h>
 #include <linux/lp.h>
 
+#ifdef CONFIG_SPARC
+#include <asm/fbio.h>
+#endif
+
 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
                              unsigned long arg, struct file *f)
 {
@@ -1194,6 +1199,7 @@ static int vt_check(struct file *file)
 {
        struct tty_struct *tty;
        struct inode *inode = file->f_path.dentry->d_inode;
+       struct vc_data *vc;
        
        if (file->f_op->ioctl != tty_ioctl)
                return -EINVAL;
@@ -1204,12 +1210,16 @@ static int vt_check(struct file *file)
                                                        
        if (tty->driver->ioctl != vt_ioctl)
                return -EINVAL;
-       
+
+       vc = (struct vc_data *)tty->driver_data;
+       if (!vc_cons_allocated(vc->vc_num))     /* impossible? */
+               return -ENOIOCTLCMD;
+
        /*
         * To have permissions to do most of the vt ioctls, we either have
-        * to be the owner of the tty, or super-user.
+        * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
         */
-       if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
+       if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
                return 1;
        return 0;                                                    
 }
@@ -1310,16 +1320,28 @@ static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg,
        struct unimapdesc32 tmp;
        struct unimapdesc32 __user *user_ud = compat_ptr(arg);
        int perm = vt_check(file);
-       
-       if (perm < 0) return perm;
+       struct vc_data *vc;
+
+       if (perm < 0)
+               return perm;
        if (copy_from_user(&tmp, user_ud, sizeof tmp))
                return -EFAULT;
+       if (tmp.entries)
+               if (!access_ok(VERIFY_WRITE, compat_ptr(tmp.entries),
+                               tmp.entry_ct*sizeof(struct unipair)))
+                       return -EFAULT;
+       vc = ((struct tty_struct *)file->private_data)->driver_data;
        switch (cmd) {
        case PIO_UNIMAP:
-               if (!perm) return -EPERM;
-               return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
+               if (!perm)
+                       return -EPERM;
+               return con_set_unimap(vc, tmp.entry_ct,
+                                               compat_ptr(tmp.entries));
        case GIO_UNIMAP:
-               return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
+               if (!perm && fg_console != vc->vc_num)
+                       return -EPERM;
+               return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct),
+                                               compat_ptr(tmp.entries));
        }
        return 0;
 }
@@ -2289,8 +2311,10 @@ static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long ar
        struct iwreq __user *iwr_u;
        struct iw_point __user *iwp;
        struct compat_iw_point __user *iwp_u;
-       compat_caddr_t pointer;
+       compat_caddr_t pointer_u;
+       void __user *pointer;
        __u16 length, flags;
+       int ret;
 
        iwr_u = compat_ptr(arg);
        iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
@@ -2308,17 +2332,29 @@ static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long ar
                           sizeof(iwr->ifr_ifrn.ifrn_name)))
                return -EFAULT;
 
-       if (__get_user(pointer, &iwp_u->pointer) ||
+       if (__get_user(pointer_u, &iwp_u->pointer) ||
            __get_user(length, &iwp_u->length) ||
            __get_user(flags, &iwp_u->flags))
                return -EFAULT;
 
-       if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
+       if (__put_user(compat_ptr(pointer_u), &iwp->pointer) ||
            __put_user(length, &iwp->length) ||
            __put_user(flags, &iwp->flags))
                return -EFAULT;
 
-       return sys_ioctl(fd, cmd, (unsigned long) iwr);
+       ret = sys_ioctl(fd, cmd, (unsigned long) iwr);
+
+       if (__get_user(pointer, &iwp->pointer) ||
+           __get_user(length, &iwp->length) ||
+           __get_user(flags, &iwp->flags))
+               return -EFAULT;
+
+       if (__put_user(ptr_to_compat(pointer), &iwp_u->pointer) ||
+           __put_user(length, &iwp_u->length) ||
+           __put_user(flags, &iwp_u->flags))
+               return -EFAULT;
+
+       return ret;
 }
 
 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
@@ -3139,12 +3175,9 @@ COMPATIBLE_IOCTL(SIOCSIWSENS)
 COMPATIBLE_IOCTL(SIOCGIWSENS)
 COMPATIBLE_IOCTL(SIOCSIWRANGE)
 COMPATIBLE_IOCTL(SIOCSIWPRIV)
-COMPATIBLE_IOCTL(SIOCGIWPRIV)
 COMPATIBLE_IOCTL(SIOCSIWSTATS)
-COMPATIBLE_IOCTL(SIOCGIWSTATS)
 COMPATIBLE_IOCTL(SIOCSIWAP)
 COMPATIBLE_IOCTL(SIOCGIWAP)
-COMPATIBLE_IOCTL(SIOCSIWSCAN)
 COMPATIBLE_IOCTL(SIOCSIWRATE)
 COMPATIBLE_IOCTL(SIOCGIWRATE)
 COMPATIBLE_IOCTL(SIOCSIWRTS)
@@ -3157,6 +3190,8 @@ COMPATIBLE_IOCTL(SIOCSIWRETRY)
 COMPATIBLE_IOCTL(SIOCGIWRETRY)
 COMPATIBLE_IOCTL(SIOCSIWPOWER)
 COMPATIBLE_IOCTL(SIOCGIWPOWER)
+COMPATIBLE_IOCTL(SIOCSIWAUTH)
+COMPATIBLE_IOCTL(SIOCGIWAUTH)
 /* hiddev */
 COMPATIBLE_IOCTL(HIDIOCGVERSION)
 COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
@@ -3472,6 +3507,25 @@ HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
 
 IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
 IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
+
+/* loop */
+IGNORE_IOCTL(LOOP_CLR_FD)
+
+#ifdef CONFIG_SPARC
+/* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
+IGNORE_IOCTL(FBIOGTYPE)
+IGNORE_IOCTL(FBIOSATTR)
+IGNORE_IOCTL(FBIOGATTR)
+IGNORE_IOCTL(FBIOSVIDEO)
+IGNORE_IOCTL(FBIOGVIDEO)
+IGNORE_IOCTL(FBIOSCURPOS)
+IGNORE_IOCTL(FBIOGCURPOS)
+IGNORE_IOCTL(FBIOGCURMAX)
+IGNORE_IOCTL(FBIOPUTCMAP32)
+IGNORE_IOCTL(FBIOGETCMAP32)
+IGNORE_IOCTL(FBIOSCURSOR32)
+IGNORE_IOCTL(FBIOGCURSOR32)
+#endif
 };
 
 #define IOCTL_HASHSIZE 256