af_unix: Allow passing cred for embryo without SO_PASSCRED/SO_PASSPIDFD.
Subsystems (3)
PATCH 1/1 af_unix: Allow passing cred for embryo without SO_PASSCRED/SO_PASSPIDFD.
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled SO_PASSCRED and SO_PASSPIDFD.
Now, the credentials are added to skb only when configured by the sender or the listener.
However, as reported in the link below, it caused a regression for some programs that assume credentials are included in every skb, but sometimes not now.
The only problematic scenario would be that a socket starts listening before setting the option. Then, there will be 2 types of non-small race window, where a client can send skb without credentials, which the peer receives as an "invalid" message (and aborts the connection it seems ?):
Client Server
------ ------
s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect()
s2.send() <-- w/o cred
s1.setsockopt(SO_PASS{CRED,PIDFD})
s2.send() <-- w/ cred
or
Client Server
------ ------
s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect()
s2.send() <-- w/o cred
s3, _ = s1.accept() <-- Inherit cred options
s2.send() <-- w/o cred but not set yet
s3.setsockopt(SO_PASS{CRED,PIDFD})
s2.send() <-- w/ cred
It's unfortunate that buggy programs depend on the behaviour, but let's restore the previous behaviour.
--- net/unix/af_unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/unix/af_unix.c +2 -1
@@ -1971,7 +1971,8 @@ static void unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,if (UNIXCB (skb).pid)return ; -if (unix_may_passcred (sk) ||unix_may_passcred (other)) { +if (unix_may_passcred (sk) ||unix_may_passcred (other) || + !other->sk_socket) {UNIXCB (skb).pid =get_pid (task_tgid (current));current_uid_gid (&UNIXCB (skb).uid, &UNIXCB (skb).gid); }
Signature · 1 line
2.49.0
Quoted 67 lines · Kuniyuki Iwashima
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled
SO_PASSCREDandSO_PASSPIDFD.Now, the credentials are added to skb only when configured by the sender or the listener.
However, as reported in the link below, it caused a regression for some programs that assume credentials are included in every skb, but sometimes not now.
The only problematic scenario would be that a socket starts listening before setting the option. Then, there will be 2 types of non-small race window, where a client can send skb without credentials, which the peer receives as an "invalid" message (and aborts the connection it seems ?):
Client Server
------ ------s1.listen() <-- No SO_PASS{CRED,PIDFD}
s2.connect()
s2.send()<-- w/o cred
s1.setsockopt(SO_PASS{CRED,PIDFD})
s2.send()<-- w/ credor
Client Server
------ ------s1.listen() <-- No SO_PASS{CRED,PIDFD}
s2.connect()
s2.send()<-- w/o cred
s3, _ =s1.accept()<-- Inherit cred options
s2.send()<-- w/o cred but not set yet
s3.setsockopt(SO_PASS{CRED,PIDFD})
s2.send()<-- w/ credIt's unfortunate that buggy programs depend on the behaviour, but let's restore the previous behaviour.
Fixes 3f84d577b79d ("af_unix: Inherit sk_flags at connect().")Reported-by Jacek Łuczak <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/unix/af_unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/unix/af_unix.c +2
-1@@ -1971,7 +1971,8 @@ static void unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,if (UNIXCB (skb).pid)return ; -if (unix_may_passcred (sk) ||unix_may_passcred (other)) { +if (unix_may_passcred (sk) ||unix_may_passcred (other) || + !other->sk_socket) {UNIXCB (skb).pid =get_pid (task_tgid (current));current_uid_gid (&UNIXCB (skb).uid, &UNIXCB (skb).gid); }Signature · 1 line
2.49.0
Em 11/06/2025 17:27, Kuniyuki Iwashima escreveu:
Quoted 40 lines
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled
SO_PASSCREDandSO_PASSPIDFD.Now, the credentials are added to skb only when configured by the sender or the listener.
However, as reported in the link below, it caused a regression for some programs that assume credentials are included in every skb, but sometimes not now.
The only problematic scenario would be that a socket starts listening before setting the option. Then, there will be 2 types of non-small race window, where a client can send skb without credentials, which the peer receives as an "invalid" message (and aborts the connection it seems ?):
Client Server ------ ------ s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect() s2.send() <-- w/o cred s1.setsockopt(SO_PASS{CRED,PIDFD}) s2.send() <-- w/ credor
Client Server ------ ------ s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect() s2.send() <-- w/o cred s3, _ = s1.accept() <-- Inherit cred options s2.send() <-- w/o cred but not set yet s3.setsockopt(SO_PASS{CRED,PIDFD}) s2.send() <-- w/ cred
Quoted 7 lines
It's unfortunate that buggy programs depend on the behaviour, but let's restore the previous behaviour.
Fixes 3f84d577b79d ("af_unix: Inherit sk_flags at connect().")Reported-by Jacek Łuczak <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Quoted 56 lines · Kuniyuki Iwashima
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled
SO_PASSCREDandSO_PASSPIDFD.Now, the credentials are added to skb only when configured by the sender or the listener.
However, as reported in the link below, it caused a regression for some programs that assume credentials are included in every skb, but sometimes not now.
The only problematic scenario would be that a socket starts listening before setting the option. Then, there will be 2 types of non-small race window, where a client can send skb without credentials, which the peer receives as an "invalid" message (and aborts the connection it seems ?):
Client Server ------ ------ s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect() s2.send() <-- w/o cred s1.setsockopt(SO_PASS{CRED,PIDFD}) s2.send() <-- w/ credor
Client Server ------ ------ s1.listen() <-- No SO_PASS{CRED,PIDFD} s2.connect() s2.send() <-- w/o cred s3, _ = s1.accept() <-- Inherit cred options s2.send() <-- w/o cred but not set yet s3.setsockopt(SO_PASS{CRED,PIDFD}) s2.send() <-- w/ credIt's unfortunate that buggy programs depend on the behaviour, but let's restore the previous behaviour.
Fixes 3f84d577b79d ("af_unix: Inherit sk_flags at connect().")Reported-by Jacek Łuczak <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/unix/af_unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/unix/af_unix.c +0
-0
net/unix/af_unix.c static void unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk, · line 1978
Quoted 9 lines
net/unix/af_unix.c +2
-1@@ -1971,7 +1971,8 @@ static void unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk,if (UNIXCB (skb).pid)return ; -if (unix_may_passcred (sk) ||unix_may_passcred (other)) { +if (unix_may_passcred (sk) ||unix_may_passcred (other) || + !other->sk_socket) {UNIXCB (skb).pid =get_pid (task_tgid (current));current_uid_gid (&UNIXCB (skb).uid, &UNIXCB (skb).gid); }
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 11 Jun 2025 13:27:35 -0700 you wrote:
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled
SO_PASSCREDandSO_PASSPIDFD.Now, the credentials are added to skb only when configured by the sender or the listener.
[...]
Here is the summary with links:
- [v1,net] af_unix: Allow passing cred for embryo without SO_PASSCRED/SO_PASSPIDFD.
https://git.kernel.org/netdev/net/c/43fb2b30eea7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 37 lines · Kuniyuki Iwashima
From: Kuniyuki Iwashima <[email protected]>
Before the cited commit, the kernel unconditionally embedded SCM credentials to skb for embryo sockets even when both the sender and listener disabled
SO_PASSCREDandSO_PASSPIDFD.Now, the credentials are added to skb only when configured by the sender or the listener.
However, as reported in the link below, it caused a regression for some programs that assume credentials are included in every skb, but sometimes not now.
The only problematic scenario would be that a socket starts listening before setting the option. Then, there will be 2 types of non-small race window, where a client can send skb without credentials, which the peer receives as an "invalid" message (and aborts the connection it seems ?):
Client Server
------ ------s1.listen() <-- No SO_PASS{CRED,PIDFD}
s2.connect()
s2.send()<-- w/o cred
s1.setsockopt(SO_PASS{CRED,PIDFD})
s2.send()<-- w/ credor
Client Server
------ ------s1.listen() <-- No SO_PASS{CRED,PIDFD}
s2.connect()
s2.send()<-- w/o cred
s3, _ =s1.accept()<-- Inherit cred options
s2.send()<-- w/o cred but not set yet
Quoted 5 lines
s3.setsockopt(SO_PASS{CRED,PIDFD})
s2.send()<-- w/ credIt's unfortunate that buggy programs depend on the behaviour, but let's restore the previous behaviour.
For the record, this one fixes the wlroots and Xorg crashes on USB-C DisplayPort Altmode hotplug that I hit consistently with 6.16-rc1 on machines like the Lenovo ThinkPad X13s and T14s.
Quoted 4 lines
Fixes 3f84d577b79d ("af_unix: Inherit sk_flags at connect().")Reported-by Jacek Łuczak <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>
Johan