login
Header Space

 
 

Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit kernels.

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@...>
Cc: <davem@...>, <netdev@...>, <yoshfuji@...>
Date: Saturday, April 26, 2008 - 7:55 pm

YOSHIFUJI Hideaki / $B5HF#1QL@(B <yoshfuji@linux-ipv6.org> wrote on 04/25/2008 
08:33:59 PM:


        __copy_in_user seems to be an alias for copy_from_user
(ie, user-to-kernel), which is totally different from
copy_in_user (user to user).
        It's terrible naming, but I think copy_in_user() is
what we want.

        On aligned(4) and packed, I think the net effect of
the discussion last night is to leave it alone.
        The only change in this version is to replace cross
references of the setsockopt routines with passing those as
an argument from the callers.

                                                +-DLS

Add support on 64-bit kernels for seting 32-bit compatible
MCAST* socket options.

Signed-off-by: David L Stevens <dlstevens@us.ibm.com>

diff -ruNp linux-2.6.18.ppc64/include/net/compat.h 
linux-2.6.18.ppc64DLS2/include/net/compat.h
--- linux-2.6.18.ppc64/include/net/compat.h     2008-04-21 
13:50:33.000000000 -0700
+++ linux-2.6.18.ppc64DLS2/include/net/compat.h 2008-04-26 
04:34:04.000000000 -0700
@@ -39,4 +39,7 @@ extern int put_cmsg_compat(struct msghdr
 
 extern int cmsghdr_from_user_compat_to_kern(struct msghdr *, struct sock 
*, unsigned char *, int);
 
+extern int compat_mc_setsockopt(struct sock *, int, int, char __user *, 
int,
+       int (*)(struct sock *, int, int, char __user *, int));
+
 #endif /* NET_COMPAT_H */
diff -ruNp linux-2.6.18.ppc64/net/compat.c 
linux-2.6.18.ppc64DLS2/net/compat.c
--- linux-2.6.18.ppc64/net/compat.c     2008-04-21 13:51:02.000000000 
-0700
+++ linux-2.6.18.ppc64DLS2/net/compat.c 2008-04-26 04:35:22.000000000 
-0700
@@ -26,6 +26,8 @@
 
 #include <net/scm.h>
 #include <net/sock.h>
+#include <net/ip.h>
+#include <net/ipv6.h>
 #include <asm/uaccess.h>
 #include <net/compat.h>
 
@@ -589,6 +591,121 @@ asmlinkage long compat_sys_getsockopt(in
        }
        return err;
 }
+
+struct compat_group_req {
+       __u32                            gr_interface;
+       struct __kernel_sockaddr_storage gr_group
+               __attribute__ ((aligned(4)));
+} __attribute__ ((packed));
+
+struct compat_group_source_req {
+       __u32                            gsr_interface;
+       struct __kernel_sockaddr_storage gsr_group
+               __attribute__ ((aligned(4)));
+       struct __kernel_sockaddr_storage gsr_source
+               __attribute__ ((aligned(4)));
+} __attribute__ ((packed));
+
+struct compat_group_filter {
+       __u32                            gf_interface;
+       struct __kernel_sockaddr_storage gf_group
+               __attribute__ ((aligned(4)));
+       __u32                            gf_fmode;
+       __u32                            gf_numsrc;
+       struct __kernel_sockaddr_storage gf_slist[1]
+               __attribute__ ((aligned(4)));
+} __attribute__ ((packed));
+
+
+int compat_mc_setsockopt(struct sock *sock, int level, int optname,
+       char __user *optval, int optlen,
+       int (*setsockopt)(struct sock *,int,int,char __user *,int))
+{
+       char __user     *koptval = optval;
+       int             koptlen = optlen;
+
+       switch (optname) {
+       case MCAST_JOIN_GROUP:
+       case MCAST_LEAVE_GROUP:
+       {
+               struct compat_group_req __user *gr32 = (void *)optval;
+               struct group_req __user *kgr =
+                       compat_alloc_user_space(sizeof(struct group_req));
+               u32 interface;
+
+               if (!access_ok(VERIFY_READ, gr32, sizeof(*gr32)) ||
+                   !access_ok(VERIFY_WRITE, kgr, sizeof(struct 
group_req)) ||
+                   __get_user(interface, &gr32->gr_interface) ||
+                   __put_user(interface, &kgr->gr_interface) ||
+                   copy_in_user(&kgr->gr_group, &gr32->gr_group,
+                               sizeof(kgr->gr_group)))
+                       return -EFAULT;
+               koptval = (char __user *)kgr;
+               koptlen = sizeof(struct group_req);
+               break;
+       }
+       case MCAST_JOIN_SOURCE_GROUP:
+       case MCAST_LEAVE_SOURCE_GROUP:
+       case MCAST_BLOCK_SOURCE:
+       case MCAST_UNBLOCK_SOURCE:
+       {
+               struct compat_group_source_req __user *gsr32 = (void 
*)optval;
+               struct group_source_req *kgsr = compat_alloc_user_space(
+                       sizeof(struct group_source_req));
+               u32 interface;
+
+               if (!access_ok(VERIFY_READ, gsr32, sizeof(*gsr32)) ||
+                   !access_ok(VERIFY_WRITE, kgsr,
+                       sizeof(struct group_source_req)) ||
+                   __get_user(interface, &gsr32->gsr_interface) ||
+                   __put_user(interface, &kgsr->gsr_interface) ||
+                   copy_in_user(&kgsr->gsr_group, &gsr32->gsr_group,
+                               sizeof(kgsr->gsr_group)) ||
+                   copy_in_user(&kgsr->gsr_source, &gsr32->gsr_source,
+                               sizeof(kgsr->gsr_source)))
+                       return -EFAULT;
+               koptval = (char __user *)kgsr;
+               koptlen = sizeof(struct group_source_req);
+               break;
+       }
+       case MCAST_MSFILTER:
+       {
+               struct compat_group_filter __user *gf32 = (void *)optval;
+               struct group_filter *kgf;
+               u32 interface, fmode, numsrc;
+
+               if (!access_ok(VERIFY_READ, gf32, sizeof(*gf32)) ||
+                   __get_user(interface, &gf32->gf_interface) ||
+                   __get_user(fmode, &gf32->gf_fmode) ||
+                   __get_user(numsrc, &gf32->gf_numsrc))
+                       return -EFAULT;
+               koptlen = optlen + sizeof(struct group_filter) -
+                               sizeof(struct compat_group_filter);
+               if (koptlen < GROUP_FILTER_SIZE(numsrc))
+                       return -EINVAL;
+               kgf = compat_alloc_user_space(koptlen);
+               if (!access_ok(VERIFY_WRITE, kgf, koptlen) ||
+                   __put_user(interface, &kgf->gf_interface) ||
+                   __put_user(fmode, &kgf->gf_fmode) ||
+                   __put_user(numsrc, &kgf->gf_numsrc) ||
+                   copy_in_user(&kgf->gf_group, &gf32->gf_group,
+                               sizeof(kgf->gf_group)) ||
+                   (numsrc && copy_in_user(&kgf->gf_slist, 
&gf32->gf_slist,
+                               numsrc * sizeof(kgf->gf_slist[0]))))
+                       return -EFAULT;
+               koptval = (char __user *)kgf;
+               break;
+       }
+
+       default:
+               break;
+       }
+       return setsockopt(sock, level, optname, koptval, koptlen);
+}
+
+EXPORT_SYMBOL(compat_mc_setsockopt);
+
+
 /* Argument list sizes for compat_sys_socketcall */
 #define AL(x) ((x) * sizeof(u32))
 static unsigned char nas[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
diff -ruNp linux-2.6.18.ppc64/net/ipv4/ip_sockglue.c 
linux-2.6.18.ppc64DLS2/net/ipv4/ip_sockglue.c
--- linux-2.6.18.ppc64/net/ipv4/ip_sockglue.c   2008-04-21 
13:51:00.000000000 -0700
+++ linux-2.6.18.ppc64DLS2/net/ipv4/ip_sockglue.c       2008-04-26 
04:36:24.000000000 -0700
@@ -37,6 +37,7 @@
 #include <linux/mroute.h>
 #include <net/route.h>
 #include <net/xfrm.h>
+#include <net/compat.h>
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
 #include <net/transp_v6.h>
 #endif
@@ -921,6 +922,10 @@ int compat_ip_setsockopt(struct sock *sk
        if (level != SOL_IP)
                return -ENOPROTOOPT;
 
+       if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
+               return compat_mc_setsockopt(sk, level, optname, optval, 
optlen,
+                       ip_setsockopt);
+
        err = do_ip_setsockopt(sk, level, optname, optval, optlen);
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default 
case */
diff -ruNp linux-2.6.18.ppc64/net/ipv6/ipv6_sockglue.c 
linux-2.6.18.ppc64DLS2/net/ipv6/ipv6_sockglue.c
--- linux-2.6.18.ppc64/net/ipv6/ipv6_sockglue.c 2008-04-21 
13:51:02.000000000 -0700
+++ linux-2.6.18.ppc64DLS2/net/ipv6/ipv6_sockglue.c     2008-04-26 
04:35:19.000000000 -0700
@@ -52,6 +52,7 @@
 #include <net/tcp.h>
 #include <net/udp.h>
 #include <net/xfrm.h>
+#include <net/compat.h>
 
 #include <asm/uaccess.h>
 
@@ -769,6 +770,10 @@ int compat_ipv6_setsockopt(struct sock *
        if (level != SOL_IPV6)
                return -ENOPROTOOPT;
 
+       if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
+               return compat_mc_setsockopt(sk, level, optname, optval, 
optlen,
+                       ipv6_setsockopt);
+
        err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
 #ifdef CONFIG_NETFILTER
        /* we need to exclude all possible ENOPROTOOPTs except default 
case */
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit kern..., YOSHIFUJI Hideaki / , (Thu Apr 24, 4:02 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Fri Apr 25, 2:37 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Fri Apr 25, 2:59 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Fri Apr 25, 3:24 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Sat Apr 26, 1:14 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Fri Apr 25, 11:33 pm)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., David Stevens, (Sat Apr 26, 7:55 pm)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Sat Apr 26, 1:09 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Sat Apr 26, 12:53 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Sat Apr 26, 1:56 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Fri Apr 25, 1:38 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Thu Apr 24, 4:16 am)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Thu Apr 24, 2:46 pm)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Thu Apr 24, 4:43 pm)
Re: [GIT PULL] [IPV6] COMPAT: Fix SSM applications on 64bit ..., YOSHIFUJI Hideaki / , (Thu Apr 24, 5:28 am)
speck-geostationary