* [PATCH v2 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
@ 2023-07-29 0:48 Kuniyuki Iwashima
2023-07-31 8:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Kuniyuki Iwashima @ 2023-07-29 0:48 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Breno Leitao, Kuniyuki Iwashima,
Kuniyuki Iwashima, netdev, Willem de Bruijn
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@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
---
v2:
* Add Reviewed-by
* s/implicitly/explicitly/ in changelog
* Replace Link with commits
v1: https://lore.kernel.org/netdev/20230720005456.88770-1-kuniyu@amazon.com/
---
net/core/sock.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index ab1e8d1bd5a1..4ad267ba0099 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1806,14 +1806,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;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
2023-07-29 0:48 [PATCH v2 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME) Kuniyuki Iwashima
@ 2023-07-31 8:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-31 8:20 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: davem, edumazet, kuba, pabeni, willemdebruijn.kernel, leitao,
kuni1840, netdev, willemb
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 28 Jul 2023 17:48:13 -0700 you wrote:
> 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:
>
> [...]
Here is the summary with links:
- [v2,net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
https://git.kernel.org/netdev/net-next/c/8936bf53a091
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-31 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-29 0:48 [PATCH v2 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME) Kuniyuki Iwashima
2023-07-31 8:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).