diff mbox series

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

Message ID 20230719084415.1378696-1-leitao@debian.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: Use _K_SS_MAXSIZE instead of absolute value | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1348 this patch: 1348
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1371 this patch: 1371
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Breno Leitao July 19, 2023, 8:44 a.m. UTC
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@debian.org>
---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kuniyuki Iwashima July 19, 2023, 5:04 p.m. UTC | #1
From: Breno Leitao <leitao@debian.org>
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@debian.org>
> ---
>  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
Breno Leitao July 19, 2023, 5:18 p.m. UTC | #2
On Wed, Jul 19, 2023 at 10:04:45AM -0700, Kuniyuki Iwashima wrote:
> From: Breno Leitao <leitao@debian.org>
> 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@debian.org>
> > ---
> >  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.

Not really, in fact. I was reading this code, and I found this
discussion a while ago, where I got the idea:

https://lore.kernel.org/lkml/20140930.005925.995989898229686123.davem@davemloft.net/
Kuniyuki Iwashima July 19, 2023, 5:30 p.m. UTC | #3
From: Breno Leitao <leitao@debian.org>
Date: Wed, 19 Jul 2023 10:18:49 -0700
> On Wed, Jul 19, 2023 at 10:04:45AM -0700, Kuniyuki Iwashima wrote:
> > From: Breno Leitao <leitao@debian.org>
> > 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@debian.org>
> > > ---
> > >  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.
> 
> Not really, in fact. I was reading this code, and I found this
> discussion a while ago, where I got the idea:
> 
> https://lore.kernel.org/lkml/20140930.005925.995989898229686123.davem@davemloft.net/

I got it, but I prefer using struct sockaddr_storage as done in
other places.

  $ grep -rn sockaddr_storage net/

Also, there would be some situations where we must cast each
family-specific address back to sockaddr_storage for fortified
library.

Then, it makes more sense to use sockaddr_storage rather than
_K_SS_MAXSIZE.
Breno Leitao July 20, 2023, 9:29 a.m. UTC | #4
On Wed, Jul 19, 2023 at 10:30:17AM -0700, Kuniyuki Iwashima wrote:
> From: Breno Leitao <leitao@debian.org>
> Date: Wed, 19 Jul 2023 10:18:49 -0700
> > On Wed, Jul 19, 2023 at 10:04:45AM -0700, Kuniyuki Iwashima wrote:
> > > From: Breno Leitao <leitao@debian.org>
> > > 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@debian.org>
> > > > ---
> > > >  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.
> > 
> > Not really, in fact. I was reading this code, and I found this
> > discussion a while ago, where I got the idea:
> > 
> > https://lore.kernel.org/lkml/20140930.005925.995989898229686123.davem@davemloft.net/
> 
> I got it, but I prefer using struct sockaddr_storage as done in
> other places.
> 
>   $ grep -rn sockaddr_storage net/
> 
> Also, there would be some situations where we must cast each
> family-specific address back to sockaddr_storage for fortified
> library.
> 
> Then, it makes more sense to use sockaddr_storage rather than
> _K_SS_MAXSIZE.

Agree, that is a better fix. Thanks for working on it!
diff mbox series

Patch

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];
 
 		lv = sock->ops->getname(sock, (struct sockaddr *)address, 2);
 		if (lv < 0)