mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
[ Upstream commit8936bf53a0] Commitdf8fc4e934("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: commit06d4c8a808("af_unix: Fix fortify_panic() in unix_bind_bsd().") commitecb4534b6a("af_unix: Terminate sun_path when bind()ing pathname socket.") commita0ade8404c("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@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
ab0ae0af0a
commit
d5372a1f0c
@@ -1774,14 +1774,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
|
|||||||
|
|
||||||
case SO_PEERNAME:
|
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)
|
if (lv < 0)
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
if (lv < len)
|
if (lv < len)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (copy_to_sockptr(optval, address, len))
|
if (copy_to_sockptr(optval, &address, len))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
goto lenout;
|
goto lenout;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user