Skip to contentSkip to conversation

net: Use _K_SS_MAXSIZE instead of absolute value

PATCH In review Breno Leitao 2 participants 5 messages Jul 19, 2023 – Jul 20, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Use _K_SS_MAXSIZE instead of absolute value

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).

---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +1 -1
index 9370fd50aa2c..58b6f00197d6 100644
@@ -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)
Signature · 1 line
2.34.1
#1 lore raw

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 01:44:12 -0700

Quoted 16 lines

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).

---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +0 -0
index 9370fd50aa2c..58b6f00197d6 100644

net/core/sock.c int sk_getsockopt(struct sock *sk, int level, int optname, · line 1818

Quoted 5 lines
net/core/sock.c +1 -1
@@ -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!

Quoted 5 lines
net/core/sock.c +0 -0
 		lv = sock->ops->getname(sock, (struct sockaddr *)address, 2);
 		if (lv < 0)
Signature · 1 line
2.34.1
#2 lore raw
Quoted 19 lines · Kuniyuki Iwashima

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 01:44:12 -0700

Quoted 17 lines

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).

---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +0 -0
index 9370fd50aa2c..58b6f00197d6 100644
@@ -1815,7 +1815,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 
Quoted 7 lines

net/core/sock.c int sk_getsockopt(struct sock *sk, int level, int optname, · line 1818

Quoted 4 lines
net/core/sock.c +1 -1
 	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/[email protected]/

#3 lore raw

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 10:18:49 -0700

Quoted 28 lines · Kuniyuki Iwashima
Quoted 19 lines

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 01:44:12 -0700

Quoted 17 lines

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).

---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +0 -0
index 9370fd50aa2c..58b6f00197d6 100644
@@ -1815,7 +1815,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 
Quoted 7 lines

net/core/sock.c int sk_getsockopt(struct sock *sk, int level, int optname, · line 1818

Quoted 4 lines
net/core/sock.c +1 -1
 	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.

Quoted 4 lines

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/[email protected]/

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.

#4 lore raw
Quoted 38 lines · Kuniyuki Iwashima

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 10:18:49 -0700

Quoted 28 lines · Kuniyuki Iwashima
Quoted 19 lines

From: Breno Leitao <[email protected]>
Date: Wed, 19 Jul 2023 01:44:12 -0700

Quoted 17 lines

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).

---
 net/core/sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +0 -0
index 9370fd50aa2c..58b6f00197d6 100644
@@ -1815,7 +1815,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 
Quoted 7 lines

net/core/sock.c int sk_getsockopt(struct sock *sk, int level, int optname, · line 1818

Quoted 4 lines
net/core/sock.c +1 -1
 	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.

Quoted 4 lines

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/[email protected]/

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

Quoted 8 lines
  $ 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!