Re: [PATCH v2] net: don't unconditionally copy_from_user a struct ifreq for socket ioctls
From: Jakub Kicinski
Date: Wed Sep 01 2021 - 19:20:16 EST
On Wed, 1 Sep 2021 11:01:32 -0700 Peter Collingbourne wrote:
> > > To stop the copy_from_user() faulting when the user buffer
> > > isn't long enough.
> > > In particular for iasatty() on arm with tagged pointers.
> >
> > Let me rephrase. is_socket_ioctl_cmd() is always true here. There were
> > only two callers, both check cmd is of specific, "sockety" type.
>
> I see, it looks like we don't need the check on the compat path then.
>
> I can send a followup to clean this up but given that I got a comment
> from another reviewer saying that we should try to make the native and
> compat paths as similar as possible, maybe it isn't too bad to leave
> things as is?
I have a weak preference to get rid of it, the code is a little
complex and extra dead code makes it harder to follow, but up to you.
IMO the "right place" for the check is:
static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
[...]
default:
/* --> here <-- */
err = sock_do_ioctl(net, sock, cmd, arg);
break;
Since that's the point where we take all the remaining cmd values and
call a function which assumes struct ifreq.
Compat code does not have a default statement.
But as I said no big deal, feel free to ignore.