linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Collingbourne <pcc@google.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Colin Ian King <colin.king@canonical.com>,
	Cong Wang <cong.wang@bytedance.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Networking <netdev@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"# 3.4.x" <stable@vger.kernel.org>
Subject: Re: [PATCH] net: don't unconditionally copy_from_user a struct ifreq for socket ioctls
Date: Thu, 26 Aug 2021 12:46:30 -0700	[thread overview]
Message-ID: <CAMn1gO5Nr_zQ5Sj3yFhSCtFFQfp4jXNU+UPPfCW3_gwfE6c9gA@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a0Euhxqz50SSid4GmxH1+GWG+weqYS8BLjgxR+ZcC-C=g@mail.gmail.com>

On Thu, Aug 26, 2021 at 1:59 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> On Thu, Aug 26, 2021 at 3:28 AM Peter Collingbourne <pcc@google.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

I think that David's suggestion of using _IOC_TYPE() should be enough
to address this for now.

> 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.

I think we should leave that for a followup if still necessary.

Peter

      reply	other threads:[~2021-08-26 19:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  1:27 [PATCH] net: don't unconditionally copy_from_user a struct ifreq for socket ioctls Peter Collingbourne
2021-08-26  6:39 ` Greg KH
2021-08-26 19:46   ` Peter Collingbourne
2021-08-26  8:12 ` David Laight
2021-08-26 19:46   ` Peter Collingbourne
2021-08-27  8:34     ` David Laight
2021-08-26  8:58 ` Arnd Bergmann
2021-08-26 19:46   ` Peter Collingbourne [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMn1gO5Nr_zQ5Sj3yFhSCtFFQfp4jXNU+UPPfCW3_gwfE6c9gA@mail.gmail.com \
    --to=pcc@google.com \
    --cc=arnd@kernel.org \
    --cc=colin.king@canonical.com \
    --cc=cong.wang@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).