]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
af_unix: Move !sunaddr case in unix_dgram_sendmsg().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Fri, 13 Dec 2024 11:08:44 +0000 (20:08 +0900)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 17 Dec 2024 11:08:28 +0000 (12:08 +0100)
When other is NULL in unix_dgram_sendmsg(), we check if sunaddr
is NULL before looking up a receiver socket.

There are three paths going through the check, but it's always
false for 2 out of the 3 paths: the first socket lookup and the
second 'goto restart'.

The condition can be true for the first 'goto restart' only when
SOCK_DEAD is flagged for the socket found with msg->msg_name.

Let's move the check to the single appropriate path.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/unix/af_unix.c

index 07d6fba99a7c4fcd1f5ab678a415af5b0eb368ed..111f953849901eadc0eb4b8f1b59a6ddeb7e402f 100644 (file)
@@ -2046,11 +2046,6 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
 
 restart:
        if (!other) {
-               if (!sunaddr) {
-                       err = -ECONNRESET;
-                       goto out_free;
-               }
-
                other = unix_find_other(sock_net(sk), sunaddr, msg->msg_namelen,
                                        sk->sk_type);
                if (IS_ERR(other)) {
@@ -2105,6 +2100,9 @@ restart_locked:
                        err = -ECONNREFUSED;
                } else {
                        unix_state_unlock(sk);
+
+                       if (!sunaddr)
+                               err = -ECONNRESET;
                }
 
                other = NULL;