* [PATCH 6.12.y 1/9] net: dropreason: Gather SOCKET_ drop reasons.
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 2/9] af_unix: Set drop reason in unix_release_sock() Heiko Stuebner
` (8 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@amazon.com>
[ Upstream commit 454d402481d45af79ee7eea7e64bce02bbbe9766 ]
The following patch adds a new drop reason starting with
the SOCKET_ prefix.
Let's gather the existing SOCKET_ reasons.
Note that the order is not part of uAPI.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250116053441.5758-2-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
include/net/dropreason-core.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 02e7be19b042..76311b3ebfc8 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -6,9 +6,10 @@
#define DEFINE_DROP_REASON(FN, FNe) \
FN(NOT_SPECIFIED) \
FN(NO_SOCKET) \
+ FN(SOCKET_FILTER) \
+ FN(SOCKET_RCVBUFF) \
FN(PKT_TOO_SMALL) \
FN(TCP_CSUM) \
- FN(SOCKET_FILTER) \
FN(UDP_CSUM) \
FN(NETFILTER_DROP) \
FN(OTHERHOST) \
@@ -18,7 +19,6 @@
FN(UNICAST_IN_L2_MULTICAST) \
FN(XFRM_POLICY) \
FN(IP_NOPROTO) \
- FN(SOCKET_RCVBUFF) \
FN(PROTO_MEM) \
FN(TCP_AUTH_HDR) \
FN(TCP_MD5NOTFOUND) \
@@ -124,12 +124,14 @@ enum skb_drop_reason {
* 3) no valid child socket during 3WHS process
*/
SKB_DROP_REASON_NO_SOCKET,
+ /** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
+ SKB_DROP_REASON_SOCKET_FILTER,
+ /** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
+ SKB_DROP_REASON_SOCKET_RCVBUFF,
/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
SKB_DROP_REASON_PKT_TOO_SMALL,
/** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */
SKB_DROP_REASON_TCP_CSUM,
- /** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
- SKB_DROP_REASON_SOCKET_FILTER,
/** @SKB_DROP_REASON_UDP_CSUM: UDP checksum error */
SKB_DROP_REASON_UDP_CSUM,
/** @SKB_DROP_REASON_NETFILTER_DROP: dropped by netfilter */
@@ -160,8 +162,6 @@ enum skb_drop_reason {
SKB_DROP_REASON_XFRM_POLICY,
/** @SKB_DROP_REASON_IP_NOPROTO: no support for IP protocol */
SKB_DROP_REASON_IP_NOPROTO,
- /** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
- SKB_DROP_REASON_SOCKET_RCVBUFF,
/**
* @SKB_DROP_REASON_PROTO_MEM: proto memory limitation, such as
* udp packet drop out of udp_memory_allocated.
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 2/9] af_unix: Set drop reason in unix_release_sock().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 1/9] net: dropreason: Gather SOCKET_ drop reasons Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 3/9] af_unix: Set drop reason in manage_oob() Heiko Stuebner
` (7 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@amazon.com>
[ Upstream commit c32f0bd7d4838982c6724fca0da92353f27c6f88 ]
unix_release_sock() is called when the last refcnt of struct file
is released.
Let's define a new drop reason SKB_DROP_REASON_SOCKET_CLOSE and
set it for kfree_skb() in unix_release_sock().
# echo 1 > /sys/kernel/tracing/events/skb/kfree_skb/enable
# python3
>>> from socket import *
>>> s1, s2 = socketpair(AF_UNIX)
>>> s1.send(b'hello world')
>>> s2.close()
# cat /sys/kernel/tracing/trace_pipe
...
python3-280 ... kfree_skb: ... protocol=0 location=unix_release_sock+0x260/0x420 reason: SOCKET_CLOSE
To be precise, unix_release_sock() is also called for a new child
socket in unix_stream_connect() when something fails, but the new
sk does not have skb in the recv queue then and no event is logged.
Note that only tcp_inbound_ao_hash() uses a similar drop reason,
SKB_DROP_REASON_TCP_CLOSE, and this can be generalised later.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250116053441.5758-3-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
include/net/dropreason-core.h | 3 +++
net/unix/af_unix.c | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 76311b3ebfc8..06912797712a 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -6,6 +6,7 @@
#define DEFINE_DROP_REASON(FN, FNe) \
FN(NOT_SPECIFIED) \
FN(NO_SOCKET) \
+ FN(SOCKET_CLOSE) \
FN(SOCKET_FILTER) \
FN(SOCKET_RCVBUFF) \
FN(PKT_TOO_SMALL) \
@@ -124,6 +125,8 @@ enum skb_drop_reason {
* 3) no valid child socket during 3WHS process
*/
SKB_DROP_REASON_NO_SOCKET,
+ /** @SKB_DROP_REASON_SOCKET_CLOSE: socket is close()d */
+ SKB_DROP_REASON_SOCKET_CLOSE,
/** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
SKB_DROP_REASON_SOCKET_FILTER,
/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 4682cc59b7a7..4caff11068c3 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -731,8 +731,8 @@ static void unix_release_sock(struct sock *sk, int embrion)
if (state == TCP_LISTEN)
unix_release_sock(skb->sk, 1);
- /* passed fds are erased in the kfree_skb hook */
- kfree_skb(skb);
+ /* passed fds are erased in the kfree_skb hook */
+ kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
}
if (path.dentry)
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 3/9] af_unix: Set drop reason in manage_oob().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 1/9] net: dropreason: Gather SOCKET_ drop reasons Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 2/9] af_unix: Set drop reason in unix_release_sock() Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 4/9] af_unix: Set drop reason in unix_stream_read_skb() Heiko Stuebner
` (6 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@amazon.com>
[ Upstream commit 533643b091dd6e246d57caf81e6892fa9cbb1cc9 ]
AF_UNIX SOCK_STREAM socket supports MSG_OOB.
When OOB data is sent to a socket, recv() will break at that point.
If the next recv() does not have MSG_OOB, the normal data following
the OOB data is returned.
Then, the OOB skb is dropped.
Let's define a new drop reason for that case in manage_oob().
# echo 1 > /sys/kernel/tracing/events/skb/kfree_skb/enable
# python3
>>> from socket import *
>>> s1, s2 = socketpair(AF_UNIX)
>>> s1.send(b'a', MSG_OOB)
>>> s1.send(b'b')
>>> s2.recv(2)
b'b'
# cat /sys/kernel/tracing/trace_pipe
...
python3-223 ... kfree_skb: ... location=unix_stream_read_generic+0x59e/0xc20 reason: UNIX_SKIP_OOB
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250116053441.5758-6-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
include/net/dropreason-core.h | 6 ++++++
net/unix/af_unix.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 06912797712a..07826c85d31c 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -9,6 +9,7 @@
FN(SOCKET_CLOSE) \
FN(SOCKET_FILTER) \
FN(SOCKET_RCVBUFF) \
+ FN(UNIX_SKIP_OOB) \
FN(PKT_TOO_SMALL) \
FN(TCP_CSUM) \
FN(UDP_CSUM) \
@@ -131,6 +132,11 @@ enum skb_drop_reason {
SKB_DROP_REASON_SOCKET_FILTER,
/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */
SKB_DROP_REASON_SOCKET_RCVBUFF,
+ /**
+ * @SKB_DROP_REASON_UNIX_SKIP_OOB: Out-Of-Band data is skipped by
+ * recv() without MSG_OOB so dropped.
+ */
+ SKB_DROP_REASON_UNIX_SKIP_OOB,
/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
SKB_DROP_REASON_PKT_TOO_SMALL,
/** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 4caff11068c3..e0f5a9382149 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2714,7 +2714,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
spin_unlock(&sk->sk_receive_queue.lock);
consume_skb(read_skb);
- kfree_skb(unread_skb);
+ kfree_skb_reason(unread_skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
return skb;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 4/9] af_unix: Set drop reason in unix_stream_read_skb().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (2 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 3/9] af_unix: Set drop reason in manage_oob() Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 5/9] af_unix/scm: fix whitespace errors Heiko Stuebner
` (5 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@amazon.com>
[ Upstream commit bace4b468049a558295a0f59460fcb51e28f8fde ]
unix_stream_read_skb() is called when BPF SOCKMAP reads some data
from a socket in the map.
SOCKMAP does not support MSG_OOB, and reading OOB results in a drop.
Let's set drop reasons respectively.
* SOCKET_CLOSE : the socket in SOCKMAP was close()d
* UNIX_SKIP_OOB : OOB was read from the socket in SOCKMAP
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250116053441.5758-7-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
net/unix/af_unix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e0f5a9382149..1d426f5b2580 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2743,7 +2743,7 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
if (sock_flag(sk, SOCK_DEAD)) {
unix_state_unlock(sk);
- kfree_skb(skb);
+ kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
return -ECONNRESET;
}
@@ -2757,7 +2757,7 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
unix_state_unlock(sk);
if (drop) {
- kfree_skb(skb);
+ kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
return -EAGAIN;
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 5/9] af_unix/scm: fix whitespace errors
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (3 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 4/9] af_unix: Set drop reason in unix_stream_read_skb() Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 6/9] af_unix: Don't hold unix_state_lock() in __unix_dgram_recvmsg() Heiko Stuebner
` (4 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Alexander Mikhalitsyn,
linux-kernel, netdev, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Leon Romanovsky,
Arnd Bergmann, Christian Brauner, Lennart Poettering,
Luca Boccassi, David Rheinsberg, Heiko Stuebner
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
[ Upstream commit 2b9996417e4ec231c91818f9ea8107ae62ef75ad ]
Fix whitespace/formatting errors.
Cc: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Luca Boccassi <bluca@debian.org>
Cc: David Rheinsberg <david@readahead.eu>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Link: https://lore.kernel.org/20250703222314.309967-5-aleksandr.mikhalitsyn@canonical.com
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
include/net/scm.h | 4 ++--
net/unix/af_unix.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/net/scm.h b/include/net/scm.h
index 0d35c7c77a74..ea85f7427a19 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -69,7 +69,7 @@ static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_co
static __inline__ void scm_set_cred(struct scm_cookie *scm,
struct pid *pid, kuid_t uid, kgid_t gid)
{
- scm->pid = get_pid(pid);
+ scm->pid = get_pid(pid);
scm->creds.pid = pid_vnr(pid);
scm->creds.uid = uid;
scm->creds.gid = gid;
@@ -78,7 +78,7 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm,
static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
{
put_pid(scm->pid);
- scm->pid = NULL;
+ scm->pid = NULL;
}
static __inline__ void scm_destroy(struct scm_cookie *scm)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 1d426f5b2580..c64d8ee0ede4 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1887,7 +1887,7 @@ static void unix_destruct_scm(struct sk_buff *skb)
struct scm_cookie scm;
memset(&scm, 0, sizeof(scm));
- scm.pid = UNIXCB(skb).pid;
+ scm.pid = UNIXCB(skb).pid;
if (UNIXCB(skb).fp)
unix_detach_fds(&scm, skb);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 6/9] af_unix: Don't hold unix_state_lock() in __unix_dgram_recvmsg().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (4 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 5/9] af_unix/scm: fix whitespace errors Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 7/9] af_unix: Don't check SOCK_DEAD in unix_stream_read_skb() Heiko Stuebner
` (3 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Willem de Bruijn,
Jakub Kicinski, Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@google.com>
[ Upstream commit b429a5ad19cb4efe63d18388a2a4deebcba742c6 ]
When __skb_try_recv_datagram() returns NULL in __unix_dgram_recvmsg(),
we hold unix_state_lock() unconditionally.
This is because SOCK_SEQPACKET sk needs to return EOF in case its peer
has been close()d concurrently.
This behaviour totally depends on the timing of the peer's close() and
reading sk->sk_shutdown, and taking the lock does not play a role.
Let's drop the lock from __unix_dgram_recvmsg() and use READ_ONCE().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250702223606.1054680-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
net/unix/af_unix.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index c64d8ee0ede4..f50049ea54a5 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2463,12 +2463,10 @@ int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
&err, &timeo, last));
if (!skb) { /* implies iolock unlocked */
- unix_state_lock(sk);
/* Signal EOF on disconnected non-blocking SEQPACKET socket. */
if (sk->sk_type == SOCK_SEQPACKET && err == -EAGAIN &&
- (sk->sk_shutdown & RCV_SHUTDOWN))
+ (READ_ONCE(sk->sk_shutdown) & RCV_SHUTDOWN))
err = 0;
- unix_state_unlock(sk);
goto out;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 7/9] af_unix: Don't check SOCK_DEAD in unix_stream_read_skb().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (5 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 6/9] af_unix: Don't hold unix_state_lock() in __unix_dgram_recvmsg() Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 8/9] af_unix: Don't use skb_recv_datagram() " Heiko Stuebner
` (2 subsequent siblings)
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@google.com>
[ Upstream commit 772f01049c4b722b28b3f7025b4996379f127ebf ]
unix_stream_read_skb() checks SOCK_DEAD only when the dequeued skb is
OOB skb.
unix_stream_read_skb() is called for a SOCK_STREAM socket in SOCKMAP
when data is sent to it.
The function is invoked via sk_psock_verdict_data_ready(), which is
set to sk->sk_data_ready().
During sendmsg(), we check if the receiver has SOCK_DEAD, so there
is no point in checking it again later in ->read_skb().
Also, unix_read_skb() for SOCK_DGRAM does not have the test either.
Let's remove the SOCK_DEAD test in unix_stream_read_skb().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250702223606.1054680-3-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
net/unix/af_unix.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f50049ea54a5..a18a4b022970 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2737,14 +2737,6 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
if (unlikely(skb == READ_ONCE(u->oob_skb))) {
bool drop = false;
- unix_state_lock(sk);
-
- if (sock_flag(sk, SOCK_DEAD)) {
- unix_state_unlock(sk);
- kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
- return -ECONNRESET;
- }
-
spin_lock(&sk->sk_receive_queue.lock);
if (likely(skb == u->oob_skb)) {
WRITE_ONCE(u->oob_skb, NULL);
@@ -2752,8 +2744,6 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
}
spin_unlock(&sk->sk_receive_queue.lock);
- unix_state_unlock(sk);
-
if (drop) {
kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
return -EAGAIN;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 8/9] af_unix: Don't use skb_recv_datagram() in unix_stream_read_skb().
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (6 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 7/9] af_unix: Don't check SOCK_DEAD in unix_stream_read_skb() Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-17 17:29 ` [PATCH 6.12.y 9/9] af_unix: Drop all SCM attributes for SOCKMAP Heiko Stuebner
2026-07-19 15:00 ` [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Sasha Levin
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@google.com>
[ Upstream commit d0aac85449dec992bb8dc2503f2cb9e94ef436db ]
unix_stream_read_skb() calls skb_recv_datagram() with MSG_DONTWAIT,
which is mostly equivalent to sock_error(sk) + skb_dequeue().
In the following patch, we will add a new field to cache the number
of bytes in the receive queue. Then, we want to avoid introducing
atomic ops in the fast path, so we will reuse the receive queue lock.
As a preparation for the change, let's not use skb_recv_datagram()
in unix_stream_read_skb().
Note that sock_error() is now moved out of the u->iolock mutex as
the mutex does not synchronise the peer's close() at all.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250702223606.1054680-4-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
net/unix/af_unix.c | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index a18a4b022970..f1e81843c1b0 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2720,6 +2720,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
{
+ struct sk_buff_head *queue = &sk->sk_receive_queue;
struct unix_sock *u = unix_sk(sk);
struct sk_buff *skb;
int err;
@@ -2727,30 +2728,34 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
if (unlikely(READ_ONCE(sk->sk_state) != TCP_ESTABLISHED))
return -ENOTCONN;
- mutex_lock(&u->iolock);
- skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
- mutex_unlock(&u->iolock);
- if (!skb)
+ err = sock_error(sk);
+ if (err)
return err;
-#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
- if (unlikely(skb == READ_ONCE(u->oob_skb))) {
- bool drop = false;
+ mutex_lock(&u->iolock);
+ spin_lock(&queue->lock);
- spin_lock(&sk->sk_receive_queue.lock);
- if (likely(skb == u->oob_skb)) {
- WRITE_ONCE(u->oob_skb, NULL);
- drop = true;
- }
- spin_unlock(&sk->sk_receive_queue.lock);
+ skb = __skb_dequeue(queue);
+ if (!skb) {
+ spin_unlock(&queue->lock);
+ mutex_unlock(&u->iolock);
+ return -EAGAIN;
+ }
- if (drop) {
- kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
- return -EAGAIN;
- }
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
+ if (skb == u->oob_skb) {
+ WRITE_ONCE(u->oob_skb, NULL);
+ spin_unlock(&queue->lock);
+ mutex_unlock(&u->iolock);
+
+ kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
+ return -EAGAIN;
}
#endif
+ spin_unlock(&queue->lock);
+ mutex_unlock(&u->iolock);
+
return recv_actor(sk, skb);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 6.12.y 9/9] af_unix: Drop all SCM attributes for SOCKMAP.
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (7 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 8/9] af_unix: Don't use skb_recv_datagram() " Heiko Stuebner
@ 2026-07-17 17:29 ` Heiko Stuebner
2026-07-19 15:00 ` [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Sasha Levin
9 siblings, 0 replies; 12+ messages in thread
From: Heiko Stuebner @ 2026-07-17 17:29 UTC (permalink / raw)
To: stable
Cc: heiko, quentin.schulz, kuniyu, kuniyu, Xingyu Jin, Jakub Kicinski,
Heiko Stuebner
From: Kuniyuki Iwashima <kuniyu@google.com>
[ Upstream commit 965dc93481d1b80d341bdd16c27b16fe197175ee ]
SOCKMAP can hide inflight fd from AF_UNIX GC.
When a socket in SOCKMAP receives skb with inflight fd,
sk_psock_verdict_data_ready() looks up the mapped socket and
enqueue skb to its psock->ingress_skb.
Since neither the old nor the new GC can inspect the psock
queue, the hidden skb leaks the inflight sockets. Note that
this cannot be detected via kmemleak because inflight sockets
are linked to a global list.
In addition, SOCKMAP redirect breaks the Tarjan-based GC's
assumption that unix_edge.successor is always alive, which
is no longer true once skb is redirected, resulting in
use-after-free below. [0]
Moreover, SOCKMAP does not call scm_stat_del() properly,
so unix_show_fdinfo() could report an incorrect fd count.
sk_msg_recvmsg() does not support any SCM attributes in the
first place.
Let's drop all SCM attributes before passing skb to the
SOCKMAP layer.
[0]:
BUG: KASAN: slab-use-after-free in unix_del_edges (net/unix/garbage.c:118 net/unix/garbage.c:181 net/unix/garbage.c:251)
Read of size 8 at addr ffff888125362670 by task kworker/56:1/496
CPU: 56 UID: 0 PID: 496 Comm: kworker/56:1 Not tainted 7.0.0-rc7-00263-gb9d8b856689d #3 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-debian-1.17.0-1 04/01/2014
Workqueue: events sk_psock_backlog
Call Trace:
<TASK>
dump_stack_lvl (lib/dump_stack.c:122)
print_report (mm/kasan/report.c:379)
kasan_report (mm/kasan/report.c:597)
unix_del_edges (net/unix/garbage.c:118 net/unix/garbage.c:181 net/unix/garbage.c:251)
unix_destroy_fpl (net/unix/garbage.c:317)
unix_destruct_scm (./include/net/scm.h:80 ./include/net/scm.h:86 net/unix/af_unix.c:1976)
sk_psock_backlog (./include/linux/skbuff.h:?)
process_scheduled_works (kernel/workqueue.c:?)
worker_thread (kernel/workqueue.c:?)
kthread (kernel/kthread.c:438)
ret_from_fork (arch/x86/kernel/process.c:164)
ret_from_fork_asm (arch/x86/entry/entry_64.S:258)
</TASK>
Allocated by task 955:
kasan_save_track (mm/kasan/common.c:58 mm/kasan/common.c:78)
__kasan_slab_alloc (mm/kasan/common.c:369)
kmem_cache_alloc_noprof (mm/slub.c:4539)
sk_prot_alloc (net/core/sock.c:2240)
sk_alloc (net/core/sock.c:2301)
unix_create1 (net/unix/af_unix.c:1099)
unix_create (net/unix/af_unix.c:1169)
__sock_create (net/socket.c:1606)
__sys_socketpair (net/socket.c:1811)
__x64_sys_socketpair (net/socket.c:1863 net/socket.c:1860 net/socket.c:1860)
do_syscall_64 (arch/x86/entry/syscall_64.c:?)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
Freed by task 496:
kasan_save_track (mm/kasan/common.c:58 mm/kasan/common.c:78)
kasan_save_free_info (mm/kasan/generic.c:587)
__kasan_slab_free (mm/kasan/common.c:287)
kmem_cache_free (mm/slub.c:6165)
__sk_destruct (net/core/sock.c:2282 net/core/sock.c:2384)
sk_psock_destroy (./include/net/sock.h:?)
process_scheduled_works (kernel/workqueue.c:?)
worker_thread (kernel/workqueue.c:?)
kthread (kernel/kthread.c:438)
ret_from_fork (arch/x86/kernel/process.c:164)
ret_from_fork_asm (arch/x86/entry/entry_64.S:258)
Fixes: c63829182c37 ("af_unix: Implement ->psock_update_sk_prot()")
Fixes: 77462de14a43 ("af_unix: Add read_sock for stream socket types")
Reported-by: Xingyu Jin <xingyuj@google.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260415184830.3988432-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
---
net/unix/af_unix.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f1e81843c1b0..23d94a08e481 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1884,16 +1884,19 @@ static void unix_peek_fds(struct scm_cookie *scm, struct sk_buff *skb)
static void unix_destruct_scm(struct sk_buff *skb)
{
- struct scm_cookie scm;
+ struct scm_cookie scm = {};
+
+ swap(scm.pid, UNIXCB(skb).pid);
- memset(&scm, 0, sizeof(scm));
- scm.pid = UNIXCB(skb).pid;
if (UNIXCB(skb).fp)
unix_detach_fds(&scm, skb);
- /* Alas, it calls VFS */
- /* So fscking what? fput() had been SMP-safe since the last Summer */
scm_destroy(&scm);
+}
+
+static void unix_wfree(struct sk_buff *skb)
+{
+ unix_destruct_scm(skb);
sock_wfree(skb);
}
@@ -1909,7 +1912,7 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
if (scm->fp && send_fds)
err = unix_attach_fds(scm, skb);
- skb->destructor = unix_destruct_scm;
+ skb->destructor = unix_wfree;
return err;
}
@@ -1970,6 +1973,13 @@ static void scm_stat_del(struct sock *sk, struct sk_buff *skb)
}
}
+static void unix_orphan_scm(struct sock *sk, struct sk_buff *skb)
+{
+ scm_stat_del(sk, skb);
+ unix_destruct_scm(skb);
+ skb->destructor = sock_wfree;
+}
+
/*
* Send AF_UNIX data.
*/
@@ -2556,10 +2566,16 @@ static int unix_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
int err;
mutex_lock(&u->iolock);
+
skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
- mutex_unlock(&u->iolock);
- if (!skb)
+ if (!skb) {
+ mutex_unlock(&u->iolock);
return err;
+ }
+
+ unix_orphan_scm(sk, skb);
+
+ mutex_unlock(&u->iolock);
return recv_actor(sk, skb);
}
@@ -2754,6 +2770,9 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
#endif
spin_unlock(&queue->lock);
+
+ unix_orphan_scm(sk, skb);
+
mutex_unlock(&u->iolock);
return recv_actor(sk, skb);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP"
2026-07-17 17:29 [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Heiko Stuebner
` (8 preceding siblings ...)
2026-07-17 17:29 ` [PATCH 6.12.y 9/9] af_unix: Drop all SCM attributes for SOCKMAP Heiko Stuebner
@ 2026-07-19 15:00 ` Sasha Levin
2026-07-21 15:35 ` Heiko Stübner
9 siblings, 1 reply; 12+ messages in thread
From: Sasha Levin @ 2026-07-19 15:00 UTC (permalink / raw)
To: stable; +Cc: Sasha Levin, heiko, quentin.schulz, kuniyu, kuniyu,
Heiko Stuebner
> This series backports the "Drop all SCM attributes for SOCKMAP" for
> af_unix onto 6.12.
Queued the series for 6.12, and picked up the fix for 6.18 as well,
thanks.
6.6.y/6.1.y/5.15.y still lack the fix, so backports along the same
lines would be welcome there too if you'd like to extend coverage.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP"
2026-07-19 15:00 ` [PATCH 6.12.y 0/9] Backport "af_unix: Drop all SCM attributes for SOCKMAP" Sasha Levin
@ 2026-07-21 15:35 ` Heiko Stübner
0 siblings, 0 replies; 12+ messages in thread
From: Heiko Stübner @ 2026-07-21 15:35 UTC (permalink / raw)
To: stable, Sasha Levin
Cc: Sasha Levin, quentin.schulz, kuniyu, kuniyu, Heiko Stuebner
Hi Sasha,
Am Sonntag, 19. Juli 2026, 17:00:23 Mitteleuropäische Sommerzeit schrieb Sasha Levin:
> > This series backports the "Drop all SCM attributes for SOCKMAP" for
> > af_unix onto 6.12.
>
> Queued the series for 6.12, and picked up the fix for 6.18 as well,
> thanks.
>
> 6.6.y/6.1.y/5.15.y still lack the fix, so backports along the same
> lines would be welcome there too if you'd like to extend coverage.
sadly, that is way out of scope for me.
I did look at 6.6 to see if that would be easily doable, but the number of
(required) changes adds up quickly, so I stopped quite fast.
6.12 is the LTS I _need_ to look at, but hopefully someone requiring
6.6, 6.1 or 5.15 will step up.
Heiko
^ permalink raw reply [flat|nested] 12+ messages in thread