lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK8P3a0Euhxqz50SSid4GmxH1+GWG+weqYS8BLjgxR+ZcC-C=g@mail.gmail.com>
Date:   Thu, 26 Aug 2021 10:58:44 +0200
From:   Arnd Bergmann <arnd@...nel.org>
To:     Peter Collingbourne <pcc@...gle.com>
Cc:     "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Colin Ian King <colin.king@...onical.com>,
        Cong Wang <cong.wang@...edance.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        Networking <netdev@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        "# 3.4.x" <stable@...r.kernel.org>
Subject: Re: [PATCH] net: don't unconditionally copy_from_user a struct ifreq
 for socket ioctls

On Thu, Aug 26, 2021 at 3:28 AM Peter Collingbourne <pcc@...gle.com> wrote:

> -       } else {
> +       } else if (is_dev_ioctl_cmd(cmd)) {
>                 struct ifreq ifr;
>                 bool need_copyout;
>                 if (copy_from_user(&ifr, argp, sizeof(struct ifreq)))
> @@ -1118,6 +1118,8 @@ static long sock_do_ioctl(struct net *net, struct socket *sock,
>                 if (!err && need_copyout)
>                         if (copy_to_user(argp, &ifr, sizeof(struct ifreq)))
>                                 return -EFAULT;
> +       } else {
> +               err = -ENOTTY;
>         }
>         return err;
>  }
> @@ -3306,6 +3308,8 @@ static int compat_ifr_data_ioctl(struct net *net, unsigned int cmd,
>         struct ifreq ifreq;
>         u32 data32;
>
> +       if (!is_dev_ioctl_cmd(cmd))
> +               return -ENOTTY;
>         if (copy_from_user(ifreq.ifr_name, u_ifreq32->ifr_name, IFNAMSIZ))
>                 return -EFAULT;
>         if (get_user(data32, &u_ifreq32->ifr_data))

This adds yet another long switch() statement into the socket ioctl
case, when there
is already one in compat_sock_ioctl_trans(), one in dev_ifsioc() and one in
dev_ioctl(), all with roughly the same set of ioctl command codes. If
any of them
are called frequently, that makes it all even slower, so I wonder if
there should
be a larger rework altogether. Maybe something based on a single lookup table
that we search through directly from sock_ioctl()/compat_sock_ioctl() to deal
with the differences in handling (ifreq based, compat handler, proto_ops
override, dev_load, rtnl_lock, rcu_read_lock, CAP_NET_ADMIN, copyout, ...).

You are also adding the checks into different places for native and compat
mode, which makes them diverge more when we should be trying to
make them more common.

I think based on my recent changes, some other simplifications are possible,
based on how the compat path already enumerates all the dev ioctls.

        Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ