OSDN Git Service

cmtp: fix compat_ioctl
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 17 Aug 2018 01:37:56 +0000 (21:37 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 10 Sep 2018 16:41:06 +0000 (12:41 -0400)
Use compat_ptr().  And don't mess with fs/compat_ioctl.c

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/compat_ioctl.c
net/bluetooth/cmtp/sock.c

index b183496..4e049f4 100644 (file)
@@ -534,11 +534,6 @@ static int mt_ioctl_trans(struct file *file,
 #define HCIUARTSETFLAGS                _IOW('U', 203, int)
 #define HCIUARTGETFLAGS                _IOR('U', 204, int)
 
-#define CMTPCONNADD    _IOW('C', 200, int)
-#define CMTPCONNDEL    _IOW('C', 201, int)
-#define CMTPGETCONNLIST        _IOR('C', 210, int)
-#define CMTPGETCONNINFO        _IOR('C', 211, int)
-
 #define HIDPCONNADD    _IOW('H', 200, int)
 #define HIDPCONNDEL    _IOW('H', 201, int)
 #define HIDPGETCONNLIST        _IOR('H', 210, int)
@@ -1090,10 +1085,6 @@ COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
-COMPATIBLE_IOCTL(CMTPCONNADD)
-COMPATIBLE_IOCTL(CMTPCONNDEL)
-COMPATIBLE_IOCTL(CMTPGETCONNLIST)
-COMPATIBLE_IOCTL(CMTPGETCONNINFO)
 COMPATIBLE_IOCTL(HIDPCONNADD)
 COMPATIBLE_IOCTL(HIDPCONNDEL)
 COMPATIBLE_IOCTL(HIDPGETCONNLIST)
index e08f28f..defdd48 100644 (file)
@@ -63,17 +63,16 @@ static int cmtp_sock_release(struct socket *sock)
        return 0;
 }
 
-static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+static int do_cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, void __user *argp)
 {
        struct cmtp_connadd_req ca;
        struct cmtp_conndel_req cd;
        struct cmtp_connlist_req cl;
        struct cmtp_conninfo ci;
        struct socket *nsock;
-       void __user *argp = (void __user *)arg;
        int err;
 
-       BT_DBG("cmd %x arg %lx", cmd, arg);
+       BT_DBG("cmd %x arg %p", cmd, argp);
 
        switch (cmd) {
        case CMTPCONNADD:
@@ -137,16 +136,22 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
        return -EINVAL;
 }
 
+static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       return do_cmtp_sock_ioctl(sock, cmd, (void __user *)arg);
+}
+
 #ifdef CONFIG_COMPAT
 static int cmtp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 {
+       void __user *argp = compat_ptr(arg);
        if (cmd == CMTPGETCONNLIST) {
                struct cmtp_connlist_req cl;
+               u32 __user *p = argp;
                u32 uci;
                int err;
 
-               if (get_user(cl.cnum, (u32 __user *) arg) ||
-                               get_user(uci, (u32 __user *) (arg + 4)))
+               if (get_user(cl.cnum, p) || get_user(uci, p + 1))
                        return -EFAULT;
 
                cl.ci = compat_ptr(uci);
@@ -156,13 +161,13 @@ static int cmtp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigne
 
                err = cmtp_get_connlist(&cl);
 
-               if (!err && put_user(cl.cnum, (u32 __user *) arg))
+               if (!err && put_user(cl.cnum, p))
                        err = -EFAULT;
 
                return err;
        }
 
-       return cmtp_sock_ioctl(sock, cmd, arg);
+       return do_cmtp_sock_ioctl(sock, cmd, argp);
 }
 #endif