From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
netdev@vger.kernel.org
Cc: io-uring@vger.kernel.org, kuba@kernel.org, kuniyu@google.com,
willemb@google.com, stable@vger.kernel.org,
Julian Orth <ju.orth@gmail.com>
Subject: Re: [PATCH 1/2] af_unix: don't post cmsg for SO_INQ unless explicitly asked for
Date: Thu, 18 Dec 2025 16:15:09 -0500 [thread overview]
Message-ID: <willemdebruijn.kernel.164466b751181@gmail.com> (raw)
In-Reply-To: <2ed38b2d-6f87-4878-b988-450cd95f8679@kernel.dk>
Jens Axboe wrote:
> On 12/18/25 1:35 PM, Willem de Bruijn wrote:
> > Jens Axboe wrote:
> >> A previous commit added SO_INQ support for AF_UNIX (SOCK_STREAM), but
> >> it posts a SCM_INQ cmsg even if just msg->msg_get_inq is set. This is
> >> incorrect, as ->msg_get_inq is just the caller asking for the remainder
> >> to be passed back in msg->msg_inq, it has nothing to do with cmsg. The
> >> original commit states that this is done to make sockets
> >> io_uring-friendly", but it's actually incorrect as io_uring doesn't
> >> use cmsg headers internally at all, and it's actively wrong as this
> >> means that cmsg's are always posted if someone does recvmsg via
> >> io_uring.
> >>
> >> Fix that up by only posting cmsg if u->recvmsg_inq is set.
> >>
> >> Cc: stable@vger.kernel.org
> >> Fixes: df30285b3670 ("af_unix: Introduce SO_INQ.")
> >> Reported-by: Julian Orth <ju.orth@gmail.com>
> >> Link: https://github.com/axboe/liburing/issues/1509
> >> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> >> ---
> >> net/unix/af_unix.c | 10 +++++++---
> >> 1 file changed, 7 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> >> index 55cdebfa0da0..110d716087b5 100644
> >> --- a/net/unix/af_unix.c
> >> +++ b/net/unix/af_unix.c
> >> @@ -3086,12 +3086,16 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
> >>
> >> mutex_unlock(&u->iolock);
> >> if (msg) {
> >> + bool do_cmsg;
> >> +
> >> scm_recv_unix(sock, msg, &scm, flags);
> >>
> >> - if (READ_ONCE(u->recvmsg_inq) || msg->msg_get_inq) {
> >> + do_cmsg = READ_ONCE(u->recvmsg_inq);
> >> + if (do_cmsg || msg->msg_get_inq) {
> >> msg->msg_inq = READ_ONCE(u->inq_len);
> >> - put_cmsg(msg, SOL_SOCKET, SCM_INQ,
> >> - sizeof(msg->msg_inq), &msg->msg_inq);
> >> + if (do_cmsg)
> >> + put_cmsg(msg, SOL_SOCKET, SCM_INQ,
> >> + sizeof(msg->msg_inq), &msg->msg_inq);
> >
> > Is it intentional that msg_inq is set also if msg_get_inq is not set,
> > but do_cmsg is?
>
> It doesn't really matter, what matters is the actual cmsg posting be
> guarded. The msg_inq should only be used for a successful return anyway,
> I think we're better off reading it unconditionally than having multiple
> branches.
>
> Not really important, if you prefer to keep them consistent, that's fine
> with me too.
>
> >
> > It just seems a bit surprising behavior.
> >
> > That is an entangling of two separate things.
> > - msg_get_inq sets msg_inq, and
> > - cmsg_flags & TCP_CMSG_INQ inserts TCP_CM_INQ cmsg
> >
> > The original TCP patch also entangles them, but in another way.
> > The cmsg is written only if msg_get_inq is requested.
>
> The cmsg is written iff TCP_CMSG_INQ is set, not if ->msg_get_inq is the
> only thing set. That part is important.
>
> But yes, both need the data left.
I see, writing msg_inq if not requested is benign indeed. The inverse
is not true.
Ok. I do think it would be good to have the protocols consistent.
Simpler to reason about the behavior and intent long term.
> --
> Jens Axboe
next prev parent reply other threads:[~2025-12-18 21:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 14:59 [PATCHSET 0/2] Fix SO_INQ for af_unix Jens Axboe
2025-12-18 14:59 ` [PATCH 1/2] af_unix: don't post cmsg for SO_INQ unless explicitly asked for Jens Axboe
2025-12-18 20:35 ` Willem de Bruijn
2025-12-18 20:44 ` Jens Axboe
2025-12-18 21:15 ` Willem de Bruijn [this message]
2025-12-18 21:18 ` Jens Axboe
2025-12-18 14:59 ` [PATCH 2/2] af_unix: only post SO_INQ cmsg for non-error case 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.164466b751181@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=ju.orth@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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