* [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
@ 2023-07-20 0:54 Kuniyuki Iwashima
2023-07-20 5:01 ` Eric Dumazet
2023-07-20 13:50 ` Willem de Bruijn
0 siblings, 2 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2023-07-20 0:54 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Breno Leitao, Kuniyuki Iwashima,
Kuniyuki Iwashima, netdev
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 struct sockaddr_XXX, which is cast from sockaddr_storage and has
a bigger size than fortified functions expect. (See Link)
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 implicitly.
Link: https://lore.kernel.org/netdev/20230720004410.87588-1-kuniyu@amazon.com/
Signed-off-by: Kuniyuki Iwashima <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] 4+ messages in thread
* Re: [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
2023-07-20 0:54 [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME) Kuniyuki Iwashima
@ 2023-07-20 5:01 ` Eric Dumazet
2023-07-20 13:50 ` Willem de Bruijn
1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-07-20 5:01 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
Breno Leitao, Kuniyuki Iwashima, netdev
On Thu, Jul 20, 2023 at 2:55 AM Kuniyuki Iwashima <kuniyu@amazon.com> 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 struct sockaddr_XXX, which is cast from sockaddr_storage and has
> a bigger size than fortified functions expect. (See Link)
>
> 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 implicitly.
>
> Link: https://lore.kernel.org/netdev/20230720004410.87588-1-kuniyu@amazon.com/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
2023-07-20 0:54 [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME) Kuniyuki Iwashima
2023-07-20 5:01 ` Eric Dumazet
@ 2023-07-20 13:50 ` Willem de Bruijn
2023-07-20 16:32 ` Kuniyuki Iwashima
1 sibling, 1 reply; 4+ messages in thread
From: Willem de Bruijn @ 2023-07-20 13:50 UTC (permalink / raw)
To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Willem de Bruijn, Breno Leitao, Kuniyuki Iwashima,
Kuniyuki Iwashima, netdev
Kuniyuki Iwashima 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 struct sockaddr_XXX, which is cast from sockaddr_storage and has
> a bigger size than fortified functions expect. (See Link)
>
> 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 implicitly.
explicitly
> Link: https://lore.kernel.org/netdev/20230720004410.87588-1-kuniyu@amazon.com/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME).
2023-07-20 13:50 ` Willem de Bruijn
@ 2023-07-20 16:32 ` Kuniyuki Iwashima
0 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2023-07-20 16:32 UTC (permalink / raw)
To: willemdebruijn.kernel
Cc: davem, edumazet, kuba, kuni1840, kuniyu, leitao, netdev, pabeni
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Thu, 20 Jul 2023 09:50:46 -0400
> Kuniyuki Iwashima 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 struct sockaddr_XXX, which is cast from sockaddr_storage and has
> > a bigger size than fortified functions expect. (See Link)
> >
> > 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 implicitly.
>
> explicitly
Will fix in v2, thanks!
>
> > Link: https://lore.kernel.org/netdev/20230720004410.87588-1-kuniyu@amazon.com/
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
>
> Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-20 16:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 0:54 [PATCH v1 net-next] net: Use sockaddr_storage for getsockopt(SO_PEERNAME) Kuniyuki Iwashima
2023-07-20 5:01 ` Eric Dumazet
2023-07-20 13:50 ` Willem de Bruijn
2023-07-20 16:32 ` Kuniyuki Iwashima
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).