Re: [PATCH net-next] net: Use _K_SS_MAXSIZE instead of absolute value

From: Kuniyuki Iwashima
Date: Wed Jul 19 2023 - 13:05:08 EST


From: Breno Leitao <leitao@xxxxxxxxxx>
Date: Wed, 19 Jul 2023 01:44:12 -0700
> Looking at sk_getsockopt function, it is unclear why 128 is a magical
> number.
>
> Use the proper macro, so it becomes clear to understand what the value
> mean, and get a reference where it is coming from (user-exported API).
>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> net/core/sock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 9370fd50aa2c..58b6f00197d6 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1815,7 +1815,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
>
> case SO_PEERNAME:
> {
> - char address[128];
> + char address[_K_SS_MAXSIZE];

I guess you saw a bug caught by the fortified memcpy(), but this
doesn't fix it properly.

I'll post a series soon that fix the issue and another realted one.

Thanks!


>
> lv = sock->ops->getname(sock, (struct sockaddr *)address, 2);
> if (lv < 0)
> --
> 2.34.1