public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Eric Dumazet <edumazet@google.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org,  davem@davemloft.net,  kuba@kernel.org,
	 pabeni@redhat.com,  horms@kernel.org,  axboe@kernel.dk,
	 kuniyu@google.com,  Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net-next] net: do not write to msg_get_inq in caller
Date: Mon, 05 Jan 2026 12:42:43 -0500	[thread overview]
Message-ID: <willemdebruijn.kernel.2124bbf561b5e@gmail.com> (raw)
In-Reply-To: <CANn89iL+AuhJw7-Ma4hQsgQ5X0vxOwToSr2mgVSbkSauy-TGkg@mail.gmail.com>

Eric Dumazet wrote:
> On Mon, Jan 5, 2026 at 5:33 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > From: Willem de Bruijn <willemb@google.com>
> >
> > msg_get_inq is an input field from caller to callee. Don't set it in
> > the callee, as the caller may not clear it on struct reuse.
> >
> > This is a kernel-internal variant of msghdr only, and the only user
> > does reinitialize the field. So this is not critical.
> >
> > But it is more robust to avoid the write, and slightly simpler code.
> >
> > Callers set msg_get_inq to request the input queue length to be
> > returned in msg_inq. This is equivalent to but independent from the
> > SO_INQ request to return that same info as a cmsg (tp->recvmsg_inq).
> > To reduce branching in the hot path the second also sets the msg_inq.
> > That is WAI.
> >
> > This is a small follow-on to commit 4d1442979e4a ("af_unix: don't
> > post cmsg for SO_INQ unless explicitly asked for"), which fixed the
> > inverse.
> >
> > Also collapse two branches using a bitwise or.
> >
> > Link: https://lore.kernel.org/netdev/willemdebruijn.kernel.24d8030f7a3de@gmail.com/
> > Signed-off-by: Willem de Bruijn <willemb@google.com>
> > ---
> 
> Patch looks sane to me, but the title is a bit confusing, I guess you meant
> 
> "net: do not write to msg_get_inq in callee" ?

Indeed, thanks. Will fix.

> 
> Also, unix_stream_read_generic() is currently potentially adding a NULL deref
> if u->recvmsg_inq is non zero, but msg is NULL ?
> 
> If this is the case  we need a Fixes: tag.

Oh good point. state->msg can be NULL as of commit 2b514574f7e8 ("net:
af_unix: implement splice for stream af_unix sockets"). That commit
mentions "we mostly have to deal with a non-existing struct msghdr
argument".

Okay. Will resubmit to net with a Fixes tag (after the usual 24hrs).

Thanks!

  parent reply	other threads:[~2026-01-05 17:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 16:32 [PATCH net-next] net: do not write to msg_get_inq in caller Willem de Bruijn
2026-01-05 17:21 ` Eric Dumazet
2026-01-05 17:42   ` Jens Axboe
2026-01-05 17:42   ` Willem de Bruijn [this message]
2026-01-05 17:44     ` Jens Axboe
2026-01-05 17:57       ` Willem de Bruijn
2026-01-05 17:58         ` Eric Dumazet
2026-01-05 17:58         ` Jens Axboe
2026-01-05 17:34 ` Jens Axboe

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=willemdebruijn.kernel.2124bbf561b5e@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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