From: sashiko-bot@kernel.org
To: "Ishu Brar" <patches@brar.si>
Cc: sparclinux@vger.kernel.org
Subject: Re: [PATCH RFC net-next 1/2] af_unix: Add SO_MAX_DGRAM_QLEN for per-socket datagram queue length
Date: Thu, 03 Dec 2026 07:09:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-247266@kernel.org> (raw)
In-Reply-To: <20261202-af-unix-dgram-qlen-v1-1-043723f83d6d@brar.si>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] af_unix: non-atomic sk_max_ack_backlog update in
unix_setsockopt()
--
commit 823d8b4920f03f27df72c9003c7366a3f59c5428
Author: Ishu Brar <patches@brar.si>
af_unix: Add SO_MAX_DGRAM_QLEN for per-socket datagram queue length
This commit adds the SO_MAX_DGRAM_QLEN socket option to configure the
datagram receive queue length (sk_max_ack_backlog) per AF_UNIX SOCK_DGRAM
socket and wakes waiting senders when the limit is raised.
Link: https://github.com/uapi-group/kernel-features
Link: https://github.com/systemd/systemd/issues/45144
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index 53a5553bfb667..2afa958c8e2ba 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
[ ... ]
> @@ -988,6 +990,29 @@ static int unix_setsockopt(struct socket *sock, int level, int optname,
> WRITE_ONCE(u->scm_rights_notrunc, val);
> break;
>
> + case SO_MAX_DGRAM_QLEN: {
> + struct net *net = sock_net(sk);
> + u32 old;
> +
> + if (sk->sk_type != SOCK_DGRAM)
> + return -ENOPROTOOPT;
> +
> + if (val < 0)
> + return -EINVAL;
> +
> + if (val > READ_ONCE(net->unx.sysctl_max_dgram_qlen) &&
> + !sockopt_ns_capable(net->user_ns, CAP_NET_ADMIN))
> + return -EPERM;
> +
> + old = READ_ONCE(sk->sk_max_ack_backlog);
> + WRITE_ONCE(sk->sk_max_ack_backlog, val);
> +
> + /* Raising frees slots without a read: wake all senders. */
> + if (val > old)
> + wake_up_interruptible_all(&u->peer_wait);
> + break;
> + }
> +
> default:
> return -ENOPROTOOPT;
> }
[Severity: Medium]
Can concurrent SO_MAX_DGRAM_QLEN updates miss the wakeup on u->peer_wait?
unix_setsockopt() runs without holding a socket lock. If sk_max_ack_backlog
starts at 10 with 5 datagrams queued, a lowering call can take effect
between another call's READ_ONCE() and WRITE_ONCE():
CPU0 CPU1
unix_setsockopt(..., val = 8)
old = READ_ONCE(sk_max_ack_backlog)
/* old == 10 */
unix_setsockopt(..., val = 2)
WRITE_ONCE(sk_max_ack_backlog, 2)
unix_dgram_sendmsg()
/* qlen 5 > 2: sleeps on peer_wait */
WRITE_ONCE(sk_max_ack_backlog, 8)
if (val > old) /* 8 > 10 is false */
/* wakeup skipped */ <-- sender remains blocked
The queue limit ends at 8 with only 5 datagrams queued, leaving the sender
stalled in sendmsg() or poll() with slots available. Using xchg() to
update sk->sk_max_ack_backlog or serializing under unix_state_lock(sk)
(as unix_listen() does) would ensure old reflects the value actually
replaced.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-af-unix-dgram-qlen-v1-0-043723f83d6d@brar.si?part=1
next prev parent reply other threads:[~2026-12-03 7:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 7:09 [PATCH RFC net-next 0/2] af_unix: Per-socket datagram queue length Ishu Brar via B4 Relay
2026-12-02 7:09 ` Ishu Brar
2026-12-02 7:09 ` [PATCH RFC net-next 1/2] af_unix: Add SO_MAX_DGRAM_QLEN for per-socket " Ishu Brar via B4 Relay
2026-12-02 7:09 ` Ishu Brar
2026-12-03 7:09 ` sashiko-bot [this message]
2026-12-02 7:09 ` [PATCH RFC net-next 2/2] selftests: af_unix: Add test for SO_MAX_DGRAM_QLEN Ishu Brar
2026-12-02 7:09 ` Ishu Brar via B4 Relay
2026-12-03 7:09 ` sashiko-bot
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=sashiko-outbox-247266@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=patches@brar.si \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sparclinux@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.