Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

af_unix: don't post cmsg for SO_INQ unless explicitly asked for

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 a cmsg if u->recvmsg_inq is set.

Additionally, mirror how TCP handles inquiry handling in that it should
only be done for a successful return. This makes the logic for the two
identical.

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>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/07adc0c2-2c3b-4d08-8af1-1c466a40b6a8@kernel.dk
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jens Axboe and committed by
Paolo Abeni
4d144297 3387a7ad

+8 -3
+8 -3
net/unix/af_unix.c
··· 2904 2904 unsigned int last_len; 2905 2905 struct unix_sock *u; 2906 2906 int copied = 0; 2907 + bool do_cmsg; 2907 2908 int err = 0; 2908 2909 long timeo; 2909 2910 int target; ··· 2930 2929 2931 2930 u = unix_sk(sk); 2932 2931 2932 + do_cmsg = READ_ONCE(u->recvmsg_inq); 2933 + if (do_cmsg) 2934 + msg->msg_get_inq = 1; 2933 2935 redo: 2934 2936 /* Lock the socket to prevent queue disordering 2935 2937 * while sleeps in memcpy_tomsg ··· 3092 3088 if (msg) { 3093 3089 scm_recv_unix(sock, msg, &scm, flags); 3094 3090 3095 - if (READ_ONCE(u->recvmsg_inq) || msg->msg_get_inq) { 3091 + if (msg->msg_get_inq && (copied ?: err) >= 0) { 3096 3092 msg->msg_inq = READ_ONCE(u->inq_len); 3097 - put_cmsg(msg, SOL_SOCKET, SCM_INQ, 3098 - sizeof(msg->msg_inq), &msg->msg_inq); 3093 + if (do_cmsg) 3094 + put_cmsg(msg, SOL_SOCKET, SCM_INQ, 3095 + sizeof(msg->msg_inq), &msg->msg_inq); 3099 3096 } 3100 3097 } else { 3101 3098 scm_destroy(&scm);