Module: xenomai-3
Branch: wip/rtnet-fixes
Commit: 84c4c98ca876a170914a6c4e27091ecea64e4b00
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=84c4c98ca876a170914a6c4e27091ecea64e4b00

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Jan  7 18:26:48 2018 +0100

net/socket: ioctl: remove direct references to user memory (2)

---

 kernel/drivers/net/stack/socket.c |   47 ++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/kernel/drivers/net/stack/socket.c 
b/kernel/drivers/net/stack/socket.c
index 66665b2..d7d36d5 100644
--- a/kernel/drivers/net/stack/socket.c
+++ b/kernel/drivers/net/stack/socket.c
@@ -243,25 +243,20 @@ EXPORT_SYMBOL_GPL(rt_socket_common_ioctl);
 int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, void __user *arg)
 {
     struct rtnet_device *rtdev;
-    const struct ifreq  *ifr;
-    struct ifreq        _ifr, *ifrw;
+    struct ifreq _ifr, *ifr, *u_ifr;
     struct sockaddr_in  _sin;
-    const struct ifconf *ifc;
-    struct ifconf _ifc, *ifcw;
+    struct ifconf _ifc, *ifc, *u_ifc;
     int ret = 0, size = 0, i;
     short flags;
 
 
     if (request == SIOCGIFCONF) {
-       ifc = rtnet_get_arg(fd, &_ifc, arg, sizeof(_ifc));
+       u_ifc = arg;
+       ifc = rtnet_get_arg(fd, &_ifc, u_ifc, sizeof(_ifc));
        if (IS_ERR(ifc))
                return PTR_ERR(ifc);
 
-       for (ifrw = ifc->ifc_req, i = 1; i <= MAX_RT_DEVICES; i++) {
-               ifrw = (struct ifreq *)rtnet_get_arg(fd, &_ifr, ifrw, 
sizeof(_ifr));
-               if (IS_ERR(ifrw))
-                       return PTR_ERR(ifrw);
-
+       for (u_ifr = ifc->ifc_req, i = 1; i <= MAX_RT_DEVICES; i++, u_ifr++) {
                rtdev = rtdev_get_by_index(i);
                if (rtdev == NULL)
                        continue;
@@ -278,26 +273,24 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, 
void __user *arg)
                        break;
                }
 
-               ret = rtnet_put_arg(fd, ifrw->ifr_name, rtdev->name, IFNAMSIZ);
+               ret = rtnet_put_arg(fd, u_ifr->ifr_name, rtdev->name, IFNAMSIZ);
                if (ret == 0) {
                        memset(&_sin, 0, sizeof(_sin));
                        _sin.sin_family      = AF_INET;
                        _sin.sin_addr.s_addr = rtdev->local_ip;
-                       ret = rtnet_put_arg(fd, &ifrw->ifr_addr, &_sin, 
sizeof(ifrw->ifr_addr));
+                       ret = rtnet_put_arg(fd, &u_ifr->ifr_addr, &_sin, 
sizeof(_sin));
                }
                
                rtdev_dereference(rtdev);
                if (ret)
                        return ret;
-               ifrw++;
        }
 
-       ifcw = arg;
-       return rtnet_put_arg(fd, &ifcw->ifc_len, &size, sizeof(size));
+       return rtnet_put_arg(fd, &u_ifc->ifc_len, &size, sizeof(size));
     }
 
-    ifrw = arg;
-    ifr = rtnet_get_arg(fd, &_ifr, arg, sizeof(_ifr));
+    u_ifr = arg;
+    ifr = rtnet_get_arg(fd, &_ifr, u_ifr, sizeof(_ifr));
     if (IS_ERR(ifr))
            return PTR_ERR(ifr);
 
@@ -305,7 +298,7 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, 
void __user *arg)
         rtdev = rtdev_get_by_index(ifr->ifr_ifindex);
         if (rtdev == NULL)
             return -ENODEV;
-       ret = rtnet_put_arg(fd, ifrw->ifr_name, rtdev->name, IFNAMSIZ);
+       ret = rtnet_put_arg(fd, u_ifr->ifr_name, rtdev->name, IFNAMSIZ);
        goto out;
     }
 
@@ -315,8 +308,8 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, 
void __user *arg)
 
     switch (request) {
        case SIOCGIFINDEX:
-               ret = rtnet_put_arg(fd, &ifrw->ifr_ifindex, &rtdev->ifindex,
-                                   sizeof(ifrw->ifr_ifindex));
+               ret = rtnet_put_arg(fd, &u_ifr->ifr_ifindex, &rtdev->ifindex,
+                                   sizeof(u_ifr->ifr_ifindex));
                break;
 
        case SIOCGIFFLAGS:
@@ -327,23 +320,23 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, 
void __user *arg)
                           | RTNET_LINK_STATE_NOCARRIER))
                     == RTNET_LINK_STATE_PRESENT)
                        flags |= IFF_RUNNING;
-               ret = rtnet_put_arg(fd, &ifrw->ifr_flags, &flags,
-                                   sizeof(ifrw->ifr_flags));
+               ret = rtnet_put_arg(fd, &u_ifr->ifr_flags, &flags,
+                                   sizeof(u_ifr->ifr_flags));
                break;
 
        case SIOCGIFHWADDR:
-               ret = rtnet_put_arg(fd, &ifrw->ifr_hwaddr.sa_data, 
rtdev->dev_addr,
-                                   rtdev->addr_len);
+               ret = rtnet_put_arg(fd, &u_ifr->ifr_hwaddr.sa_data,
+                                   rtdev->dev_addr, rtdev->addr_len);
                if (!ret)
-                       ret = rtnet_put_arg(fd, &ifrw->ifr_hwaddr.sa_family, 
&rtdev->type,
-                                           sizeof(ifrw->ifr_hwaddr.sa_family));
+                       ret = rtnet_put_arg(fd, &u_ifr->ifr_hwaddr.sa_family,
+                                           &rtdev->type, 
sizeof(u_ifr->ifr_hwaddr.sa_family));
                break;
 
        case SIOCGIFADDR:
                memset(&_sin, 0, sizeof(_sin));
                _sin.sin_family      = AF_INET;
                _sin.sin_addr.s_addr = rtdev->local_ip;
-               ret = rtnet_put_arg(fd, &ifrw->ifr_addr, &_sin, 
sizeof(ifrw->ifr_addr));
+               ret = rtnet_put_arg(fd, &u_ifr->ifr_addr, &_sin, sizeof(_sin));
                break;
 
        case SIOCETHTOOL:


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to