Re: [PATCH 3/3] net: cleanly handle kernel vs user buffers for ->msg_control

From: Christoph Hellwig
Date: Wed May 13 2020 - 12:09:44 EST


On Wed, May 13, 2020 at 08:41:57AM -0700, Eric Dumazet wrote:
> > + * recv* side when msg_control_is_user is set, msg_control is the kernel
> > + * buffer used for all other cases.
> > + */
> > + union {
> > + void *msg_control;
> > + void __user *msg_control_user;
> > + };
> > + bool msg_control_is_user : 1;
>
> Adding a field in this structure seems dangerous.
>
> Some users of 'struct msghdr ' define their own struct on the stack,
> and are unaware of this new mandatory field.
>
> This bit contains garbage, crashes are likely to happen ?
>
> Look at IPV6_2292PKTOPTIONS for example.

I though of that, an that is why the field is structured as-is. The idea
is that the field only matters if:

(1) we are in the recvmsg and friends path, and
(2) msg_control is non-zero

I went through the places that initialize msg_control to find any spot
that would need an annotation. The IPV6_2292PKTOPTIONS sockopt doesn't
need one as it is using the msghdr in sendmsg-like context.

That being said while I did the audit I'd appreciate another look from
people that know the networking code better than me of course.