net: Add compat ioctl support for the ipv4 multicast ioctl SIOCGETSGCNT
Subsystems (4)
PATCH 1/1 net: Add compat ioctl support for the ipv4 multicast ioctl SIOCGETSGCNT
SIOCGETSGCNT is not a unique ioctl value as it it maps tio SIOCPROTOPRIVATE +1, which unfortunately means the existing infrastructure for compat networking ioctls is insufficient. A trivial compact ioctl implementation would conflict with:
SIOCAX25ADDUID
SIOCAIPXPRISLTSIOCGETSGCNT_IN6
SIOCGETSGCNT
SIOCRSSCAUSE
SIOCX25SSUBSCRIP
SIOCX25SDTEFACILITIES
To make this work I have updated the compat_ioctl decode path to mirror the the normal ioctl decode path. I have added an ipv4 inet_compat_ioctl function
so that I can have ipv4 specific compat ioctls. I have added a compat_ioctl
function into struct proto so I can break out ioctls by which kind of ip socket I am using. I have added a compat_raw_ioctl function because SIOCGETSGCNT only works on raw sockets. I have added a ipmr_compat_ioctl that mirrors the normal ipmr_ioctl.
This was necessary because unfortunately the struct layout for the SIOCGETSGCNT has unsigned longs in it so changes between 32bit and 64bit kernels.
This change was sufficient to run a 32bit ip multicast routing daemon on a 64bit kernel.
--- include/linux/mroute.h | 1 + include/net/sock.h | 2 ++ net/ipv4/af_inet.c | 16 ++++++++++++++++ net/ipv4/ipmr.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/raw.c | 19 +++++++++++++++++++ 5 files changed, 84 insertions(+), 0 deletions(-)
include/linux/mroute.h +1 -0
@@ -150,6 +150,7 @@ static inline int ip_mroute_opt(int opt)extern int ip_mroute_setsockopt (struct sock *,int ,char __user *,unsigned int );extern int ip_mroute_getsockopt (struct sock *,int ,char __user *,int __user *);extern int ipmr_ioctl (struct sock *sk,int cmd,void __user *arg); +extern int ipmr_compat_ioctl (struct sock *sk,unsigned int cmd,void __user *arg);extern int ip_mr_init (void );#else static inline
include/net/sock.h +2 -0
@@ -734,6 +734,8 @@ struct proto {int level, int optname, char __user *optval, int __user *option); +int (*compat_ioctl)(struct sock *sk, +unsigned int cmd,unsigned long arg);#endif int (*sendmsg)(struct kiocb *iocb,struct sock *sk,struct msghdr *msg,size_t len);
net/ipv4/af_inet.c +16 -0
@@ -880,6 +880,19 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) }EXPORT_SYMBOL (inet_ioctl); +#ifdef CONFIG_COMPAT +int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) +{ +struct sock *sk = sock->sk; +int err = -ENOIOCTLCMD ; + +if (sk->sk_prot->compat_ioctl) + err = sk->sk_prot->compat_ioctl (sk, cmd, arg); + +return err; +} +#endif +const struct proto_ops inet_stream_ops = { .family =PF_INET , .owner =THIS_MODULE ,
@@ -903,6 +916,7 @@ const struct proto_ops inet_stream_ops = {#ifdef CONFIG_COMPAT .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, + .compat_ioctl = inet_compat_ioctl,#endif };EXPORT_SYMBOL (inet_stream_ops);
@@ -929,6 +943,7 @@ const struct proto_ops inet_dgram_ops = {#ifdef CONFIG_COMPAT .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, + .compat_ioctl = inet_compat_ioctl,#endif };EXPORT_SYMBOL (inet_dgram_ops);
@@ -959,6 +974,7 @@ static const struct proto_ops inet_sockraw_ops = {#ifdef CONFIG_COMPAT .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt, + .compat_ioctl = inet_compat_ioctl,#endif };
net/ipv4/ipmr.c +46 -0
58 lines not on this page · raw message
net/ipv4/raw.c +19 -0
@@ -76,6 +76,7 @@#include <linux/seq_file.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv4.h> +#include <linux/compat.h> static struct raw_hashinfo raw_v4_hashinfo = { .lock =__RW_LOCK_UNLOCKED (raw_v4_hashinfo.lock),
@@ -839,6 +840,23 @@ static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) } } +#ifdef CONFIG_COMPAT +static int compat_raw_ioctl (struct sock *sk,unsigned int cmd,unsigned long arg) +{ +switch (cmd) { +case SIOCOUTQ : +case SIOCINQ : +return -ENOIOCTLCMD ; +default : +#ifdef CONFIG_IP_MROUTE +return ipmr_compat_ioctl (sk, cmd,compat_ptr (arg)); +#else +return -ENOIOCTLCMD ; +#endif + } +} +#endif +struct proto raw_prot = { .name ="RAW" , .owner =THIS_MODULE ,
@@ -861,6 +879,7 @@ struct proto raw_prot = {#ifdef CONFIG_COMPAT .compat_setsockopt = compat_raw_setsockopt, .compat_getsockopt = compat_raw_getsockopt, + .compat_ioctl = compat_raw_ioctl,#endif };
Signature · 1 line
1.6.5.2.143.g8cc62
David Miller
maintainerFrom: [email protected] (Eric W. Biederman)
Date: Sat, 29 Jan 2011 18:15:56 -0800
Quoted 22 lines
SIOCGETSGCNT is not a unique ioctl value as it it maps tio SIOCPROTOPRIVATE +1, which unfortunately means the existing infrastructure for compat networking ioctls is insufficient. A trivial compact ioctl implementation would conflict with:
SIOCAX25ADDUID
SIOCAIPXPRISLTSIOCGETSGCNT_IN6
SIOCGETSGCNT
SIOCRSSCAUSE
SIOCX25SSUBSCRIP
SIOCX25SDTEFACILITIESTo make this work I have updated the
compat_ioctldecode path to mirror the the normal ioctl decode path. I have added an ipv4inet_compat_ioctlfunction
so that I can have ipv4 specific compat ioctls. I have added acompat_ioctl
function into struct proto so I can break out ioctls by which kind of ip socket I am using. I have added acompat_raw_ioctlfunction because SIOCGETSGCNT only works on raw sockets. I have added aipmr_compat_ioctlthat mirrors the normalipmr_ioctl.
Quoted 8 lines
This was necessary because unfortunately the struct layout for the SIOCGETSGCNT has unsigned longs in it so changes between 32bit and 64bit kernels.
This change was sufficient to run a 32bit ip multicast routing daemon on a 64bit kernel.
Reported-by Bill Fenner <[email protected]>Signed-off-by Eric W. Biederman <[email protected]>
Thanks a lot for doing this work Eric, applied to net-2.6.
Quoted 8 lines · On Sunday 30 January 2011 03:15:56 Eric W. Biederman wrote:
A trivial compact ioctl implementation would conflict with:
SIOCAX25ADDUID
SIOCAIPXPRISLTSIOCGETSGCNT_IN6
SIOCGETSGCNT
SIOCRSSCAUSE
SIOCX25SSUBSCRIP
SIOCX25SDTEFACILITIES
Since you have compiled the list, did you see if these are all handled compatible, or would it make sense to create patches for the other protocols as well, to handle them individually?
Quoted 8 lines
This was necessary because unfortunately the struct layout for the SIOCGETSGCNT has unsigned longs in it so changes between 32bit and 64bit kernels.
This change was sufficient to run a 32bit ip multicast routing daemon on a 64bit kernel.
Reported-by Bill Fenner <[email protected]>Signed-off-by Eric W. Biederman <[email protected]>
Looks good,
net/ipv4/raw.c static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) · line 849
Quoted 7 lines
net/ipv4/raw.c +7
-0+#ifdef CONFIG_COMPAT +static int compat_raw_ioctl (struct sock *sk,unsigned int cmd,unsigned long arg) +{ +switch (cmd) { +case SIOCOUTQ : +case SIOCINQ : +return -ENOIOCTLCMD ;
I would have suggested doing
return raw_ioctl(sk, cmd, (unsigned long)compat_ptr(arg));
here, but returning -ENOIOCTLCMD is equivalent and correct. Your solution is slightly more compact, the other one would be slightly faster.
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · On Sunday 30 January 2011 03:15:56 Eric W. Biederman wrote:
A trivial compact ioctl implementation would conflict with:
SIOCAX25ADDUID
SIOCAIPXPRISLTSIOCGETSGCNT_IN6
SIOCGETSGCNT
SIOCRSSCAUSE
SIOCX25SSUBSCRIP
SIOCX25SDTEFACILITIES
Quoted 3 lines
Since you have compiled the list, did you see if these are all handled compatible, or would it make sense to create patches for the other protocols as well, to handle them individually?
I didn't look. I had a specific pre-existing application that didn't work, and those ioctls meant the existing solutions for network compat ioctls wouldn't work and the infrastructure needed fixing.
Quoted 10 lines
net/ipv4/raw.c static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) · line 849
Quoted 7 lines
net/ipv4/raw.c +7
-0+#ifdef CONFIG_COMPAT +static int compat_raw_ioctl (struct sock *sk,unsigned int cmd,unsigned long arg) +{ +switch (cmd) { +case SIOCOUTQ : +case SIOCINQ : +return -ENOIOCTLCMD ;I would have suggested doing
Quoted 4 lines
return raw_ioctl(sk, cmd, (unsigned long)compat_ptr(arg));here, but returning
-ENOIOCTLCMDis equivalent and correct. Your solution is slightly more compact, the other one would be slightly faster.
Correct and maintainable is fine by me.
Right now my network stack performance problems are almost all rtnl_lock hold time problems.
Eric
Quoted 12 lines · On Sunday 30 January 2011 19:15:40 Eric W. Biederman wrote:
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · On Sunday 30 January 2011 03:15:56 Eric W. Biederman wrote:
A trivial compact ioctl implementation would conflict with:
SIOCAX25ADDUID
SIOCAIPXPRISLTSIOCGETSGCNT_IN6
SIOCGETSGCNT
SIOCRSSCAUSE
SIOCX25SSUBSCRIP
SIOCX25SDTEFACILITIES
Quoted 7 lines
Quoted 3 lines
Since you have compiled the list, did you see if these are all handled compatible, or would it make sense to create patches for the other protocols as well, to handle them individually?
I didn't look. I had a specific pre-existing application that didn't work, and those ioctls meant the existing solutions for network compat ioctls wouldn't work and the infrastructure needed fixing.
I just looked at all users of SIOCPROTOPRIVATE to check what else is needed here, for reference. What I found is:
* appletalk, ipx and x25 have full compat_ioctl support.
* ax25 needs some real work in order to be usable in compat mode.
* phonet and rose use only data structures that are compatible, so adding support would be trivial.
* ip multicast actually needs support for SIOCGETVIFCNT in addition to SIOCGETSGCNT to be complete.
* ipv6 multicast needs the same patch as ipv4 multicast for SIOCGETMIFCNT_IN6/SIOCGETSGCNT_IN6.
It would probably be a good idea if someone could complete the work on ipv4/v6 multicast compat_ioctl, on top of your patch.
Arnd
David Miller
maintainerFrom: Arnd Bergmann <[email protected]>
Date: Sun, 30 Jan 2011 19:59:53 +0100
Quoted 7 lines
* ip multicast actually needs support for SIOCGETVIFCNT in addition to SIOCGETSGCNT to be complete.
* ipv6 multicast needs the same patch as ipv4 multicast for SIOCGETMIFCNT_IN6/SIOCGETSGCNT_IN6.It would probably be a good idea if someone could complete the work on ipv4/v6 multicast
compat_ioctl, on top of your patch.
Actually, on top of this, Eric's patch is buggy.
He defines the "struct compat_sioc_sg_req" but doesn't actually use it.
I'll fix that, then take care of the missing cases. Thanks Arnd.
Quoted 8 lines · David Miller
From: Arnd Bergmann <[email protected]>
Date: Sun, 30 Jan 2011 19:59:53 +0100Quoted 5 lines
* ip multicast actually needs support for SIOCGETVIFCNT in addition to SIOCGETSGCNT to be complete.
* ipv6 multicast needs the same patch as ipv4 multicast for SIOCGETMIFCNT_IN6/SIOCGETSGCNT_IN6.
Quoted 4 lines
Quoted 2 lines
It would probably be a good idea if someone could complete the work on ipv4/v6 multicast
compat_ioctl, on top of your patch.Actually, on top of this, Eric's patch is buggy.
Ouch. Thanks for catching that.
Quoted 4 lines
He defines the "struct
compat_sioc_sg_req" but doesn't actually use it.I'll fix that, then take care of the missing cases. Thanks Arnd.
Eric