lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241206052607.1197-15-kuniyu@amazon.com>
Date: Fri, 6 Dec 2024 14:26:06 +0900
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
	<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
	<pabeni@...hat.com>
CC: Kuniyuki Iwashima <kuniyu@...zon.com>, Kuniyuki Iwashima
	<kuni1840@...il.com>, <netdev@...r.kernel.org>
Subject: [PATCH v1 net-next 14/15] af_unix: Remove sk_locked logic in unix_dgram_sendmsg().

If the receiver socket is not connected to the sender socket and the
receiver's queue is full in unix_dgram_sendmsg(), we lock the both
sockets and retry.

The logic adds one unlikely check to the sane path and complicates the
entire function, but it's not worth that.

Let's remove the sk_locked variable and simplify the logic and the error
path.

Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
---
 net/unix/af_unix.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 629e7a81178e..594c7428f22d 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1967,7 +1967,6 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 	struct scm_cookie scm;
 	struct sk_buff *skb;
 	int data_len = 0;
-	int sk_locked;
 	long timeo;
 	int err;
 
@@ -2059,7 +2058,6 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 	}
 
 restart:
-	sk_locked = 0;
 	unix_state_lock(other);
 restart_locked:
 
@@ -2082,8 +2080,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 			goto out_sock_put;
 		}
 
-		if (!sk_locked)
-			unix_state_lock(sk);
+		unix_state_lock(sk);
 
 		if (unix_peer(sk) == other) {
 			unix_peer(sk) = NULL;
@@ -2136,27 +2133,21 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 			goto restart;
 		}
 
-		if (!sk_locked) {
-			unix_state_unlock(other);
-			unix_state_double_lock(sk, other);
-		}
+		unix_state_unlock(other);
+		unix_state_double_lock(sk, other);
 
 		if (unix_peer(sk) != other ||
-		    unix_dgram_peer_wake_me(sk, other)) {
+		    unix_dgram_peer_wake_me(sk, other))
 			err = -EAGAIN;
-			sk_locked = 1;
+
+		unix_state_unlock(sk);
+
+		if (err)
 			goto out_unlock;
-		}
 
-		if (!sk_locked) {
-			sk_locked = 1;
-			goto restart_locked;
-		}
+		goto restart_locked;
 	}
 
-	if (unlikely(sk_locked))
-		unix_state_unlock(sk);
-
 	if (sock_flag(other, SOCK_RCVTSTAMP))
 		__net_timestamp(skb);
 	maybe_add_creds(skb, sock, other);
@@ -2169,8 +2160,6 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 	return len;
 
 out_unlock:
-	if (sk_locked)
-		unix_state_unlock(sk);
 	unix_state_unlock(other);
 out_sock_put:
 	sock_put(other);
-- 
2.39.5 (Apple Git-154)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ