From: Dickson Wu via B4 Relay <devnull+dickson.wu.certik.com@kernel.org>
To: netdev@vger.kernel.org
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Willem de Bruijn <willemb@google.com>
Subject: [PATCH net] af_unix: return 0 for SIOCATMARK on listeners
Date: Fri, 27 Nov 2026 16:04:41 +0000 [thread overview]
Message-ID: <20261127-unix-atmark2-v1-1-d164028cdae7@certik.com> (raw)
From: Dickson Wu <dickson.wu@certik.com>
AF_UNIX listeners cannot receive out-of-band data, but SIOCATMARK
currently peeks at sk_receive_queue. That queue contains connection
requests, and unix_accept() can dequeue and free its head under
sk_receive_queue.lock without taking u->iolock. As a result, SIOCATMARK
can read the freed skb.
Take u->iolock and the state lock in stream receive order. Return 0
for TCP_LISTEN, and keep both locks over the receive-queue inspection.
This prevents a concurrent listen() transition between the state check
and the queue access.
Fixes: e400cfa38bb0 ("af_unix: Fix wrong ioctl(SIOCATMARK) when consumed OOB skb is at the head.")
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
This is the listener case left after d119775f2bad ("af_unix: Reject
SIOCATMARK on non-stream sockets"). The earlier queue-lock proposal
for the same lifetime problem was redirected toward rejecting
unsupported sockets:
https://lore.kernel.org/netdev/f6cbbc8da90e95584847b5ceb60aae830d1631c2.1775731983.git.wangjiexun2025@gmail.com/
net-next 387f48167305 ("af_unix: Remove MSG_OOB.") removes SIOCATMARK
along with AF_UNIX OOB, so this is only for net and stable.
Tested under UML with KASAN as uid 65534 with no capabilities: one
thread loops SIOCATMARK on a listener while others connect and accept.
Stock 7.3.6 and a mainline snapshot hit a slab-use-after-free in
unix_ioctl() (freed by unix_accept()) within 30-45 s, as does the patch
reverted. With the patch, 300 s runs (about 24M ioctls and 36k accepts
on 7.3.6) were clean. A second test races listen() against SIOCATMARK
on the same socket: 20/20 clean. tools/testing/selftests/net/af_unix
msg_oob passed 60/60. A reproducer is available if it helps.
This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.
net/unix/af_unix.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 91c1d6cad497..1ba12617d55a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -3344,6 +3344,10 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
return -EOPNOTSUPP;
mutex_lock(&u->iolock);
+ unix_state_lock(sk);
+
+ if (sk->sk_state == TCP_LISTEN)
+ goto out_unlock;
skb = skb_peek(&sk->sk_receive_queue);
if (skb) {
@@ -3358,6 +3362,8 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
answ = 1;
}
+out_unlock:
+ unix_state_unlock(sk);
mutex_unlock(&u->iolock);
err = put_user(answ, (int __user *)arg);
--
2.43.0
next reply other threads:[~2026-11-27 20:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:04 Dickson Wu via B4 Relay [this message]
2026-11-29 7:00 ` [PATCH net] af_unix: return 0 for SIOCATMARK on listeners Kuniyuki Iwashima
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=20261127-unix-atmark2-v1-1-d164028cdae7@certik.com \
--to=devnull+dickson.wu.certik.com@kernel.org \
--cc=davem@davemloft.net \
--cc=dickson.wu@certik.com \
--cc=edumazet@kernel.org \
--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