OSDN Git Service

net: socket: Use convoluted tricks to silence a GCC 9 error
authorSultan Alsawaf <sultan@kerneltoast.com>
Thu, 27 Jun 2019 00:45:57 +0000 (17:45 -0700)
committer0ranko0P <ranko0p@outlook.com>
Wed, 4 Dec 2019 17:17:34 +0000 (01:17 +0800)
GCC 9 is unhappy that we copy three struct's worth of data to a pointer
for a single struct. And it is rightfully unhappy, but net devs are
crazy and know better. Expand the pointer arithmetic bothering GCC to
make it shut up.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
net/socket.c

index 690b4de..dba9112 100644 (file)
@@ -3064,8 +3064,9 @@ static int routing_ioctl(struct net *net, struct socket *sock,
 
        if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */
                struct in6_rtmsg32 __user *ur6 = argp;
-               ret = copy_from_user(&r6.rtmsg_dst, &(ur6->rtmsg_dst),
-                       3 * sizeof(struct in6_addr));
+               ret = copy_from_user((u8 *)&r6 + offsetof(typeof(r6), rtmsg_dst),
+                                    (u8 *)ur6 + offsetof(typeof(*ur6), rtmsg_dst),
+                                    3 * sizeof(r6.rtmsg_dst));
                ret |= get_user(r6.rtmsg_type, &(ur6->rtmsg_type));
                ret |= get_user(r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
                ret |= get_user(r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
@@ -3077,8 +3078,9 @@ static int routing_ioctl(struct net *net, struct socket *sock,
                r = (void *) &r6;
        } else { /* ipv4 */
                struct rtentry32 __user *ur4 = argp;
-               ret = copy_from_user(&r4.rt_dst, &(ur4->rt_dst),
-                                       3 * sizeof(struct sockaddr));
+               ret = copy_from_user((u8 *)&r4 + offsetof(typeof(r4), rt_dst),
+                                    (u8 *)ur4 + offsetof(typeof(*ur4), rt_dst),
+                                    3 * sizeof(r4.rt_dst));
                ret |= get_user(r4.rt_flags, &(ur4->rt_flags));
                ret |= get_user(r4.rt_metric, &(ur4->rt_metric));
                ret |= get_user(r4.rt_mtu, &(ur4->rt_mtu));