Patch "net: Use sockaddr_storage for getsockopt(SO_PEERNAME)." has been added to the 6.5-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: Use sockaddr_storage for getsockopt(SO_PEERNAME).

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-use-sockaddr_storage-for-getsockopt-so_peername.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8678c1ca9368c023232df7a3ff1a32ef29e4f693
Author: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>
Date:   Fri Jul 28 17:48:13 2023 -0700

    net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
    
    [ Upstream commit 8936bf53a091ad6a34b480c22002f1cb2422ab38 ]
    
    Commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") started
    applying strict rules to standard string functions.
    
    It does not work well with conventional socket code around each protocol-
    specific sockaddr_XXX struct, which is cast from sockaddr_storage and has
    a bigger size than fortified functions expect.  See these commits:
    
     commit 06d4c8a80836 ("af_unix: Fix fortify_panic() in unix_bind_bsd().")
     commit ecb4534b6a1c ("af_unix: Terminate sun_path when bind()ing pathname socket.")
     commit a0ade8404c3b ("af_packet: Fix warning of fortified memcpy() in packet_getname().")
    
    We must cast the protocol-specific address back to sockaddr_storage
    to call such functions.
    
    However, in the case of getsockaddr(SO_PEERNAME), the rationale is a bit
    unclear as the buffer is defined by char[128] which is the same size as
    sockaddr_storage.
    
    Let's use sockaddr_storage explicitly.
    
    Signed-off-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>
    Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>
    Reviewed-by: Willem de Bruijn <willemb@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/core/sock.c b/net/core/sock.c
index 29c6cb030818b..eef27812013a4 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1824,14 +1824,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 
 	case SO_PEERNAME:
 	{
-		char address[128];
+		struct sockaddr_storage address;
 
-		lv = sock->ops->getname(sock, (struct sockaddr *)address, 2);
+		lv = sock->ops->getname(sock, (struct sockaddr *)&address, 2);
 		if (lv < 0)
 			return -ENOTCONN;
 		if (lv < len)
 			return -EINVAL;
-		if (copy_to_sockptr(optval, address, len))
+		if (copy_to_sockptr(optval, &address, len))
 			return -EFAULT;
 		goto lenout;
 	}



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux