net: inet_diag: always export IPV6_V6ONLY sockopt
Subsystems (2)
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
@@ -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
Quoted 21 lines · Phil Sutter
Reconsidering my commit 20462155 "net:
inet_diag: exportIPV6_V6ONLYsockopt", 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_INET6sockets is: "Does it NOT haveIPV6_V6ONLYset?" Because it is the unexpected case. This patch allows to answer this question reliably.Signed-off-by Phil Sutter <[email protected]>Cc Eric Dumazet <[email protected]>--- net/ipv4/inet_diag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/ipv4/inet_diag.c +0
-0
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.
Quoted 25 lines · Eric Dumazet
Quoted 24 lines · Phil Sutter
Reconsidering my commit 20462155 "net:
inet_diag: exportIPV6_V6ONLYsockopt", 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_INET6sockets is: "Does it NOT haveIPV6_V6ONLYset?" Because it is the unexpected case. This patch allows to answer this question reliably.Signed-off-by Phil Sutter <[email protected]>Cc Eric Dumazet <[email protected]>--- net/ipv4/inet_diag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/ipv4/inet_diag.c +0
-0@@ -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
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_statecan 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
@@ -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
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
@@ -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
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: exportIPV6_V6ONLYsockopt", 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_INET6sockets is: "Does it NOT haveIPV6_V6ONLYset?" Because it is the unexpected case. This patch allows to answer this question reliably.Signed-off-by Phil Sutter <[email protected]>Cc Eric Dumazet <[email protected]>
Applied, thanks.