Netdev List
 help / color / mirror / Atom feed
* [PATCH net] af_unix: return 0 for SIOCATMARK on listeners
@ 2026-11-27 16:04 Dickson Wu via B4 Relay
  2026-11-29  7:00 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-27 16:04 UTC (permalink / raw)
  To: netdev
  Cc: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] af_unix: return 0 for SIOCATMARK on listeners
  2026-11-27 16:04 [PATCH net] af_unix: return 0 for SIOCATMARK on listeners Dickson Wu via B4 Relay
@ 2026-11-29  7:00 ` Kuniyuki Iwashima
  0 siblings, 0 replies; 2+ messages in thread
From: Kuniyuki Iwashima @ 2026-11-29  7:00 UTC (permalink / raw)
  To: Dickson Wu
  Cc: netdev, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn

On Fri, 27 Nov 2026 16:04:41 +0000, Dickson Wu wrote:
> 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.

not worth a conflict.

pw-bot: rejected

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29  7:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 16:04 [PATCH net] af_unix: return 0 for SIOCATMARK on listeners Dickson Wu via B4 Relay
2026-11-29  7:00 ` Kuniyuki Iwashima

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox