get rid of compat_mc_getsockopt()

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.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro
2020-03-29 22:08:59 -04:00
parent 931ca7ab7f
commit 0dfe6581a7
4 changed files with 79 additions and 88 deletions

View File

@@ -1607,9 +1607,47 @@ int compat_ip_getsockopt(struct sock *sk, int level, int optname,
{
int err;
if (optname == MCAST_MSFILTER)
return compat_mc_getsockopt(sk, level, optname, optval, optlen,
ip_getsockopt);
if (optname == MCAST_MSFILTER) {
const int size0 = offsetof(struct compat_group_filter, gf_slist);
struct compat_group_filter __user *p = (void __user *)optval;
struct compat_group_filter gf32;
struct group_filter gf;
int ulen, err;
int num;
if (level != SOL_IP)
return -EOPNOTSUPP;
if (get_user(ulen, optlen))
return -EFAULT;
if (ulen < size0)
return -EINVAL;
if (copy_from_user(&gf32, p, size0))
return -EFAULT;
gf.gf_interface = gf32.gf_interface;
gf.gf_fmode = gf32.gf_fmode;
num = gf.gf_numsrc = gf32.gf_numsrc;
gf.gf_group = gf32.gf_group;
rtnl_lock();
lock_sock(sk);
err = ip_mc_gsfget(sk, &gf, p->gf_slist);
release_sock(sk);
rtnl_unlock();
if (err)
return err;
if (gf.gf_numsrc < num)
num = gf.gf_numsrc;
ulen = GROUP_FILTER_SIZE(num) - (sizeof(gf) - sizeof(gf32));
if (put_user(ulen, optlen) ||
put_user(gf.gf_fmode, &p->gf_fmode) ||
put_user(gf.gf_numsrc, &p->gf_numsrc))
return -EFAULT;
return 0;
}
err = do_ip_getsockopt(sk, level, optname, optval, optlen,
MSG_CMSG_COMPAT);