Re: [PATCH v2 net-next 6/9] af_unix: Move SOCK_PASS{CRED,PIDFD,SEC} to struct sock.

From
Kuniyuki Iwashima <hidden>
Date
2025-05-13 03:18:53
Reply to
Willem de Bruijn, 2025-05-13
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Mon, 12 May 2025 22:44:04 -0400
Kuniyuki Iwashima wrote:
quoted
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Mon, 12 May 2025 15:20:54 -0400
quoted
Kuniyuki Iwashima wrote:
quoted
As explained in the next patch, SO_PASSRIGHTS would have a problem
if we assigned a corresponding bit to socket->flags, so it must be
managed in struct sock.

Mixing socket->flags and sk->sk_flags for similar options will look
confusing, and sk->sk_flags does not have enough space on 32bit system.

Also, as mentioned in commit 16e572626961 ("af_unix: dont send
SCM_CREDENTIALS by default"), SOCK_PASSCRED and SOCK_PASSPID handling
is known to be slow, and managing the flags in struct socket cannot
avoid that for embryo sockets.

Let's move SOCK_PASS{CRED,PIDFD,SEC} to struct sock.

While at it, other SOCK_XXX flags in net.h are grouped as enum.

Signed-off-by: Kuniyuki Iwashima <redacted>
quoted
diff --git a/net/core/sock.c b/net/core/sock.c
index 1ab59efbafc5..9540cbe3d83e 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1224,19 +1224,19 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 		if (!sk_may_scm_recv(sk))
 			return -EOPNOTSUPP;
 
-		assign_bit(SOCK_PASSSEC, &sock->flags, valbool);
+		sk->sk_scm_security = valbool;
Is it safe to switch from atomic to non-atomic updates?

Reads and writes can race. Especially given that these are bit stores, so RMW.
Exactly, will move them down after sockopt_lock_sock().
So all reads in the datapath are with the socket locked? Okay, that
was not immediately obvious to me. If respinning, please add a
comment.
Sure, will add a comment.
Thread (23 messages) 23 messages, 3 authors, last reply 2025-05-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help