uaccess-related stuff in net/*
Subsystems (5)
RFC PATCH 1/1 uaccess-related stuff in net/*
Assorted uaccess-related work in net/*. First, there's
getting rid of compat_alloc_user_space() mess in MCAST_... [gs]etsockopt() - no need to play with copying to/from temporary object on userland stack, etc., when ->compat_[sg]etsockopt() instances in question can easly do everything without that. That's the first 13 patches. Then there's a trivial bit in net/batman-adv (completely unrelated to everything else) and finally getting the atm compat ioctls into simpler shape.
Please, review and comment. Individual patches in followups,
the entire branch (on top of current net/master) is ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #uaccess.net
Shortlog:
Al Viro (19):
lift compat definitions of mcast [sg]etsockopt requests into net/compat.h compat_ip{,v6}_setsockopt(): enumerate MCAST_... options explicitly ip*_mc_gsfget(): lift copyout of struct group_filter into callers get rid of compat_mc_getsockopt()
set_mcast_msfilter(): take the guts of setsockopt(MCAST_MSFILTER) into a helper
ipv4: do compat setsockopt for MCAST_MSFILTER directly ip6_mc_msfilter(): pass the address list separately
ipv6: do compat setsockopt for MCAST_MSFILTER directly
ipv[46]: do compat setsockopt for MCAST_{JOIN,LEAVE}_GROUP directly
ipv4: take handling of group_source_req options into a helper
ipv6: take handling of group_source_req options into a helper handle the group_source_req options directly
get rid of compat_mc_setsockopt()
batadv_socket_read(): get rid of pointless access_ok()
atm: separate ATM_GETNAMES handling from the rest of atm_dev_ioctl()
atm: move copyin from atm_getnames() into the caller
atm: switch do_atm_iobuf() to direct use of atm_getnames()
atm: lift copyin from atm_dev_ioctl()
atm: switch do_atmif_sioc() to direct use of atm_dev_ioctl()
Diffstat:
include/linux/igmp.h | 2 +- include/net/compat.h | 29 +++- include/net/ipv6.h | 5 +- net/atm/ioctl.c | 96 +++++++------ net/atm/resources.c | 108 +++++--------- net/atm/resources.h | 5 +- net/batman-adv/icmp_socket.c | 3 - net/compat.c | 194 ------------------------- net/ipv4/igmp.c | 18 +-- net/ipv4/ip_sockglue.c | 329 ++++++++++++++++++++++++++++++++----------- net/ipv6/ipv6_sockglue.c | 233 ++++++++++++++++++++++++------ net/ipv6/mcast.c | 17 +-- 12 files changed, 567 insertions(+), 472 deletions(-)
PATCH 2/19 compat_ip{,v6}_setsockopt(): enumerate MCAST_... options explicitly
In reply to Al ViroFrom: Al Viro <[email protected]>
We want to check if optname is among the MCAST_... ones; do that as an explicit switch.
--- net/ipv4/ip_sockglue.c | 10 +++++++++- net/ipv6/ipv6_sockglue.c | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-)
net/ipv4/ip_sockglue.c +9 -1
@@ -1272,9 +1272,17 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,if (level !=SOL_IP )return -ENOPROTOOPT ; -if (optname >=MCAST_JOIN_GROUP && optname <=MCAST_MSFILTER ) +switch (optname) { +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case 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
net/ipv6/ipv6_sockglue.c +9 -1
@@ -973,9 +973,17 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,if (level !=SOL_IPV6 )return -ENOPROTOOPT ; -if (optname >=MCAST_JOIN_GROUP && optname <=MCAST_MSFILTER ) +switch (optname) { +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case 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
Signature · 1 line
2.11.0
PATCH 16/19 atm: move copyin from atm_getnames() into the caller
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 19 ++++++++++++++++++- net/atm/resources.c | 19 +------------------ net/atm/resources.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-)
net/atm/ioctl.c +18 -1
@@ -56,6 +56,8 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,int error;struct list_head *pos;void __user *argp = (void __user *)arg; +void __user *buf; +int __user *len; vcc =ATM_SD (sock);switch (cmd) {
@@ -163,7 +165,22 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, goto done;if (cmd ==ATM_GETNAMES ) { - error =atm_getnames (argp, compat); +if (IS_ENABLED (CONFIG_COMPAT ) && compat) { +#ifdef CONFIG_COMPAT +struct compat_atm_iobuf __user *ciobuf = argp; +compat_uptr_t cbuf; + len = &ciobuf->length; +if (get_user (cbuf, &ciobuf->buffer)) +return -EFAULT ; + buf =compat_ptr (cbuf); +#endif + }else { +struct atm_iobuf __user *iobuf = argp; + len = &iobuf->length; +if (get_user (buf, &iobuf->buffer)) +return -EFAULT ; + } + error =atm_getnames (buf, len); }else { error =atm_dev_ioctl (cmd, argp, compat); }
net/atm/resources.c +1 -18
@@ -193,30 +193,13 @@ static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg,return error ? -EFAULT :0 ; } -int atm_getnames (void __user *arg,int compat) +int atm_getnames (void __user *buf,int __user *iobuf_len) { -void __user *buf;int error, len, size =0 ;struct atm_dev *dev;struct list_head *p;int *tmp_buf, *tmp_p; -int __user *iobuf_len; -if (IS_ENABLED (CONFIG_COMPAT ) && compat) { -#ifdef CONFIG_COMPAT -struct compat_atm_iobuf __user *ciobuf = arg; -compat_uptr_t cbuf; - iobuf_len = &ciobuf->length; -if (get_user (cbuf, &ciobuf->buffer)) -return -EFAULT ; - buf =compat_ptr (cbuf); -#endif - }else { -struct atm_iobuf __user *iobuf = arg; - iobuf_len = &iobuf->length; -if (get_user (buf, &iobuf->buffer)) -return -EFAULT ; - }if (get_user (len, iobuf_len))return -EFAULT ;mutex_lock (&atm_dev_mutex);
net/atm/resources.h +1 -1
@@ -14,7 +14,7 @@extern struct list_head atm_devs;extern struct mutex atm_dev_mutex; -int atm_getnames (void __user *arg,int compat); +int atm_getnames (void __user *buf,int __user *iobuf_len);int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat);
Signature · 1 line
2.11.0
PATCH 17/19 atm: switch do_atm_iobuf() to direct use of atm_getnames()
In reply to Al ViroFrom: Al Viro <[email protected]>
... and sod the compat_alloc_user_space() with its complications
--- net/atm/ioctl.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
net/atm/ioctl.c +3 -22
@@ -251,32 +251,13 @@ static struct {static int do_atm_iobuf (struct socket *sock,unsigned int cmd,unsigned long arg) { -struct atm_iobuf __user *iobuf; -struct compat_atm_iobuf __user *iobuf32; +struct compat_atm_iobuf __user *iobuf32 =compat_ptr (arg);u32 data; -void __user *datap; -int len, err; - - iobuf =compat_alloc_user_space (sizeof (*iobuf)); - iobuf32 =compat_ptr (arg); -if (get_user (len, &iobuf32->length) || -get_user (data, &iobuf32->buffer)) -return -EFAULT ; - datap =compat_ptr (data); -if (put_user (len, &iobuf->length) || -put_user (datap, &iobuf->buffer)) +if (get_user (data, &iobuf32->buffer))return -EFAULT ; - err =do_vcc_ioctl (sock, cmd, (unsigned long ) iobuf,0 ); - -if (!err) { -if (copy_in_user (&iobuf32->length, &iobuf->length, -sizeof (int ))) - err = -EFAULT ; - } - -return err; +return atm_getnames (&iobuf32->length,compat_ptr (data)); } static int do_atmif_sioc(struct socket *sock, unsigned int cmd,
Signature · 1 line
2.11.0
PATCH 8/19 ipv6: do compat setsockopt for MCAST_MSFILTER directly
In reply to Al ViroFrom: Al Viro <[email protected]>
similar to the ipv4 counterpart of that patch - the same trick used to align the tail array properly.
--- net/ipv6/ipv6_sockglue.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
net/ipv6/ipv6_sockglue.c +47 -1
@@ -980,9 +980,55 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -case MCAST_MSFILTER :return compat_mc_setsockopt (sk, level, optname, optval, optlen, ipv6_setsockopt); +case MCAST_MSFILTER : + { +const int size0 = offsetof(struct compat_group_filter , gf_slist); +struct compat_group_filter *gf32; +void *p; +int n; + +if (optlen < size0) +return -EINVAL ; +if (optlen > sysctl_optmem_max -4 ) +return -ENOBUFS ; + + p =kmalloc (optlen +4 ,GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + gf32 = p +4 ;/* we want ->gf_group and ->gf_slist aligned */ +if (copy_from_user (gf32, optval, optlen)) { + err = -EFAULT ; + goto mc_msf_out; + } + + n = gf32->gf_numsrc; +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >=0x1ffffffU || + n > sysctl_mld_max_msf) { + err = -ENOBUFS ; + goto mc_msf_out; + } + if (offsetof(struct compat_group_filter, gf_slist[n]) > optlen) { + err = -EINVAL ; + goto mc_msf_out; + } + +rtnl_lock (); +lock_sock (sk); + err =ip6_mc_msfilter (sk, &(struct group_filter ){ + .gf_interface = gf32->gf_interface, + .gf_group = gf32->gf_group, + .gf_fmode = gf32->gf_fmode, + .gf_numsrc = gf32->gf_numsrc}, gf32->gf_slist); +release_sock (sk); +rtnl_unlock (); +mc_msf_out: +kfree (p); +return err; + } } err =do_ipv6_setsockopt (sk, level, optname, optval, optlen);
Signature · 1 line
2.11.0
PATCH 5/19 set_mcast_msfilter(): take the guts of setsockopt(MCAST_MSFILTER) into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv4/ip_sockglue.c | 73 +++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 33 deletions(-)
net/ipv4/ip_sockglue.c +40 -33
@@ -587,6 +587,43 @@ static bool setsockopt_needs_rtnl(int optname)return false; } +static int set_mcast_msfilter (struct sock *sk,int ifindex, +int numsrc,int fmode, +struct sockaddr_storage *group, +struct sockaddr_storage *list) +{ +int msize =IP_MSFILTER_SIZE (numsrc); +struct ip_msfilter *msf; +struct sockaddr_in *psin; +int err, i; + + msf =kmalloc (msize,GFP_KERNEL ); +if (!msf) +return -ENOBUFS ; + + psin = (struct sockaddr_in *)group; +if (psin->sin_family !=AF_INET ) + goto Eaddrnotavail; + msf->imsf_multiaddr = psin->sin_addr.s_addr; + msf->imsf_interface =0 ; + msf->imsf_fmode = fmode; + msf->imsf_numsrc = numsrc; +for (i =0 ; i < numsrc; ++i) { + psin = (struct sockaddr_in *)&list[i]; + +if (psin->sin_family !=AF_INET ) + goto Eaddrnotavail; + msf->imsf_slist[i] = psin->sin_addr.s_addr; + } + err =ip_mc_msfilter (sk, msf, ifindex); +kfree (msf); +return err; + +Eaddrnotavail: +kfree (msf); +return -EADDRNOTAVAIL ; +} +static int do_ip_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1079,10 +1116,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, }case MCAST_MSFILTER : { -struct sockaddr_in *psin; -struct ip_msfilter *msf =NULL ;struct group_filter *gsf =NULL ; -int msize, i, ifindex;if (optlen <GROUP_FILTER_SIZE (0 )) goto e_inval;
@@ -1095,7 +1129,6 @@ static int do_ip_setsockopt(struct sock *sk, int level, err =PTR_ERR (gsf);break ; } -/* numsrc >= (4G-140)/128 overflow in 32 bits */ if (gsf->gf_numsrc >=0x1ffffff || gsf->gf_numsrc > net->ipv4.sysctl_igmp_max_msf) {
@@ -1106,36 +1139,10 @@ static int do_ip_setsockopt(struct sock *sk, int level, err = -EINVAL ; goto mc_msf_out; } - msize =IP_MSFILTER_SIZE (gsf->gf_numsrc); - msf =kmalloc (msize,GFP_KERNEL ); -if (!msf) { - err = -ENOBUFS ; - goto mc_msf_out; - } - ifindex = gsf->gf_interface; - psin = (struct sockaddr_in *)&gsf->gf_group; -if (psin->sin_family !=AF_INET ) { - err = -EADDRNOTAVAIL ; - goto mc_msf_out; - } - msf->imsf_multiaddr = psin->sin_addr.s_addr; - msf->imsf_interface =0 ; - msf->imsf_fmode = gsf->gf_fmode; - msf->imsf_numsrc = gsf->gf_numsrc; - err = -EADDRNOTAVAIL ; -for (i =0 ; i < gsf->gf_numsrc; ++i) { - psin = (struct sockaddr_in *)&gsf->gf_slist[i]; - -if (psin->sin_family !=AF_INET ) - goto mc_msf_out; - msf->imsf_slist[i] = psin->sin_addr.s_addr; - } -kfree (gsf); - gsf =NULL ; - - err =ip_mc_msfilter (sk, msf, ifindex); + err =set_mcast_msfilter (sk, gsf->gf_interface, + gsf->gf_numsrc, gsf->gf_fmode, + &gsf->gf_group, gsf->gf_slist); mc_msf_out: -kfree (msf);kfree (gsf);break ; }
Signature · 1 line
2.11.0
PATCH 19/19 atm: switch do_atmif_sioc() to direct use of atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-)
net/atm/ioctl.c +4 -21
@@ -286,30 +286,13 @@ static int do_atm_iobuf(struct socket *sock, unsigned int cmd,static int do_atmif_sioc (struct socket *sock,unsigned int cmd,unsigned long arg) { -struct atmif_sioc __user *sioc; -struct compat_atmif_sioc __user *sioc32; +struct compat_atmif_sioc __user *sioc32 =compat_ptr (arg); +int number;u32 data; -void __user *datap; -int err; - sioc =compat_alloc_user_space (sizeof (*sioc)); - sioc32 =compat_ptr (arg); - -if (copy_in_user (&sioc->number, &sioc32->number,2 *sizeof (int )) || -get_user (data, &sioc32->arg)) -return -EFAULT ; - datap =compat_ptr (data); -if (put_user (datap, &sioc->arg)) +if (get_user (data, &sioc32->arg) ||get_user (number, &sioc32->number))return -EFAULT ; - - err =do_vcc_ioctl (sock, cmd, (unsigned long ) sioc,0 ); - -if (!err) { -if (copy_in_user (&sioc32->length, &sioc->length, -sizeof (int ))) - err = -EFAULT ; - } -return err; +return atm_dev_ioctl (cmd,compat_ptr (data), &sioc32->length, number,0 ); } static int do_atm_ioctl(struct socket *sock, unsigned int cmd32,
Signature · 1 line
2.11.0
PATCH 18/19 atm: lift copyin from atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 25 ++++++++++++++++++++++++- net/atm/resources.c | 35 +++++------------------------------ net/atm/resources.h | 4 ++-- 3 files changed, 31 insertions(+), 33 deletions(-)
net/atm/ioctl.c +24 -1
@@ -182,7 +182,30 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, } error =atm_getnames (buf, len); }else { - error =atm_dev_ioctl (cmd, argp, compat); +int number; + +if (IS_ENABLED (CONFIG_COMPAT ) && compat) { +#ifdef CONFIG_COMPAT +struct compat_atmif_sioc __user *csioc = argp; +compat_uptr_t carg; + + len = &csioc->length; +if (get_user (carg, &csioc->arg)) +return -EFAULT ; + buf =compat_ptr (carg); +if (get_user (number, &csioc->number)) +return -EFAULT ; +#endif + }else { +struct atmif_sioc __user *sioc = argp; + + len = &sioc->length; +if (get_user (buf, &sioc->arg)) +return -EFAULT ; +if (get_user (number, &sioc->number)) +return -EFAULT ; + } + error =atm_dev_ioctl (cmd, buf, len, number, compat); } done:
net/atm/resources.c +5 -30
@@ -227,39 +227,14 @@ int atm_getnames(void __user *buf, int __user *iobuf_len)return error; } -int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat) +int atm_dev_ioctl (unsigned int cmd,void __user *buf,int __user *sioc_len, +int number,int compat) { -void __user *buf; -int error, len, number, size =0 ; +int error, len, size =0 ;struct atm_dev *dev; -int __user *sioc_len; -if (IS_ENABLED (CONFIG_COMPAT ) && compat) { -#ifdef CONFIG_COMPAT -struct compat_atmif_sioc __user *csioc = arg; -compat_uptr_t carg; - - sioc_len = &csioc->length; -if (get_user (carg, &csioc->arg)) -return -EFAULT ; - buf =compat_ptr (carg); - -if (get_user (len, &csioc->length)) -return -EFAULT ; -if (get_user (number, &csioc->number)) -return -EFAULT ; -#endif - }else { -struct atmif_sioc __user *sioc = arg; - - sioc_len = &sioc->length; -if (get_user (buf, &sioc->arg)) -return -EFAULT ; -if (get_user (len, &sioc->length)) -return -EFAULT ; -if (get_user (number, &sioc->number)) -return -EFAULT ; - } +if (get_user (len, sioc_len)) +return -EFAULT ; dev =try_then_request_module (atm_dev_lookup (number),"atm-device-%d" , number);
net/atm/resources.h +2 -2
@@ -15,8 +15,8 @@ extern struct list_head atm_devs;extern struct mutex atm_dev_mutex;int atm_getnames (void __user *buf,int __user *iobuf_len); -int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat); - +int atm_dev_ioctl (unsigned int cmd,void __user *buf,int __user *sioc_len, +int number,int compat);#ifdef CONFIG_PROC_FS
Signature · 1 line
2.11.0
PATCH 15/19 atm: separate ATM_GETNAMES handling from the rest of atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
atm_dev_ioctl() does copyin in two different ways - one for ATM_GETNAMES, another for everything else. Start with separating the former into a new helper (atm_getnames()). The next step will be to lift the copyin into the callers.
--- net/atm/ioctl.c | 6 +++- net/atm/resources.c | 88 +++++++++++++++++++++++++++-------------------------- net/atm/resources.h | 1 + 3 files changed, 51 insertions(+), 44 deletions(-)
net/atm/ioctl.c +5 -1
@@ -162,7 +162,11 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,if (error != -ENOIOCTLCMD ) goto done; - error =atm_dev_ioctl (cmd, argp, compat); +if (cmd ==ATM_GETNAMES ) { + error =atm_getnames (argp, compat); + }else { + error =atm_dev_ioctl (cmd, argp, compat); + } done:return error;
net/atm/resources.c +45 -43
106 lines not on this page · raw message
net/atm/resources.h +1 -0
@@ -14,6 +14,7 @@extern struct list_head atm_devs;extern struct mutex atm_dev_mutex; +int atm_getnames (void __user *arg,int compat);int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat);
Signature · 1 line
2.11.0
PATCH 12/19 handle the group_source_req options directly
In reply to Al ViroFrom: Al Viro <[email protected]>
Native ->setsockopt() handling of these options (MCAST_..._SOURCE_GROUP and MCAST_{,UN}BLOCK_SOURCE) consists of copyin + call of a helper that does the actual work. The only change needed for ->compat_setsockopt() is a slightly different copyin - the helpers can be reused as-is.
--- net/ipv4/ip_sockglue.c | 23 +++++++++++++++++++++-- net/ipv6/ipv6_sockglue.c | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-)
net/ipv4/ip_sockglue.c +21 -2
@@ -1322,8 +1322,27 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -return compat_mc_setsockopt (sk, level, optname, optval, optlen, - ip_setsockopt); + { +struct compat_group_source_req __user *gsr32 = (void __user *)optval; +struct group_source_req greqs; + +if (optlen !=sizeof (struct compat_group_source_req )) +return -EINVAL ; + +if (get_user (greqs.gsr_interface, &gsr32->gsr_interface) || +copy_from_user (&greqs.gsr_group, &gsr32->gsr_group, +sizeof (greqs.gsr_group)) || +copy_from_user (&greqs.gsr_source, &gsr32->gsr_source, +sizeof (greqs.gsr_source))) +return -EFAULT ; + +rtnl_lock (); +lock_sock (sk); + err =do_mcast_group_source (sk, optname, &greqs); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_MSFILTER : {const int size0 = offsetof(struct compat_group_filter , gf_slist);
net/ipv6/ipv6_sockglue.c +21 -2
@@ -1015,8 +1015,27 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -return compat_mc_setsockopt (sk, level, optname, optval, optlen, - ipv6_setsockopt); + { +struct compat_group_source_req __user *gsr32 = (void __user *)optval; +struct group_source_req greqs; + +if (optlen <sizeof (struct compat_group_source_req )) +return -EINVAL ; + +if (get_user (greqs.gsr_interface, &gsr32->gsr_interface) || +copy_from_user (&greqs.gsr_group, &gsr32->gsr_group, +sizeof (greqs.gsr_group)) || +copy_from_user (&greqs.gsr_source, &gsr32->gsr_source, +sizeof (greqs.gsr_source))) +return -EFAULT ; + +rtnl_lock (); +lock_sock (sk); + err =do_ipv6_mcast_group_source (sk, optname, &greqs); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_MSFILTER : {const int size0 = offsetof(struct compat_group_filter , gf_slist);
Signature · 1 line
2.11.0
PATCH 13/19 get rid of compat_mc_setsockopt()
In reply to Al ViroFrom: Al Viro <[email protected]>
not used anymore
--- include/net/compat.h | 4 --- net/compat.c | 90 ---------------------------------------------------- 2 files changed, 94 deletions(-)
include/net/compat.h +0 -4
@@ -49,10 +49,6 @@ int put_cmsg_compat(struct msghdr*, int, int, int, void *);int cmsghdr_from_user_compat_to_kern (struct msghdr *,struct sock *,unsigned char *,int ); -int compat_mc_setsockopt (struct sock *,int ,int ,char __user *,unsigned int , -int (*)(struct sock *,int ,int ,char __user *, -unsigned int )); -struct compat_group_req {__u32 gr_interface;struct __kernel_sockaddr_storage gr_group
net/compat.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 14/19 batadv_socket_read(): get rid of pointless access_ok()
In reply to Al ViroFrom: Al Viro <[email protected]>
address is passed only to copy_to_user()
--- net/batman-adv/icmp_socket.c | 3 --- 1 file changed, 3 deletions(-)
net/batman-adv/icmp_socket.c +0 -3
@@ -135,9 +135,6 @@ static ssize_t batadv_socket_read(struct file *file, char __user *buf,if (!buf || count <sizeof (struct batadv_icmp_packet ))return -EINVAL ; -if (!access_ok (buf, count)) -return -EFAULT ; - error =wait_event_interruptible (socket_client->queue_wait, socket_client->queue_len);
Signature · 1 line
2.11.0
PATCH 9/19 ipv[46]: do compat setsockopt for MCAST_{JOIN,LEAVE}_GROUP directly
In reply to Al ViroFrom: Al Viro <[email protected]>
direct parallel to the way these two are handled in the native ->setsockopt() instances - the helpers that do the real work are already separated and can be reused as-is in this case.
--- net/ipv4/ip_sockglue.c | 31 +++++++++++++++++++++++++++++++ net/ipv6/ipv6_sockglue.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
net/ipv4/ip_sockglue.c +31 -0
@@ -1282,6 +1282,37 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,switch (optname) {case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP : + { +struct compat_group_req __user *gr32 = (void __user *)optval; +struct group_req greq; +struct sockaddr_in *psin = (struct sockaddr_in *)&greq.gr_group; +struct ip_mreqn mreq; + +if (optlen <sizeof (struct compat_group_req )) +return -EINVAL ; + +if (get_user (greq.gr_interface, &gr32->gr_interface) || +copy_from_user (&greq.gr_group, &gr32->gr_group, +sizeof (greq.gr_group))) +return -EFAULT ; + +if (psin->sin_family !=AF_INET ) +return -EINVAL ; + +memset (&mreq,0 ,sizeof (mreq)); + mreq.imr_multiaddr = psin->sin_addr; + mreq.imr_ifindex = greq.gr_interface; + +rtnl_lock (); +lock_sock (sk); +if (optname ==MCAST_JOIN_GROUP ) + err =ip_mc_join_group (sk, &mreq); +else + err =ip_mc_leave_group (sk, &mreq); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :
net/ipv6/ipv6_sockglue.c +28 -0
@@ -976,6 +976,34 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,switch (optname) {case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP : + { +struct compat_group_req __user *gr32 = (void __user *)optval; +struct group_req greq; +struct sockaddr_in6 *psin6 = (struct sockaddr_in6 *)&greq.gr_group; + +if (optlen <sizeof (struct compat_group_req )) +return -EINVAL ; + +if (get_user (greq.gr_interface, &gr32->gr_interface) || +copy_from_user (&greq.gr_group, &gr32->gr_group, +sizeof (greq.gr_group))) +return -EFAULT ; + +if (greq.gr_group.ss_family !=AF_INET6 ) +return -EADDRNOTAVAIL ; + +rtnl_lock (); +lock_sock (sk); +if (optname ==MCAST_JOIN_GROUP ) + err =ipv6_sock_mc_join (sk, greq.gr_interface, + &psin6->sin6_addr); +else + err =ipv6_sock_mc_drop (sk, greq.gr_interface, + &psin6->sin6_addr); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :
Signature · 1 line
2.11.0
PATCH 11/19 ipv6: take handling of group_source_req options into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv6/ipv6_sockglue.c | 65 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-)
net/ipv6/ipv6_sockglue.c +36 -29
@@ -136,6 +136,41 @@ static bool setsockopt_needs_rtnl(int optname)return false; } +static int do_ipv6_mcast_group_source (struct sock *sk,int optname, +struct group_source_req *greqs) +{ +int omode, add; + +if (greqs->gsr_group.ss_family !=AF_INET6 || + greqs->gsr_source.ss_family !=AF_INET6 ) +return -EADDRNOTAVAIL ; + +if (optname ==MCAST_BLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =1 ; + }else if (optname ==MCAST_UNBLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =0 ; + }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { +struct sockaddr_in6 *psin6; +int retv; + + psin6 = (struct sockaddr_in6 *)&greqs->gsr_group; + retv =ipv6_sock_mc_join_ssm (sk, greqs->gsr_interface, + &psin6->sin6_addr, +MCAST_INCLUDE ); +/* prior join w/ different source is ok */ +if (retv && retv != -EADDRINUSE ) +return retv; + omode =MCAST_INCLUDE ; + add =1 ; + }else /* MCAST_LEAVE_SOURCE_GROUP */ { + omode =MCAST_INCLUDE ; + add =0 ; + } +return ip6_mc_source (add, omode, sk, greqs); +} +static int do_ipv6_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -715,7 +750,6 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_UNBLOCK_SOURCE : {struct group_source_req greqs; -int omode, add;if (optlen <sizeof (struct group_source_req )) goto e_inval;
@@ -723,34 +757,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv = -EFAULT ;break ; } -if (greqs.gsr_group.ss_family !=AF_INET6 || - greqs.gsr_source.ss_family !=AF_INET6 ) { - retv = -EADDRNOTAVAIL ; -break ; - } -if (optname ==MCAST_BLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =1 ; - }else if (optname ==MCAST_UNBLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =0 ; - }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { -struct sockaddr_in6 *psin6; - - psin6 = (struct sockaddr_in6 *)&greqs.gsr_group; - retv =ipv6_sock_mc_join_ssm (sk, greqs.gsr_interface, - &psin6->sin6_addr, -MCAST_INCLUDE ); -/* prior join w/ different source is ok */ -if (retv && retv != -EADDRINUSE ) -break ; - omode =MCAST_INCLUDE ; - add =1 ; - }else /* MCAST_LEAVE_SOURCE_GROUP */ { - omode =MCAST_INCLUDE ; - add =0 ; - } - retv =ip6_mc_source (add, omode, sk, &greqs); + retv =do_ipv6_mcast_group_source (sk, optname, &greqs);break ; }case MCAST_MSFILTER :
Signature · 1 line
2.11.0
PATCH 10/19 ipv4: take handling of group_source_req options into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv4/ip_sockglue.c | 83 ++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 39 deletions(-)
net/ipv4/ip_sockglue.c +44 -39
@@ -624,6 +624,49 @@ static int set_mcast_msfilter(struct sock *sk, int ifindex,return -EADDRNOTAVAIL ; } +static int do_mcast_group_source (struct sock *sk,int optname, +struct group_source_req *greqs) +{ +struct ip_mreq_source mreqs; +struct sockaddr_in *psin; +int omode, add, err; + +if (greqs->gsr_group.ss_family !=AF_INET || + greqs->gsr_source.ss_family !=AF_INET ) +return -EADDRNOTAVAIL ; + + psin = (struct sockaddr_in *)&greqs->gsr_group; + mreqs.imr_multiaddr = psin->sin_addr.s_addr; + psin = (struct sockaddr_in *)&greqs->gsr_source; + mreqs.imr_sourceaddr = psin->sin_addr.s_addr; + mreqs.imr_interface =0 ;/* use index for mc_source */ + +if (optname ==MCAST_BLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =1 ; + }else if (optname ==MCAST_UNBLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =0 ; + }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { +struct ip_mreqn mreq; + + psin = (struct sockaddr_in *)&greqs->gsr_group; + mreq.imr_multiaddr = psin->sin_addr; + mreq.imr_address.s_addr =0 ; + mreq.imr_ifindex = greqs->gsr_interface; + err =ip_mc_join_group_ssm (sk, &mreq,MCAST_INCLUDE ); +if (err && err != -EADDRINUSE ) +return err; + greqs->gsr_interface = mreq.imr_ifindex; + omode =MCAST_INCLUDE ; + add =1 ; + }else /* MCAST_LEAVE_SOURCE_GROUP */ { + omode =MCAST_INCLUDE ; + add =0 ; + } +return ip_mc_source (add, omode, sk, &mreqs, greqs->gsr_interface); +} +static int do_ip_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1066,9 +1109,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,case MCAST_UNBLOCK_SOURCE : {struct group_source_req greqs; -struct ip_mreq_source mreqs; -struct sockaddr_in *psin; -int omode, add;if (optlen !=sizeof (struct group_source_req )) goto e_inval;
@@ -1076,42 +1116,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, err = -EFAULT ;break ; } -if (greqs.gsr_group.ss_family !=AF_INET || - greqs.gsr_source.ss_family !=AF_INET ) { - err = -EADDRNOTAVAIL ; -break ; - } - psin = (struct sockaddr_in *)&greqs.gsr_group; - mreqs.imr_multiaddr = psin->sin_addr.s_addr; - psin = (struct sockaddr_in *)&greqs.gsr_source; - mreqs.imr_sourceaddr = psin->sin_addr.s_addr; - mreqs.imr_interface =0 ;/* use index for mc_source */ - -if (optname ==MCAST_BLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =1 ; - }else if (optname ==MCAST_UNBLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =0 ; - }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { -struct ip_mreqn mreq; - - psin = (struct sockaddr_in *)&greqs.gsr_group; - mreq.imr_multiaddr = psin->sin_addr; - mreq.imr_address.s_addr =0 ; - mreq.imr_ifindex = greqs.gsr_interface; - err =ip_mc_join_group_ssm (sk, &mreq,MCAST_INCLUDE ); -if (err && err != -EADDRINUSE ) -break ; - greqs.gsr_interface = mreq.imr_ifindex; - omode =MCAST_INCLUDE ; - add =1 ; - }else /* MCAST_LEAVE_SOURCE_GROUP */ { - omode =MCAST_INCLUDE ; - add =0 ; - } - err =ip_mc_source (add, omode, sk, &mreqs, - greqs.gsr_interface); + err =do_mcast_group_source (sk, optname, &greqs);break ; }case MCAST_MSFILTER :
Signature · 1 line
2.11.0
PATCH 7/19 ip6_mc_msfilter(): pass the address list separately
In reply to Al ViroFrom: Al Viro <[email protected]>
that way we'll be able to reuse it for compat case
--- include/net/ipv6.h | 3 ++- net/ipv6/ipv6_sockglue.c | 2 +- net/ipv6/mcast.c | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-)
include/net/ipv6.h +2 -1
@@ -1134,7 +1134,8 @@ struct group_filter;int ip6_mc_source (int add,int omode,struct sock *sk,struct group_source_req *pgsr); -int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf); +int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf, +struct sockaddr_storage *list);int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf,struct sockaddr_storage __user *p);
net/ipv6/ipv6_sockglue.c +1 -1
@@ -780,7 +780,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv = -EINVAL ;break ; } - retv =ip6_mc_msfilter (sk, gsf); + retv =ip6_mc_msfilter (sk, gsf, gsf->gf_slist);kfree (gsf);break ;
net/ipv6/mcast.c +4 -3
@@ -457,7 +457,8 @@ int ip6_mc_source(int add, int omode, struct sock *sk,return err; } -int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf) +int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf, +struct sockaddr_storage *list) {const struct in6_addr *group;struct ipv6_mc_socklist *pmc;
@@ -509,10 +510,10 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) goto done; } newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc; -for (i =0 ; i < newpsl->sl_count; ++i) { +for (i =0 ; i < newpsl->sl_count; ++i, ++list) {struct sockaddr_in6 *psin6; - psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i]; + psin6 = (struct sockaddr_in6 *)list; newpsl->sl_addr[i] = psin6->sin6_addr; } err = ip6_mc_add_src(idev, group, gsf->gf_fmode,
Signature · 1 line
2.11.0
PATCH 1/19 lift compat definitions of mcast [sg]etsockopt requests into net/compat.h
In reply to Al ViroFrom: Al Viro <[email protected]>
We want to get rid of compat_mc_[sg]etsockopt() and to have that stuff handled without compat_alloc_user_space(), extra copying through userland, etc. To do that we'll need ipv4 and ipv6 instances of ->compat_[sg]etsockopt() to manipulate the 32bit variants of mcast requests, so we need to move the definitions of those out of net/compat.c and into a public header.
This patch just does a mechanical move to include/net/compat.h
--- include/net/compat.h | 24 ++++++++++++++++++++++++ net/compat.c | 25 ------------------------- 2 files changed, 24 insertions(+), 25 deletions(-)
include/net/compat.h +24 -0
@@ -56,4 +56,28 @@ int compat_mc_getsockopt(struct sock *, int, int, char __user *, int __user *, int (*)(struct sock *, int, int, char __user *, int __user *)); +struct compat_group_req { +__u32 gr_interface; +struct __kernel_sockaddr_storage gr_group +__aligned(4) ; +} __packed; + +struct compat_group_source_req { +__u32 gsr_interface; +struct __kernel_sockaddr_storage gsr_group +__aligned(4) ; +struct __kernel_sockaddr_storage gsr_source +__aligned(4) ; +} __packed; + +struct compat_group_filter { +__u32 gf_interface; +struct __kernel_sockaddr_storage gf_group +__aligned(4) ; +__u32 gf_fmode; +__u32 gf_numsrc; +struct __kernel_sockaddr_storage gf_slist[1 ] +__aligned(4) ; +} __packed; +#endif /* NET_COMPAT_H */
net/compat.c +0 -25
@@ -447,34 +447,9 @@ COMPAT_SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,return __compat_sys_getsockopt (fd, level, optname, optval, optlen); } -struct compat_group_req { -__u32 gr_interface; -struct __kernel_sockaddr_storage gr_group -__aligned(4) ; -} __packed; - -struct compat_group_source_req { -__u32 gsr_interface; -struct __kernel_sockaddr_storage gsr_group -__aligned(4) ; -struct __kernel_sockaddr_storage gsr_source -__aligned(4) ; -} __packed; - -struct compat_group_filter { -__u32 gf_interface; -struct __kernel_sockaddr_storage gf_group -__aligned(4) ; -__u32 gf_fmode; -__u32 gf_numsrc; -struct __kernel_sockaddr_storage gf_slist[1 ] -__aligned(4) ; -} __packed; -#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \ sizeof(struct __kernel_sockaddr_storage)) -int compat_mc_setsockopt (struct sock *sock,int level,int optname,char __user *optval,unsigned int optlen,int (*setsockopt)(struct sock *,int ,int ,char __user *,unsigned int ))
Signature · 1 line
2.11.0
PATCH 6/19 ipv4: do compat setsockopt for MCAST_MSFILTER directly
From: Al Viro <[email protected]>
Parallel to what the native setsockopt() does, except that unlike the native setsockopt() we do not use memdup_user() - we want the sockaddr_storage fields properly aligned, so we allocate 4 bytes more and copy compat_group_filter at the offset 4, which yields the proper alignments.
--- net/ipv4/ip_sockglue.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
net/ipv4/ip_sockglue.c +47 -1
@@ -1286,9 +1286,55 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -case MCAST_MSFILTER :return compat_mc_setsockopt (sk, level, optname, optval, optlen, ip_setsockopt); +case MCAST_MSFILTER : + { +const int size0 = offsetof(struct compat_group_filter , gf_slist); +struct compat_group_filter *gf32; +void *p; +int n; + +if (optlen < size0) +return -EINVAL ; +if (optlen > sysctl_optmem_max -4 ) +return -ENOBUFS ; + + p =kmalloc (optlen +4 ,GFP_KERNEL ); +if (!p) +return -ENOMEM ; + gf32 = p +4 ;/* we want ->gf_group and ->gf_slist aligned */ +if (copy_from_user (gf32, optval, optlen)) { + err = -EFAULT ; + goto mc_msf_out; + } + + n = gf32->gf_numsrc; +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >=0x1ffffff ) { + err = -ENOBUFS ; + goto mc_msf_out; + } + if (offsetof(struct compat_group_filter, gf_slist[n]) > optlen) { + err = -EINVAL ; + goto mc_msf_out; + } + +rtnl_lock (); +lock_sock (sk); +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >sock_net (sk)->ipv4.sysctl_igmp_max_msf) + err = -ENOBUFS ; +else + err =set_mcast_msfilter (sk, gf32->gf_interface, + n, gf32->gf_fmode, + &gf32->gf_group, gf32->gf_slist); +release_sock (sk); +rtnl_unlock (); +mc_msf_out: +kfree (p); +return err; + } } err =do_ip_setsockopt (sk, level, optname, optval, optlen);
Signature · 1 line
2.11.0
PATCH 4/19 get rid of compat_mc_getsockopt()
In reply to Al ViroFrom: Al Viro <[email protected]>
now we can do MCAST_MSFILTER in compat ->getsockopt() without playing silly buggers with copying things back and forth. We can form a native struct group_filter (sans the variable-length tail) on stack, pass that + pointer to the tail of original request to the helper doing the bulk of the work, then do the rest of copyout - same as the native getsockopt() does.
--- include/net/compat.h | 3 -- net/compat.c | 79 ------------------------------------------------ net/ipv4/ip_sockglue.c | 44 +++++++++++++++++++++++++-- net/ipv6/ipv6_sockglue.c | 41 +++++++++++++++++++++++-- 4 files changed, 79 insertions(+), 88 deletions(-)
include/net/compat.h +0 -3
@@ -52,9 +52,6 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *, struct sock *,int compat_mc_setsockopt (struct sock *,int ,int ,char __user *,unsigned int ,int (*)(struct sock *,int ,int ,char __user *,unsigned int )); -int compat_mc_getsockopt (struct sock *,int ,int ,char __user *,int __user *, -int (*)(struct sock *,int ,int ,char __user *, -int __user *));struct compat_group_req {__u32 gr_interface;
net/compat.c +0 -79
85 lines not on this page · raw message
net/ipv4/ip_sockglue.c +41 -3
50 lines not on this page · raw message
net/ipv6/ipv6_sockglue.c +38 -3
47 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 3/19 ip*_mc_gsfget(): lift copyout of struct group_filter into callers
In reply to Al ViroFrom: Al Viro <[email protected]>
pass the userland pointer to the array in its tail, so that part gets copied out by our functions; copyout of everything else is done in the callers. Rationale: reuse for compat; the array is the same in native and compat, the layout of parts before it is different for compat.
--- include/linux/igmp.h | 2 +- include/net/ipv6.h | 2 +- net/ipv4/igmp.c | 18 +++++------------- net/ipv4/ip_sockglue.c | 19 ++++++++++++++----- net/ipv6/ipv6_sockglue.c | 18 ++++++++++++++---- net/ipv6/mcast.c | 10 +++------- 6 files changed, 38 insertions(+), 31 deletions(-)
include/linux/igmp.h +1 -1
@@ -123,7 +123,7 @@ extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);extern int ip_mc_msfget (struct sock *sk,struct ip_msfilter *msf,struct ip_msfilter __user *optval,int __user *optlen);extern int ip_mc_gsfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen); +struct sockaddr_storage __user *p);extern int ip_mc_sf_allow (struct sock *sk,__be32 local,__be32 rmt,int dif,int sdif);extern void ip_mc_init_dev (struct in_device *);
include/net/ipv6.h +1 -1
@@ -1136,7 +1136,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk, struct group_source_req *pgsr);int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf);int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen); +struct sockaddr_storage __user *p);#ifdef CONFIG_PROC_FS int ac6_proc_init (struct net *net);
net/ipv4/igmp.c +5 -13
@@ -2565,9 +2565,9 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, }int ip_mc_gsfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen) +struct sockaddr_storage __user *p) { -int err, i, count, copycount; +int i, count, copycount;struct sockaddr_in *psin;__be32 addr;struct ip_mc_socklist *pmc;
@@ -2583,37 +2583,29 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,if (!ipv4_is_multicast (addr))return -EINVAL ; - err = -EADDRNOTAVAIL ; -for_each_pmc_rtnl (inet, pmc) {if (pmc->multi.imr_multiaddr.s_addr == addr && pmc->multi.imr_ifindex == gsf->gf_interface)break ; }if (!pmc)/* must have a prior join */ - goto done; +return -EADDRNOTAVAIL ; gsf->gf_fmode = pmc->sfmode; psl =rtnl_dereference (pmc->sflist); count = psl ? psl->sl_count :0 ; copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; gsf->gf_numsrc = count; -if (put_user (GROUP_FILTER_SIZE (copycount), optlen) || -copy_to_user (optval, gsf,GROUP_FILTER_SIZE (0 ))) { -return -EFAULT ; - } -for (i =0 ; i < copycount; i++) { +for (i =0 ; i < copycount; i++, p++) {struct sockaddr_storage ss; psin = (struct sockaddr_in *)&ss;memset (&ss,0 ,sizeof (ss)); psin->sin_family =AF_INET ; psin->sin_addr.s_addr = psl->sl_addr[i]; -if (copy_to_user (&optval->gf_slist[i], &ss,sizeof (ss))) +if (copy_to_user (p, &ss,sizeof (ss)))return -EFAULT ; }return 0 ; -done: -return err; }/*
net/ipv4/ip_sockglue.c +14 -5
@@ -1473,19 +1473,28 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname, }case MCAST_MSFILTER : { +struct group_filter __user *p = (void __user *)optval;struct group_filter gsf; +const int size0 = offsetof(struct group_filter , gf_slist); +int num; -if (len <GROUP_FILTER_SIZE (0 )) { +if (len < size0) { err = -EINVAL ; goto out; } -if (copy_from_user (&gsf, optval,GROUP_FILTER_SIZE (0 ))) { +if (copy_from_user (&gsf, p, size0)) { err = -EFAULT ; goto out; } - err =ip_mc_gsfget (sk, &gsf, - (struct group_filter __user *)optval, - optlen); + num = gsf.gf_numsrc; + err =ip_mc_gsfget (sk, &gsf, p->gf_slist); +if (err) + goto out; +if (gsf.gf_numsrc < num) + num = gsf.gf_numsrc; +if (put_user (GROUP_FILTER_SIZE (num), optlen) || +copy_to_user (p, &gsf, size0)) + err = -EFAULT ; goto out; }case IP_MULTICAST_ALL :
net/ipv6/ipv6_sockglue.c +14 -4
@@ -1056,18 +1056,28 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,break ;case MCAST_MSFILTER : { +struct group_filter __user *p = (void __user *)optval;struct group_filter gsf; +const int size0 = offsetof(struct group_filter , gf_slist); +int num;int err; -if (len <GROUP_FILTER_SIZE (0 )) +if (len < size0)return -EINVAL ; -if (copy_from_user (&gsf, optval,GROUP_FILTER_SIZE (0 ))) +if (copy_from_user (&gsf, p, size0))return -EFAULT ;if (gsf.gf_group.ss_family !=AF_INET6 )return -EADDRNOTAVAIL ; + num = gsf.gf_numsrc;lock_sock (sk); - err =ip6_mc_msfget (sk, &gsf, - (struct group_filter __user *)optval, optlen); + err =ip6_mc_msfget (sk, &gsf, p->gf_slist); +if (!err) { +if (num > gsf.gf_numsrc) + num = gsf.gf_numsrc; +if (put_user (GROUP_FILTER_SIZE (num), optlen) || +copy_to_user (p, &gsf, size0)) + err = -EFAULT ; + }release_sock (sk);return err; }
net/ipv6/mcast.c +3 -7
@@ -547,7 +547,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) }int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen) +struct sockaddr_storage *p) {int err, i, count, copycount;const struct in6_addr *group;
@@ -592,14 +592,10 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; gsf->gf_numsrc = count; -if (put_user (GROUP_FILTER_SIZE (copycount), optlen) || -copy_to_user (optval, gsf,GROUP_FILTER_SIZE (0 ))) { -return -EFAULT ; - }/* changes to psl require the socket lock, and a write lock * on pmc->sflock. We have the socket lock so reading here is safe. */ -for (i =0 ; i < copycount; i++) { +for (i =0 ; i < copycount; i++, p++) {struct sockaddr_in6 *psin6;struct sockaddr_storage ss;
@@ -607,7 +603,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,memset (&ss,0 ,sizeof (ss)); psin6->sin6_family =AF_INET6 ; psin6->sin6_addr = psl->sl_addr[i]; -if (copy_to_user (&optval->gf_slist[i], &ss,sizeof (ss))) +if (copy_to_user (p, &ss,sizeof (ss)))return -EFAULT ; }return 0 ;
Signature · 1 line
2.11.0
From: Al Viro <[email protected]>
Date: Mon, 11 May 2020 05:43:28 +0100
Quoted 9 lines
Assorted uaccess-related work in
net/*. First, there's
getting rid ofcompat_alloc_user_space()mess inMCAST_... [gs]etsockopt() - no need to play with copying to/from temporary object on userland stack, etc., when ->compat_[sg]etsockopt() instances in question can easly do everything without that. That's the first 13 patches. Then there's a trivial bit innet/batman-adv(completely unrelated to everything else) and finally getting the atm compat ioctls into simpler shape.
Quoted 3 lines
Please, review and comment. Individual patches in followups,
the entire branch (on top of current net/master) is ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git#uaccess.net
I have no problems with this series:
Quoted 12 lines · David Miller
From: Al Viro <[email protected]>
Date: Mon, 11 May 2020 05:43:28 +0100Quoted 9 lines
Assorted uaccess-related work in
net/*. First, there's
getting rid ofcompat_alloc_user_space()mess inMCAST_... [gs]etsockopt() - no need to play with copying to/from temporary object on userland stack, etc., when ->compat_[sg]etsockopt() instances in question can easly do everything without that. That's the first 13 patches. Then there's a trivial bit innet/batman-adv(completely unrelated to everything else) and finally getting the atm compat ioctls into simpler shape.
Quoted 7 lines
Quoted 3 lines
Please, review and comment. Individual patches in followups,
the entire branch (on top of current net/master) is ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git#uaccess.netI have no problems with this series:
Acked-by David S. Miller <[email protected]>
OK, rebased on top of current net/master (no conflicts) and pushed out to the same branch. Patches (for net-next) in followups
PATCH 2/19 compat_ip{,v6}_setsockopt(): enumerate MCAST_... options explicitly
In reply to Al ViroFrom: Al Viro <[email protected]>
We want to check if optname is among the MCAST_... ones; do that as an explicit switch.
--- net/ipv4/ip_sockglue.c | 10 +++++++++- net/ipv6/ipv6_sockglue.c | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-)
net/ipv4/ip_sockglue.c +9 -1
@@ -1272,9 +1272,17 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,if (level !=SOL_IP )return -ENOPROTOOPT ; -if (optname >=MCAST_JOIN_GROUP && optname <=MCAST_MSFILTER ) +switch (optname) { +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case 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
net/ipv6/ipv6_sockglue.c +9 -1
@@ -973,9 +973,17 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,if (level !=SOL_IPV6 )return -ENOPROTOOPT ; -if (optname >=MCAST_JOIN_GROUP && optname <=MCAST_MSFILTER ) +switch (optname) { +case MCAST_JOIN_GROUP : +case MCAST_LEAVE_GROUP : +case MCAST_JOIN_SOURCE_GROUP : +case MCAST_LEAVE_SOURCE_GROUP : +case MCAST_BLOCK_SOURCE : +case MCAST_UNBLOCK_SOURCE : +case 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
Signature · 1 line
2.11.0
PATCH 7/19 ip6_mc_msfilter(): pass the address list separately
In reply to Al ViroFrom: Al Viro <[email protected]>
that way we'll be able to reuse it for compat case
--- include/net/ipv6.h | 3 ++- net/ipv6/ipv6_sockglue.c | 2 +- net/ipv6/mcast.c | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-)
include/net/ipv6.h +2 -1
@@ -1136,7 +1136,8 @@ struct group_filter;int ip6_mc_source (int add,int omode,struct sock *sk,struct group_source_req *pgsr); -int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf); +int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf, +struct sockaddr_storage *list);int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf,struct sockaddr_storage __user *p);
net/ipv6/ipv6_sockglue.c +1 -1
@@ -780,7 +780,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv = -EINVAL ;break ; } - retv =ip6_mc_msfilter (sk, gsf); + retv =ip6_mc_msfilter (sk, gsf, gsf->gf_slist);kfree (gsf);break ;
net/ipv6/mcast.c +4 -3
@@ -457,7 +457,8 @@ int ip6_mc_source(int add, int omode, struct sock *sk,return err; } -int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf) +int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf, +struct sockaddr_storage *list) {const struct in6_addr *group;struct ipv6_mc_socklist *pmc;
@@ -509,10 +510,10 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) goto done; } newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc; -for (i =0 ; i < newpsl->sl_count; ++i) { +for (i =0 ; i < newpsl->sl_count; ++i, ++list) {struct sockaddr_in6 *psin6; - psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i]; + psin6 = (struct sockaddr_in6 *)list; newpsl->sl_addr[i] = psin6->sin6_addr; } err = ip6_mc_add_src(idev, group, gsf->gf_fmode,
Signature · 1 line
2.11.0
PATCH 9/19 ipv[46]: do compat setsockopt for MCAST_{JOIN,LEAVE}_GROUP directly
In reply to Al ViroFrom: Al Viro <[email protected]>
direct parallel to the way these two are handled in the native ->setsockopt() instances - the helpers that do the real work are already separated and can be reused as-is in this case.
--- net/ipv4/ip_sockglue.c | 31 +++++++++++++++++++++++++++++++ net/ipv6/ipv6_sockglue.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
net/ipv4/ip_sockglue.c +31 -0
@@ -1282,6 +1282,37 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,switch (optname) {case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP : + { +struct compat_group_req __user *gr32 = (void __user *)optval; +struct group_req greq; +struct sockaddr_in *psin = (struct sockaddr_in *)&greq.gr_group; +struct ip_mreqn mreq; + +if (optlen <sizeof (struct compat_group_req )) +return -EINVAL ; + +if (get_user (greq.gr_interface, &gr32->gr_interface) || +copy_from_user (&greq.gr_group, &gr32->gr_group, +sizeof (greq.gr_group))) +return -EFAULT ; + +if (psin->sin_family !=AF_INET ) +return -EINVAL ; + +memset (&mreq,0 ,sizeof (mreq)); + mreq.imr_multiaddr = psin->sin_addr; + mreq.imr_ifindex = greq.gr_interface; + +rtnl_lock (); +lock_sock (sk); +if (optname ==MCAST_JOIN_GROUP ) + err =ip_mc_join_group (sk, &mreq); +else + err =ip_mc_leave_group (sk, &mreq); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :
net/ipv6/ipv6_sockglue.c +28 -0
@@ -976,6 +976,34 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,switch (optname) {case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP : + { +struct compat_group_req __user *gr32 = (void __user *)optval; +struct group_req greq; +struct sockaddr_in6 *psin6 = (struct sockaddr_in6 *)&greq.gr_group; + +if (optlen <sizeof (struct compat_group_req )) +return -EINVAL ; + +if (get_user (greq.gr_interface, &gr32->gr_interface) || +copy_from_user (&greq.gr_group, &gr32->gr_group, +sizeof (greq.gr_group))) +return -EFAULT ; + +if (greq.gr_group.ss_family !=AF_INET6 ) +return -EADDRNOTAVAIL ; + +rtnl_lock (); +lock_sock (sk); +if (optname ==MCAST_JOIN_GROUP ) + err =ipv6_sock_mc_join (sk, greq.gr_interface, + &psin6->sin6_addr); +else + err =ipv6_sock_mc_drop (sk, greq.gr_interface, + &psin6->sin6_addr); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :
Signature · 1 line
2.11.0
PATCH 18/19 atm: lift copyin from atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 25 ++++++++++++++++++++++++- net/atm/resources.c | 35 +++++------------------------------ net/atm/resources.h | 4 ++-- 3 files changed, 31 insertions(+), 33 deletions(-)
net/atm/ioctl.c +24 -1
@@ -182,7 +182,30 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, } error =atm_getnames (buf, len); }else { - error =atm_dev_ioctl (cmd, argp, compat); +int number; + +if (IS_ENABLED (CONFIG_COMPAT ) && compat) { +#ifdef CONFIG_COMPAT +struct compat_atmif_sioc __user *csioc = argp; +compat_uptr_t carg; + + len = &csioc->length; +if (get_user (carg, &csioc->arg)) +return -EFAULT ; + buf =compat_ptr (carg); +if (get_user (number, &csioc->number)) +return -EFAULT ; +#endif + }else { +struct atmif_sioc __user *sioc = argp; + + len = &sioc->length; +if (get_user (buf, &sioc->arg)) +return -EFAULT ; +if (get_user (number, &sioc->number)) +return -EFAULT ; + } + error =atm_dev_ioctl (cmd, buf, len, number, compat); } done:
net/atm/resources.c +5 -30
@@ -227,39 +227,14 @@ int atm_getnames(void __user *buf, int __user *iobuf_len)return error; } -int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat) +int atm_dev_ioctl (unsigned int cmd,void __user *buf,int __user *sioc_len, +int number,int compat) { -void __user *buf; -int error, len, number, size =0 ; +int error, len, size =0 ;struct atm_dev *dev; -int __user *sioc_len; -if (IS_ENABLED (CONFIG_COMPAT ) && compat) { -#ifdef CONFIG_COMPAT -struct compat_atmif_sioc __user *csioc = arg; -compat_uptr_t carg; - - sioc_len = &csioc->length; -if (get_user (carg, &csioc->arg)) -return -EFAULT ; - buf =compat_ptr (carg); - -if (get_user (len, &csioc->length)) -return -EFAULT ; -if (get_user (number, &csioc->number)) -return -EFAULT ; -#endif - }else { -struct atmif_sioc __user *sioc = arg; - - sioc_len = &sioc->length; -if (get_user (buf, &sioc->arg)) -return -EFAULT ; -if (get_user (len, &sioc->length)) -return -EFAULT ; -if (get_user (number, &sioc->number)) -return -EFAULT ; - } +if (get_user (len, sioc_len)) +return -EFAULT ; dev =try_then_request_module (atm_dev_lookup (number),"atm-device-%d" , number);
net/atm/resources.h +2 -2
@@ -15,8 +15,8 @@ extern struct list_head atm_devs;extern struct mutex atm_dev_mutex;int atm_getnames (void __user *buf,int __user *iobuf_len); -int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat); - +int atm_dev_ioctl (unsigned int cmd,void __user *buf,int __user *sioc_len, +int number,int compat);#ifdef CONFIG_PROC_FS
Signature · 1 line
2.11.0
PATCH 19/19 atm: switch do_atmif_sioc() to direct use of atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-)
net/atm/ioctl.c +4 -21
@@ -286,30 +286,13 @@ static int do_atm_iobuf(struct socket *sock, unsigned int cmd,static int do_atmif_sioc (struct socket *sock,unsigned int cmd,unsigned long arg) { -struct atmif_sioc __user *sioc; -struct compat_atmif_sioc __user *sioc32; +struct compat_atmif_sioc __user *sioc32 =compat_ptr (arg); +int number;u32 data; -void __user *datap; -int err; - sioc =compat_alloc_user_space (sizeof (*sioc)); - sioc32 =compat_ptr (arg); - -if (copy_in_user (&sioc->number, &sioc32->number,2 *sizeof (int )) || -get_user (data, &sioc32->arg)) -return -EFAULT ; - datap =compat_ptr (data); -if (put_user (datap, &sioc->arg)) +if (get_user (data, &sioc32->arg) ||get_user (number, &sioc32->number))return -EFAULT ; - - err =do_vcc_ioctl (sock, cmd, (unsigned long ) sioc,0 ); - -if (!err) { -if (copy_in_user (&sioc32->length, &sioc->length, -sizeof (int ))) - err = -EFAULT ; - } -return err; +return atm_dev_ioctl (cmd,compat_ptr (data), &sioc32->length, number,0 ); } static int do_atm_ioctl(struct socket *sock, unsigned int cmd32,
Signature · 1 line
2.11.0
PATCH 13/19 get rid of compat_mc_setsockopt()
In reply to Al ViroFrom: Al Viro <[email protected]>
not used anymore
--- include/net/compat.h | 4 --- net/compat.c | 90 ---------------------------------------------------- 2 files changed, 94 deletions(-)
include/net/compat.h +0 -4
@@ -67,10 +67,6 @@ int put_cmsg_compat(struct msghdr*, int, int, int, void *);int cmsghdr_from_user_compat_to_kern (struct msghdr *,struct sock *,unsigned char *,int ); -int compat_mc_setsockopt (struct sock *,int ,int ,char __user *,unsigned int , -int (*)(struct sock *,int ,int ,char __user *, -unsigned int )); -struct compat_group_req {__u32 gr_interface;struct __kernel_sockaddr_storage gr_group
net/compat.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 15/19 atm: separate ATM_GETNAMES handling from the rest of atm_dev_ioctl()
In reply to Al ViroFrom: Al Viro <[email protected]>
atm_dev_ioctl() does copyin in two different ways - one for ATM_GETNAMES, another for everything else. Start with separating the former into a new helper (atm_getnames()). The next step will be to lift the copyin into the callers.
--- net/atm/ioctl.c | 6 +++- net/atm/resources.c | 88 +++++++++++++++++++++++++++-------------------------- net/atm/resources.h | 1 + 3 files changed, 51 insertions(+), 44 deletions(-)
net/atm/ioctl.c +5 -1
@@ -162,7 +162,11 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,if (error != -ENOIOCTLCMD ) goto done; - error =atm_dev_ioctl (cmd, argp, compat); +if (cmd ==ATM_GETNAMES ) { + error =atm_getnames (argp, compat); + }else { + error =atm_dev_ioctl (cmd, argp, compat); + } done:return error;
net/atm/resources.c +45 -43
106 lines not on this page · raw message
net/atm/resources.h +1 -0
@@ -14,6 +14,7 @@extern struct list_head atm_devs;extern struct mutex atm_dev_mutex; +int atm_getnames (void __user *arg,int compat);int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat);
Signature · 1 line
2.11.0
PATCH 17/19 atm: switch do_atm_iobuf() to direct use of atm_getnames()
In reply to Al ViroFrom: Al Viro <[email protected]>
... and sod the compat_alloc_user_space() with its complications
--- net/atm/ioctl.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
net/atm/ioctl.c +3 -22
@@ -251,32 +251,13 @@ static struct {static int do_atm_iobuf (struct socket *sock,unsigned int cmd,unsigned long arg) { -struct atm_iobuf __user *iobuf; -struct compat_atm_iobuf __user *iobuf32; +struct compat_atm_iobuf __user *iobuf32 =compat_ptr (arg);u32 data; -void __user *datap; -int len, err; - - iobuf =compat_alloc_user_space (sizeof (*iobuf)); - iobuf32 =compat_ptr (arg); -if (get_user (len, &iobuf32->length) || -get_user (data, &iobuf32->buffer)) -return -EFAULT ; - datap =compat_ptr (data); -if (put_user (len, &iobuf->length) || -put_user (datap, &iobuf->buffer)) +if (get_user (data, &iobuf32->buffer))return -EFAULT ; - err =do_vcc_ioctl (sock, cmd, (unsigned long ) iobuf,0 ); - -if (!err) { -if (copy_in_user (&iobuf32->length, &iobuf->length, -sizeof (int ))) - err = -EFAULT ; - } - -return err; +return atm_getnames (&iobuf32->length,compat_ptr (data)); } static int do_atmif_sioc(struct socket *sock, unsigned int cmd,
Signature · 1 line
2.11.0
PATCH 12/19 handle the group_source_req options directly
In reply to Al ViroFrom: Al Viro <[email protected]>
Native ->setsockopt() handling of these options (MCAST_..._SOURCE_GROUP and MCAST_{,UN}BLOCK_SOURCE) consists of copyin + call of a helper that does the actual work. The only change needed for ->compat_setsockopt() is a slightly different copyin - the helpers can be reused as-is.
--- net/ipv4/ip_sockglue.c | 23 +++++++++++++++++++++-- net/ipv6/ipv6_sockglue.c | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-)
net/ipv4/ip_sockglue.c +21 -2
@@ -1322,8 +1322,27 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -return compat_mc_setsockopt (sk, level, optname, optval, optlen, - ip_setsockopt); + { +struct compat_group_source_req __user *gsr32 = (void __user *)optval; +struct group_source_req greqs; + +if (optlen !=sizeof (struct compat_group_source_req )) +return -EINVAL ; + +if (get_user (greqs.gsr_interface, &gsr32->gsr_interface) || +copy_from_user (&greqs.gsr_group, &gsr32->gsr_group, +sizeof (greqs.gsr_group)) || +copy_from_user (&greqs.gsr_source, &gsr32->gsr_source, +sizeof (greqs.gsr_source))) +return -EFAULT ; + +rtnl_lock (); +lock_sock (sk); + err =do_mcast_group_source (sk, optname, &greqs); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_MSFILTER : {const int size0 = offsetof(struct compat_group_filter , gf_slist);
net/ipv6/ipv6_sockglue.c +21 -2
@@ -1015,8 +1015,27 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -return compat_mc_setsockopt (sk, level, optname, optval, optlen, - ipv6_setsockopt); + { +struct compat_group_source_req __user *gsr32 = (void __user *)optval; +struct group_source_req greqs; + +if (optlen <sizeof (struct compat_group_source_req )) +return -EINVAL ; + +if (get_user (greqs.gsr_interface, &gsr32->gsr_interface) || +copy_from_user (&greqs.gsr_group, &gsr32->gsr_group, +sizeof (greqs.gsr_group)) || +copy_from_user (&greqs.gsr_source, &gsr32->gsr_source, +sizeof (greqs.gsr_source))) +return -EFAULT ; + +rtnl_lock (); +lock_sock (sk); + err =do_ipv6_mcast_group_source (sk, optname, &greqs); +release_sock (sk); +rtnl_unlock (); +return err; + }case MCAST_MSFILTER : {const int size0 = offsetof(struct compat_group_filter , gf_slist);
Signature · 1 line
2.11.0
PATCH 11/19 ipv6: take handling of group_source_req options into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv6/ipv6_sockglue.c | 65 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-)
net/ipv6/ipv6_sockglue.c +36 -29
@@ -136,6 +136,41 @@ static bool setsockopt_needs_rtnl(int optname)return false; } +static int do_ipv6_mcast_group_source (struct sock *sk,int optname, +struct group_source_req *greqs) +{ +int omode, add; + +if (greqs->gsr_group.ss_family !=AF_INET6 || + greqs->gsr_source.ss_family !=AF_INET6 ) +return -EADDRNOTAVAIL ; + +if (optname ==MCAST_BLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =1 ; + }else if (optname ==MCAST_UNBLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =0 ; + }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { +struct sockaddr_in6 *psin6; +int retv; + + psin6 = (struct sockaddr_in6 *)&greqs->gsr_group; + retv =ipv6_sock_mc_join_ssm (sk, greqs->gsr_interface, + &psin6->sin6_addr, +MCAST_INCLUDE ); +/* prior join w/ different source is ok */ +if (retv && retv != -EADDRINUSE ) +return retv; + omode =MCAST_INCLUDE ; + add =1 ; + }else /* MCAST_LEAVE_SOURCE_GROUP */ { + omode =MCAST_INCLUDE ; + add =0 ; + } +return ip6_mc_source (add, omode, sk, greqs); +} +static int do_ipv6_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -715,7 +750,6 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_UNBLOCK_SOURCE : {struct group_source_req greqs; -int omode, add;if (optlen <sizeof (struct group_source_req )) goto e_inval;
@@ -723,34 +757,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, retv = -EFAULT ;break ; } -if (greqs.gsr_group.ss_family !=AF_INET6 || - greqs.gsr_source.ss_family !=AF_INET6 ) { - retv = -EADDRNOTAVAIL ; -break ; - } -if (optname ==MCAST_BLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =1 ; - }else if (optname ==MCAST_UNBLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =0 ; - }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { -struct sockaddr_in6 *psin6; - - psin6 = (struct sockaddr_in6 *)&greqs.gsr_group; - retv =ipv6_sock_mc_join_ssm (sk, greqs.gsr_interface, - &psin6->sin6_addr, -MCAST_INCLUDE ); -/* prior join w/ different source is ok */ -if (retv && retv != -EADDRINUSE ) -break ; - omode =MCAST_INCLUDE ; - add =1 ; - }else /* MCAST_LEAVE_SOURCE_GROUP */ { - omode =MCAST_INCLUDE ; - add =0 ; - } - retv =ip6_mc_source (add, omode, sk, &greqs); + retv =do_ipv6_mcast_group_source (sk, optname, &greqs);break ; }case MCAST_MSFILTER :
Signature · 1 line
2.11.0
PATCH 14/19 batadv_socket_read(): get rid of pointless access_ok()
In reply to Al ViroFrom: Al Viro <[email protected]>
address is passed only to copy_to_user()
--- net/batman-adv/icmp_socket.c | 3 --- 1 file changed, 3 deletions(-)
net/batman-adv/icmp_socket.c +0 -3
@@ -135,9 +135,6 @@ static ssize_t batadv_socket_read(struct file *file, char __user *buf,if (!buf || count <sizeof (struct batadv_icmp_packet ))return -EINVAL ; -if (!access_ok (buf, count)) -return -EFAULT ; - error =wait_event_interruptible (socket_client->queue_wait, socket_client->queue_len);
Signature · 1 line
2.11.0
PATCH 16/19 atm: move copyin from atm_getnames() into the caller
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/atm/ioctl.c | 19 ++++++++++++++++++- net/atm/resources.c | 19 +------------------ net/atm/resources.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-)
net/atm/ioctl.c +18 -1
@@ -56,6 +56,8 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,int error;struct list_head *pos;void __user *argp = (void __user *)arg; +void __user *buf; +int __user *len; vcc =ATM_SD (sock);switch (cmd) {
@@ -163,7 +165,22 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd, goto done;if (cmd ==ATM_GETNAMES ) { - error =atm_getnames (argp, compat); +if (IS_ENABLED (CONFIG_COMPAT ) && compat) { +#ifdef CONFIG_COMPAT +struct compat_atm_iobuf __user *ciobuf = argp; +compat_uptr_t cbuf; + len = &ciobuf->length; +if (get_user (cbuf, &ciobuf->buffer)) +return -EFAULT ; + buf =compat_ptr (cbuf); +#endif + }else { +struct atm_iobuf __user *iobuf = argp; + len = &iobuf->length; +if (get_user (buf, &iobuf->buffer)) +return -EFAULT ; + } + error =atm_getnames (buf, len); }else { error =atm_dev_ioctl (cmd, argp, compat); }
net/atm/resources.c +1 -18
@@ -193,30 +193,13 @@ static int fetch_stats(struct atm_dev *dev, struct atm_dev_stats __user *arg,return error ? -EFAULT :0 ; } -int atm_getnames (void __user *arg,int compat) +int atm_getnames (void __user *buf,int __user *iobuf_len) { -void __user *buf;int error, len, size =0 ;struct atm_dev *dev;struct list_head *p;int *tmp_buf, *tmp_p; -int __user *iobuf_len; -if (IS_ENABLED (CONFIG_COMPAT ) && compat) { -#ifdef CONFIG_COMPAT -struct compat_atm_iobuf __user *ciobuf = arg; -compat_uptr_t cbuf; - iobuf_len = &ciobuf->length; -if (get_user (cbuf, &ciobuf->buffer)) -return -EFAULT ; - buf =compat_ptr (cbuf); -#endif - }else { -struct atm_iobuf __user *iobuf = arg; - iobuf_len = &iobuf->length; -if (get_user (buf, &iobuf->buffer)) -return -EFAULT ; - }if (get_user (len, iobuf_len))return -EFAULT ;mutex_lock (&atm_dev_mutex);
net/atm/resources.h +1 -1
@@ -14,7 +14,7 @@extern struct list_head atm_devs;extern struct mutex atm_dev_mutex; -int atm_getnames (void __user *arg,int compat); +int atm_getnames (void __user *buf,int __user *iobuf_len);int atm_dev_ioctl (unsigned int cmd,void __user *arg,int compat);
Signature · 1 line
2.11.0
PATCH 10/19 ipv4: take handling of group_source_req options into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv4/ip_sockglue.c | 83 ++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 39 deletions(-)
net/ipv4/ip_sockglue.c +44 -39
@@ -624,6 +624,49 @@ static int set_mcast_msfilter(struct sock *sk, int ifindex,return -EADDRNOTAVAIL ; } +static int do_mcast_group_source (struct sock *sk,int optname, +struct group_source_req *greqs) +{ +struct ip_mreq_source mreqs; +struct sockaddr_in *psin; +int omode, add, err; + +if (greqs->gsr_group.ss_family !=AF_INET || + greqs->gsr_source.ss_family !=AF_INET ) +return -EADDRNOTAVAIL ; + + psin = (struct sockaddr_in *)&greqs->gsr_group; + mreqs.imr_multiaddr = psin->sin_addr.s_addr; + psin = (struct sockaddr_in *)&greqs->gsr_source; + mreqs.imr_sourceaddr = psin->sin_addr.s_addr; + mreqs.imr_interface =0 ;/* use index for mc_source */ + +if (optname ==MCAST_BLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =1 ; + }else if (optname ==MCAST_UNBLOCK_SOURCE ) { + omode =MCAST_EXCLUDE ; + add =0 ; + }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { +struct ip_mreqn mreq; + + psin = (struct sockaddr_in *)&greqs->gsr_group; + mreq.imr_multiaddr = psin->sin_addr; + mreq.imr_address.s_addr =0 ; + mreq.imr_ifindex = greqs->gsr_interface; + err =ip_mc_join_group_ssm (sk, &mreq,MCAST_INCLUDE ); +if (err && err != -EADDRINUSE ) +return err; + greqs->gsr_interface = mreq.imr_ifindex; + omode =MCAST_INCLUDE ; + add =1 ; + }else /* MCAST_LEAVE_SOURCE_GROUP */ { + omode =MCAST_INCLUDE ; + add =0 ; + } +return ip_mc_source (add, omode, sk, &mreqs, greqs->gsr_interface); +} +static int do_ip_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1066,9 +1109,6 @@ static int do_ip_setsockopt(struct sock *sk, int level,case MCAST_UNBLOCK_SOURCE : {struct group_source_req greqs; -struct ip_mreq_source mreqs; -struct sockaddr_in *psin; -int omode, add;if (optlen !=sizeof (struct group_source_req )) goto e_inval;
@@ -1076,42 +1116,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, err = -EFAULT ;break ; } -if (greqs.gsr_group.ss_family !=AF_INET || - greqs.gsr_source.ss_family !=AF_INET ) { - err = -EADDRNOTAVAIL ; -break ; - } - psin = (struct sockaddr_in *)&greqs.gsr_group; - mreqs.imr_multiaddr = psin->sin_addr.s_addr; - psin = (struct sockaddr_in *)&greqs.gsr_source; - mreqs.imr_sourceaddr = psin->sin_addr.s_addr; - mreqs.imr_interface =0 ;/* use index for mc_source */ - -if (optname ==MCAST_BLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =1 ; - }else if (optname ==MCAST_UNBLOCK_SOURCE ) { - omode =MCAST_EXCLUDE ; - add =0 ; - }else if (optname ==MCAST_JOIN_SOURCE_GROUP ) { -struct ip_mreqn mreq; - - psin = (struct sockaddr_in *)&greqs.gsr_group; - mreq.imr_multiaddr = psin->sin_addr; - mreq.imr_address.s_addr =0 ; - mreq.imr_ifindex = greqs.gsr_interface; - err =ip_mc_join_group_ssm (sk, &mreq,MCAST_INCLUDE ); -if (err && err != -EADDRINUSE ) -break ; - greqs.gsr_interface = mreq.imr_ifindex; - omode =MCAST_INCLUDE ; - add =1 ; - }else /* MCAST_LEAVE_SOURCE_GROUP */ { - omode =MCAST_INCLUDE ; - add =0 ; - } - err =ip_mc_source (add, omode, sk, &mreqs, - greqs.gsr_interface); + err =do_mcast_group_source (sk, optname, &greqs);break ; }case MCAST_MSFILTER :
Signature · 1 line
2.11.0
PATCH 8/19 ipv6: do compat setsockopt for MCAST_MSFILTER directly
In reply to Al ViroFrom: Al Viro <[email protected]>
similar to the ipv4 counterpart of that patch - the same trick used to align the tail array properly.
--- net/ipv6/ipv6_sockglue.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
net/ipv6/ipv6_sockglue.c +47 -1
@@ -980,9 +980,55 @@ int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -case MCAST_MSFILTER :return compat_mc_setsockopt (sk, level, optname, optval, optlen, ipv6_setsockopt); +case MCAST_MSFILTER : + { +const int size0 = offsetof(struct compat_group_filter , gf_slist); +struct compat_group_filter *gf32; +void *p; +int n; + +if (optlen < size0) +return -EINVAL ; +if (optlen > sysctl_optmem_max -4 ) +return -ENOBUFS ; + + p =kmalloc (optlen +4 ,GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + gf32 = p +4 ;/* we want ->gf_group and ->gf_slist aligned */ +if (copy_from_user (gf32, optval, optlen)) { + err = -EFAULT ; + goto mc_msf_out; + } + + n = gf32->gf_numsrc; +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >=0x1ffffffU || + n > sysctl_mld_max_msf) { + err = -ENOBUFS ; + goto mc_msf_out; + } + if (offsetof(struct compat_group_filter, gf_slist[n]) > optlen) { + err = -EINVAL ; + goto mc_msf_out; + } + +rtnl_lock (); +lock_sock (sk); + err =ip6_mc_msfilter (sk, &(struct group_filter ){ + .gf_interface = gf32->gf_interface, + .gf_group = gf32->gf_group, + .gf_fmode = gf32->gf_fmode, + .gf_numsrc = gf32->gf_numsrc}, gf32->gf_slist); +release_sock (sk); +rtnl_unlock (); +mc_msf_out: +kfree (p); +return err; + } } err =do_ipv6_setsockopt (sk, level, optname, optval, optlen);
Signature · 1 line
2.11.0
PATCH 6/19 ipv4: do compat setsockopt for MCAST_MSFILTER directly
In reply to Al ViroFrom: Al Viro <[email protected]>
Parallel to what the native setsockopt() does, except that unlike the native setsockopt() we do not use memdup_user() - we want the sockaddr_storage fields properly aligned, so we allocate 4 bytes more and copy compat_group_filter at the offset 4, which yields the proper alignments.
--- net/ipv4/ip_sockglue.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
net/ipv4/ip_sockglue.c +47 -1
@@ -1286,9 +1286,55 @@ int compat_ip_setsockopt(struct sock *sk, int level, int optname,case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :case MCAST_UNBLOCK_SOURCE : -case MCAST_MSFILTER :return compat_mc_setsockopt (sk, level, optname, optval, optlen, ip_setsockopt); +case MCAST_MSFILTER : + { +const int size0 = offsetof(struct compat_group_filter , gf_slist); +struct compat_group_filter *gf32; +void *p; +int n; + +if (optlen < size0) +return -EINVAL ; +if (optlen > sysctl_optmem_max -4 ) +return -ENOBUFS ; + + p =kmalloc (optlen +4 ,GFP_KERNEL ); +if (!p) +return -ENOMEM ; + gf32 = p +4 ;/* we want ->gf_group and ->gf_slist aligned */ +if (copy_from_user (gf32, optval, optlen)) { + err = -EFAULT ; + goto mc_msf_out; + } + + n = gf32->gf_numsrc; +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >=0x1ffffff ) { + err = -ENOBUFS ; + goto mc_msf_out; + } + if (offsetof(struct compat_group_filter, gf_slist[n]) > optlen) { + err = -EINVAL ; + goto mc_msf_out; + } + +rtnl_lock (); +lock_sock (sk); +/* numsrc >= (4G-140)/128 overflow in 32 bits */ +if (n >sock_net (sk)->ipv4.sysctl_igmp_max_msf) + err = -ENOBUFS ; +else + err =set_mcast_msfilter (sk, gf32->gf_interface, + n, gf32->gf_fmode, + &gf32->gf_group, gf32->gf_slist); +release_sock (sk); +rtnl_unlock (); +mc_msf_out: +kfree (p); +return err; + } } err =do_ip_setsockopt (sk, level, optname, optval, optlen);
Signature · 1 line
2.11.0
PATCH 4/19 get rid of compat_mc_getsockopt()
In reply to Al ViroFrom: Al Viro <[email protected]>
now we can do MCAST_MSFILTER in compat ->getsockopt() without playing silly buggers with copying things back and forth. We can form a native struct group_filter (sans the variable-length tail) on stack, pass that + pointer to the tail of original request to the helper doing the bulk of the work, then do the rest of copyout - same as the native getsockopt() does.
--- include/net/compat.h | 3 -- net/compat.c | 79 ------------------------------------------------ net/ipv4/ip_sockglue.c | 44 +++++++++++++++++++++++++-- net/ipv6/ipv6_sockglue.c | 41 +++++++++++++++++++++++-- 4 files changed, 79 insertions(+), 88 deletions(-)
include/net/compat.h +0 -3
@@ -70,9 +70,6 @@ int cmsghdr_from_user_compat_to_kern(struct msghdr *, struct sock *,int compat_mc_setsockopt (struct sock *,int ,int ,char __user *,unsigned int ,int (*)(struct sock *,int ,int ,char __user *,unsigned int )); -int compat_mc_getsockopt (struct sock *,int ,int ,char __user *,int __user *, -int (*)(struct sock *,int ,int ,char __user *, -int __user *));struct compat_group_req {__u32 gr_interface;
net/compat.c +0 -79
85 lines not on this page · raw message
net/ipv4/ip_sockglue.c +41 -3
50 lines not on this page · raw message
net/ipv6/ipv6_sockglue.c +38 -3
47 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 5/19 set_mcast_msfilter(): take the guts of setsockopt(MCAST_MSFILTER) into a helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- net/ipv4/ip_sockglue.c | 73 +++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 33 deletions(-)
net/ipv4/ip_sockglue.c +40 -33
@@ -587,6 +587,43 @@ static bool setsockopt_needs_rtnl(int optname)return false; } +static int set_mcast_msfilter (struct sock *sk,int ifindex, +int numsrc,int fmode, +struct sockaddr_storage *group, +struct sockaddr_storage *list) +{ +int msize =IP_MSFILTER_SIZE (numsrc); +struct ip_msfilter *msf; +struct sockaddr_in *psin; +int err, i; + + msf =kmalloc (msize,GFP_KERNEL ); +if (!msf) +return -ENOBUFS ; + + psin = (struct sockaddr_in *)group; +if (psin->sin_family !=AF_INET ) + goto Eaddrnotavail; + msf->imsf_multiaddr = psin->sin_addr.s_addr; + msf->imsf_interface =0 ; + msf->imsf_fmode = fmode; + msf->imsf_numsrc = numsrc; +for (i =0 ; i < numsrc; ++i) { + psin = (struct sockaddr_in *)&list[i]; + +if (psin->sin_family !=AF_INET ) + goto Eaddrnotavail; + msf->imsf_slist[i] = psin->sin_addr.s_addr; + } + err =ip_mc_msfilter (sk, msf, ifindex); +kfree (msf); +return err; + +Eaddrnotavail: +kfree (msf); +return -EADDRNOTAVAIL ; +} +static int do_ip_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1079,10 +1116,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, }case MCAST_MSFILTER : { -struct sockaddr_in *psin; -struct ip_msfilter *msf =NULL ;struct group_filter *gsf =NULL ; -int msize, i, ifindex;if (optlen <GROUP_FILTER_SIZE (0 )) goto e_inval;
@@ -1095,7 +1129,6 @@ static int do_ip_setsockopt(struct sock *sk, int level, err =PTR_ERR (gsf);break ; } -/* numsrc >= (4G-140)/128 overflow in 32 bits */ if (gsf->gf_numsrc >=0x1ffffff || gsf->gf_numsrc > net->ipv4.sysctl_igmp_max_msf) {
@@ -1106,36 +1139,10 @@ static int do_ip_setsockopt(struct sock *sk, int level, err = -EINVAL ; goto mc_msf_out; } - msize =IP_MSFILTER_SIZE (gsf->gf_numsrc); - msf =kmalloc (msize,GFP_KERNEL ); -if (!msf) { - err = -ENOBUFS ; - goto mc_msf_out; - } - ifindex = gsf->gf_interface; - psin = (struct sockaddr_in *)&gsf->gf_group; -if (psin->sin_family !=AF_INET ) { - err = -EADDRNOTAVAIL ; - goto mc_msf_out; - } - msf->imsf_multiaddr = psin->sin_addr.s_addr; - msf->imsf_interface =0 ; - msf->imsf_fmode = gsf->gf_fmode; - msf->imsf_numsrc = gsf->gf_numsrc; - err = -EADDRNOTAVAIL ; -for (i =0 ; i < gsf->gf_numsrc; ++i) { - psin = (struct sockaddr_in *)&gsf->gf_slist[i]; - -if (psin->sin_family !=AF_INET ) - goto mc_msf_out; - msf->imsf_slist[i] = psin->sin_addr.s_addr; - } -kfree (gsf); - gsf =NULL ; - - err =ip_mc_msfilter (sk, msf, ifindex); + err =set_mcast_msfilter (sk, gsf->gf_interface, + gsf->gf_numsrc, gsf->gf_fmode, + &gsf->gf_group, gsf->gf_slist); mc_msf_out: -kfree (msf);kfree (gsf);break ; }
Signature · 1 line
2.11.0
PATCH 1/19 lift compat definitions of mcast [sg]etsockopt requests into net/compat.h
In reply to Al ViroFrom: Al Viro <[email protected]>
We want to get rid of compat_mc_[sg]etsockopt() and to have that stuff handled without compat_alloc_user_space(), extra copying through userland, etc. To do that we'll need ipv4 and ipv6 instances of ->compat_[sg]etsockopt() to manipulate the 32bit variants of mcast requests, so we need to move the definitions of those out of net/compat.c and into a public header.
This patch just does a mechanical move to include/net/compat.h
--- include/net/compat.h | 24 ++++++++++++++++++++++++ net/compat.c | 25 ------------------------- 2 files changed, 24 insertions(+), 25 deletions(-)
include/net/compat.h +24 -0
@@ -74,4 +74,28 @@ int compat_mc_getsockopt(struct sock *, int, int, char __user *, int __user *, int (*)(struct sock *, int, int, char __user *, int __user *)); +struct compat_group_req { +__u32 gr_interface; +struct __kernel_sockaddr_storage gr_group +__aligned(4) ; +} __packed; + +struct compat_group_source_req { +__u32 gsr_interface; +struct __kernel_sockaddr_storage gsr_group +__aligned(4) ; +struct __kernel_sockaddr_storage gsr_source +__aligned(4) ; +} __packed; + +struct compat_group_filter { +__u32 gf_interface; +struct __kernel_sockaddr_storage gf_group +__aligned(4) ; +__u32 gf_fmode; +__u32 gf_numsrc; +struct __kernel_sockaddr_storage gf_slist[1 ] +__aligned(4) ; +} __packed; +#endif /* NET_COMPAT_H */
net/compat.c +0 -25
@@ -448,34 +448,9 @@ COMPAT_SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,return __compat_sys_getsockopt (fd, level, optname, optval, optlen); } -struct compat_group_req { -__u32 gr_interface; -struct __kernel_sockaddr_storage gr_group -__aligned(4) ; -} __packed; - -struct compat_group_source_req { -__u32 gsr_interface; -struct __kernel_sockaddr_storage gsr_group -__aligned(4) ; -struct __kernel_sockaddr_storage gsr_source -__aligned(4) ; -} __packed; - -struct compat_group_filter { -__u32 gf_interface; -struct __kernel_sockaddr_storage gf_group -__aligned(4) ; -__u32 gf_fmode; -__u32 gf_numsrc; -struct __kernel_sockaddr_storage gf_slist[1 ] -__aligned(4) ; -} __packed; -#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \ sizeof(struct __kernel_sockaddr_storage)) -int compat_mc_setsockopt (struct sock *sock,int level,int optname,char __user *optval,unsigned int optlen,int (*setsockopt)(struct sock *,int ,int ,char __user *,unsigned int ))
Signature · 1 line
2.11.0
PATCH 3/19 ip*_mc_gsfget(): lift copyout of struct group_filter into callers
From: Al Viro <[email protected]>
pass the userland pointer to the array in its tail, so that part gets copied out by our functions; copyout of everything else is done in the callers. Rationale: reuse for compat; the array is the same in native and compat, the layout of parts before it is different for compat.
--- include/linux/igmp.h | 2 +- include/net/ipv6.h | 2 +- net/ipv4/igmp.c | 18 +++++------------- net/ipv4/ip_sockglue.c | 19 ++++++++++++++----- net/ipv6/ipv6_sockglue.c | 18 ++++++++++++++---- net/ipv6/mcast.c | 10 +++------- 6 files changed, 38 insertions(+), 31 deletions(-)
include/linux/igmp.h +1 -1
@@ -123,7 +123,7 @@ extern int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf,int ifindex);extern int ip_mc_msfget (struct sock *sk,struct ip_msfilter *msf,struct ip_msfilter __user *optval,int __user *optlen);extern int ip_mc_gsfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen); +struct sockaddr_storage __user *p);extern int ip_mc_sf_allow (struct sock *sk,__be32 local,__be32 rmt,int dif,int sdif);extern void ip_mc_init_dev (struct in_device *);
include/net/ipv6.h +1 -1
@@ -1138,7 +1138,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk, struct group_source_req *pgsr);int ip6_mc_msfilter (struct sock *sk,struct group_filter *gsf);int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen); +struct sockaddr_storage __user *p);#ifdef CONFIG_PROC_FS int ac6_proc_init (struct net *net);
net/ipv4/igmp.c +5 -13
@@ -2565,9 +2565,9 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, }int ip_mc_gsfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen) +struct sockaddr_storage __user *p) { -int err, i, count, copycount; +int i, count, copycount;struct sockaddr_in *psin;__be32 addr;struct ip_mc_socklist *pmc;
@@ -2583,37 +2583,29 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,if (!ipv4_is_multicast (addr))return -EINVAL ; - err = -EADDRNOTAVAIL ; -for_each_pmc_rtnl (inet, pmc) {if (pmc->multi.imr_multiaddr.s_addr == addr && pmc->multi.imr_ifindex == gsf->gf_interface)break ; }if (!pmc)/* must have a prior join */ - goto done; +return -EADDRNOTAVAIL ; gsf->gf_fmode = pmc->sfmode; psl =rtnl_dereference (pmc->sflist); count = psl ? psl->sl_count :0 ; copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; gsf->gf_numsrc = count; -if (put_user (GROUP_FILTER_SIZE (copycount), optlen) || -copy_to_user (optval, gsf,GROUP_FILTER_SIZE (0 ))) { -return -EFAULT ; - } -for (i =0 ; i < copycount; i++) { +for (i =0 ; i < copycount; i++, p++) {struct sockaddr_storage ss; psin = (struct sockaddr_in *)&ss;memset (&ss,0 ,sizeof (ss)); psin->sin_family =AF_INET ; psin->sin_addr.s_addr = psl->sl_addr[i]; -if (copy_to_user (&optval->gf_slist[i], &ss,sizeof (ss))) +if (copy_to_user (p, &ss,sizeof (ss)))return -EFAULT ; }return 0 ; -done: -return err; }/*
net/ipv4/ip_sockglue.c +14 -5
@@ -1473,19 +1473,28 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname, }case MCAST_MSFILTER : { +struct group_filter __user *p = (void __user *)optval;struct group_filter gsf; +const int size0 = offsetof(struct group_filter , gf_slist); +int num; -if (len <GROUP_FILTER_SIZE (0 )) { +if (len < size0) { err = -EINVAL ; goto out; } -if (copy_from_user (&gsf, optval,GROUP_FILTER_SIZE (0 ))) { +if (copy_from_user (&gsf, p, size0)) { err = -EFAULT ; goto out; } - err =ip_mc_gsfget (sk, &gsf, - (struct group_filter __user *)optval, - optlen); + num = gsf.gf_numsrc; + err =ip_mc_gsfget (sk, &gsf, p->gf_slist); +if (err) + goto out; +if (gsf.gf_numsrc < num) + num = gsf.gf_numsrc; +if (put_user (GROUP_FILTER_SIZE (num), optlen) || +copy_to_user (p, &gsf, size0)) + err = -EFAULT ; goto out; }case IP_MULTICAST_ALL :
net/ipv6/ipv6_sockglue.c +14 -4
@@ -1056,18 +1056,28 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,break ;case MCAST_MSFILTER : { +struct group_filter __user *p = (void __user *)optval;struct group_filter gsf; +const int size0 = offsetof(struct group_filter , gf_slist); +int num;int err; -if (len <GROUP_FILTER_SIZE (0 )) +if (len < size0)return -EINVAL ; -if (copy_from_user (&gsf, optval,GROUP_FILTER_SIZE (0 ))) +if (copy_from_user (&gsf, p, size0))return -EFAULT ;if (gsf.gf_group.ss_family !=AF_INET6 )return -EADDRNOTAVAIL ; + num = gsf.gf_numsrc;lock_sock (sk); - err =ip6_mc_msfget (sk, &gsf, - (struct group_filter __user *)optval, optlen); + err =ip6_mc_msfget (sk, &gsf, p->gf_slist); +if (!err) { +if (num > gsf.gf_numsrc) + num = gsf.gf_numsrc; +if (put_user (GROUP_FILTER_SIZE (num), optlen) || +copy_to_user (p, &gsf, size0)) + err = -EFAULT ; + }release_sock (sk);return err; }
net/ipv6/mcast.c +3 -7
@@ -547,7 +547,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) }int ip6_mc_msfget (struct sock *sk,struct group_filter *gsf, -struct group_filter __user *optval,int __user *optlen) +struct sockaddr_storage *p) {int err, i, count, copycount;const struct in6_addr *group;
@@ -592,14 +592,10 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; gsf->gf_numsrc = count; -if (put_user (GROUP_FILTER_SIZE (copycount), optlen) || -copy_to_user (optval, gsf,GROUP_FILTER_SIZE (0 ))) { -return -EFAULT ; - }/* changes to psl require the socket lock, and a write lock * on pmc->sflock. We have the socket lock so reading here is safe. */ -for (i =0 ; i < copycount; i++) { +for (i =0 ; i < copycount; i++, p++) {struct sockaddr_in6 *psin6;struct sockaddr_storage ss;
@@ -607,7 +603,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,memset (&ss,0 ,sizeof (ss)); psin6->sin6_family =AF_INET6 ; psin6->sin6_addr = psl->sl_addr[i]; -if (copy_to_user (&optval->gf_slist[i], &ss,sizeof (ss))) +if (copy_to_user (p, &ss,sizeof (ss)))return -EFAULT ; }return 0 ;
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Al Viro <[email protected]>
Date: Thu, 21 May 2020 01:36:57 +0100
Quoted 17 lines · David Miller
Quoted 16 lines
From: Al Viro <[email protected]>
Date: Mon, 11 May 2020 05:43:28 +0100Quoted 12 lines
Assorted uaccess-related work in
net/*. First, there's
getting rid ofcompat_alloc_user_space()mess inMCAST_... [gs]etsockopt() - no need to play with copying to/from temporary object on userland stack, etc., when ->compat_[sg]etsockopt() instances in question can easly do everything without that. That's the first 13 patches. Then there's a trivial bit innet/batman-adv(completely unrelated to everything else) and finally getting the atm compat ioctls into simpler shape.Please, review and comment. Individual patches in followups,
the entire branch (on top of current net/master) is ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git#uaccess.net
Quoted 6 lines
Quoted 3 lines
I have no problems with this series:
Acked-by David S. Miller <[email protected]>OK, rebased on top of current net/master (no conflicts) and pushed out to the same branch. Patches (for net-next) in followups
Looks good, pulled into net-next.