Subject: Re: [PATCH v1 net] netlink: Use copy_to_user() for optval in netlink_getsockopt().

From: Kuniyuki Iwashima <[email-masked]>
Date: Wed, 19 Apr 2023 20:40:50 -0700

From: Jakub Kicinski <[email-masked]>
Date: Wed, 19 Apr 2023 16:09:08 -0700
> On Wed, 19 Apr 2023 09:17:37 +0200 Johannes Berg wrote:
> > > @@ -1754,39 +1754,17 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname,
> > >
> > >         switch (optname) {
> > >         case NETLINK_PKTINFO:
> > > -               if (len < sizeof(int))
> > > -                       return -EINVAL;
> > > -               len = sizeof(int);
> >
> > On the other hand, this is actually accepting say a u64 now, and then
> > sets only 4 bytes of it, though at least it also sets the size to what
> > it wrote out.
> >
> > So I guess here we can argue either
> >  1) keep writing len to 4 and set 4 bytes of the output
> >  2) keep the length as is and set all bytes of the output
> >
> > but (2) gets confusing if you say used 6 bytes buffer as input? I mean,
> > yeah, I'd really hope nobody does that.
> >
> > If Jakub is feeling adventurous maybe we should attempt to see if we
> > break anything by accepting only == sizeof(int) rather than >= ... :-)
> 
> Can't think of a strong reason either way, so I'd keep the check
> and len setting as is.

Ok, I'll respin v2 with the existing check and len setting.

Thank you, Johannes and Jakub!