Skip to contentSkip to conversation

net: inet_diag: always export IPV6_V6ONLY sockopt

PATCH Superseded Phil Sutter 3 participants 6 messages Jul 9, 2015 – Jul 11, 2015

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

PATCH 1/1 net: inet_diag: always export IPV6_V6ONLY sockopt

Reconsidering my commit 20462155 "net: inet_diag: export IPV6_V6ONLY sockopt", I am not happy with the limitations it causes for socket analysing code in userspace. Exporting the value only if it is set makes it hard for userspace to decide whether the option is not set or the kernel does not support exporting the option at all.

Quoted 1 line

From an auditor's perspective, the interesting question for AF_INET6

sockets is: "Does it NOT have IPV6_V6ONLY set?" Because it is the unexpected case. This patch allows to answer this question reliably.

---
 net/ipv4/inet_diag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv4/inet_diag.c +1 -2
index 9bc2667..e622d2e 100644
@@ -152,8 +152,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
 
-		if (ipv6_only_sock(sk) &&
-		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+		if (nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
 			goto errout;
 	}
 #endif
Signature · 1 line
2.1.2
#1 lore raw
Quoted 21 lines · Phil Sutter

Reconsidering my commit 20462155 "net: inet_diag: export IPV6_V6ONLY sockopt", I am not happy with the limitations it causes for socket analysing code in userspace. Exporting the value only if it is set makes it hard for userspace to decide whether the option is not set or the kernel does not support exporting the option at all.

From an auditor's perspective, the interesting question for AF_INET6 sockets is: "Does it NOT have IPV6_V6ONLY set?" Because it is the unexpected case. This patch allows to answer this question reliably.

---
 net/ipv4/inet_diag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv4/inet_diag.c +0 -0
index 9bc2667..e622d2e 100644

net/ipv4/inet_diag.c int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, · line 158

Quoted 9 lines
net/ipv4/inet_diag.c +1 -2
@@ -152,8 +152,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
 
-		if (ipv6_only_sock(sk) &&
-		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+		if (nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
 			goto errout;
 	}
 #endif

Okay, I guess you don't dump millions of sockets.

Can you remind me why this attribute is useful for non listening sockets ?

It looks you are interested to know if a _listener_ is v6 only or not.

#2 lore raw
Quoted 25 lines · Eric Dumazet
Quoted 24 lines · Phil Sutter

Reconsidering my commit 20462155 "net: inet_diag: export IPV6_V6ONLY sockopt", I am not happy with the limitations it causes for socket analysing code in userspace. Exporting the value only if it is set makes it hard for userspace to decide whether the option is not set or the kernel does not support exporting the option at all.

From an auditor's perspective, the interesting question for AF_INET6 sockets is: "Does it NOT have IPV6_V6ONLY set?" Because it is the unexpected case. This patch allows to answer this question reliably.

---
 net/ipv4/inet_diag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv4/inet_diag.c +0 -0
index 9bc2667..e622d2e 100644
@@ -152,8 +152,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
 
Quoted 8 lines

net/ipv4/inet_diag.c int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, · line 158

Quoted 6 lines
net/ipv4/inet_diag.c +1 -2
-		if (ipv6_only_sock(sk) &&
-		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+		if (nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
 			goto errout;
 	}
 #endif

Okay, I guess you don't dump millions of sockets.

I hope not, although I don't know what tools other than ss use inet_diag.

Quoted 2 lines

Can you remind me why this attribute is useful for non listening sockets ?

Indeed, it isn't.

Quoted 1 line

It looks you are interested to know if a _listener_ is v6 only or not.

Is it possible to select that in a generic way? If I didn't misread the code, 'ss -l' filters them out locally. It looks like sk->sk_state can be used to determine that, but it seems to be used for TCP states only? Or is the value 10 (TCP_LISTEN) used for e.g. UDP as well?

Thanks, Phil

#3 lore raw
Quoted 4 lines · Phil Sutter

Is it possible to select that in a generic way? If I didn't misread the code, 'ss -l' filters them out locally. It looks like sk->sk_state can be used to determine that, but it seems to be used for TCP states only? Or is the value 10 (TCP_LISTEN) used for e.g. UDP as well?

You could specifically filter TCP_LISTEN | TCP_CLOSE

Like in :

net/ipv4/inet_diag.c +2 -2
index 9bc26677058e..c3b1f3a0f4cf 100644
@@ -152,8 +152,8 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
 
-		if (ipv6_only_sock(sk) &&
-		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+		if (((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
+		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
 			goto errout;
 	}
 #endif
#4 lore raw

PATCH v2 1/1 net: inet_diag: always export IPV6_V6ONLY sockopt for listening sockets

Reconsidering my commit 20462155 "net: inet_diag: export IPV6_V6ONLY sockopt", I am not happy with the limitations it causes for socket analysing code in userspace. Exporting the value only if it is set makes it hard for userspace to decide whether the option is not set or the kernel does not support exporting the option at all.

Quoted 1 line

From an auditor's perspective, the interesting question for listening

AF_INET6 sockets is: "Does it NOT have IPV6_V6ONLY set?" Because it is the unexpected case. This patch allows to answer this question reliably.

---
Changes since v1:
- Export the value only for listening sockets, as suggested by Eric Dumazet.
- Adjusted commit message accordingly.

---
 net/ipv4/inet_diag.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/inet_diag.c +2 -2
index 9bc2667..c3b1f3a 100644
@@ -152,8 +152,8 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
 
-		if (ipv6_only_sock(sk) &&
-		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+		if (((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
+		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
 			goto errout;
 	}
 #endif
Signature · 1 line
2.1.2
maintainer Applied
#5 lore raw

Re: [PATCH v2] net: inet_diag: always export IPV6_V6ONLY sockopt for listening sockets

From: Phil Sutter <[email protected]>
Date: Fri, 10 Jul 2015 11:39:57 +0200

Quoted 6 lines

Reconsidering my commit 20462155 "net: inet_diag: export IPV6_V6ONLY sockopt", I am not happy with the limitations it causes for socket analysing code in userspace. Exporting the value only if it is set makes it hard for userspace to decide whether the option is not set or the kernel does not support exporting the option at all.

Quoted 6 lines

From an auditor's perspective, the interesting question for listening AF_INET6 sockets is: "Does it NOT have IPV6_V6ONLY set?" Because it is the unexpected case. This patch allows to answer this question reliably.

Applied, thanks.