net: extend INET_DIAG_INFO with information specific to TCP ULP
Subsystems (4)
cover net: extend INET_DIAG_INFO with information specific to TCP ULP
The current kernel does not provide any diagnostic tool, except getsockopt(TCP_ULP), to know more about TCP sockets that have an upper layer protocol (ULP) on top of them. This series extends the set of information exported by INET_DIAG_INFO, to include data that are specific to the ULP (and that might be meaningful for debug/testing purposes).
patch 1/2 extends INET_DIAG_INFO and allows knowing the ULP name for each TCP socket that has done setsockopt(TCP_ULP) successfully.
kernel TLS is the only TCP ULP user at the moment: patch 2/2 extends kTLS to let programs like 'ss' know the protocol version and the cipher in use.
Davide Caratti (2):
tcp: ulp: add functions to dump ulp-specific information
net: tls: export protocol version and cipher to socket diag
include/net/tcp.h | 3 +++ include/uapi/linux/inet_diag.h | 9 +++++++ include/uapi/linux/tls.h | 8 +++++++ net/ipv4/tcp_diag.c | 34 +++++++++++++++++++++++++-- net/tls/tls_main.c | 43 ++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH 1/2 tcp: ulp: add functions to dump ulp-specific information
currently, only getsockopt(TCP_ULP) can be invoked to know if a ULP is on top of a TCP socket. Extend idiag_get_aux() and idiag_get_aux_size(), introduced by commit b37e88407c1d ("inet_diag: allow protocols to provide additional data"), to report the ULP name and other information that can be made available by the ULP through optional functions.
Users having CAP_NET_ADMIN privileges will then be able to retrieve this information through inet_diag_handler, if they specify INET_DIAG_INFO in the request.
--- include/net/tcp.h | 3 +++ include/uapi/linux/inet_diag.h | 8 ++++++++ net/ipv4/tcp_diag.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-)
include/net/tcp.h +3 -0
@@ -2108,6 +2108,9 @@ struct tcp_ulp_ops {int (*init)(struct sock *sk);/* cleanup ulp */ void (*release)(struct sock *sk); +/* diagnostic */ +int (*get_info)(struct sock *sk,struct sk_buff *skb); +size_t (*get_info_size)(struct sock *sk);char name[TCP_ULP_NAME_MAX ];struct module *owner;
include/uapi/linux/inet_diag.h +8 -0
@@ -153,11 +153,19 @@ enum {INET_DIAG_BBRINFO ,/* request as INET_DIAG_VEGASINFO */ INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG , +INET_DIAG_ULP_INFO , __INET_DIAG_MAX, };#define INET_DIAG_MAX (__INET_DIAG_MAX - 1) +enum { +ULP_INFO_NAME , + __ULP_INFO_MAX, +}; + +#define ULP_INFO_MAX (__ULP_INFO_MAX - 1) +/* INET_DIAG_MEM */ struct inet_diag_meminfo {
net/ipv4/tcp_diag.c +32 -2
@@ -88,10 +88,12 @@ static int tcp_diag_put_md5sig(struct sk_buff *skb,static int tcp_diag_get_aux (struct sock *sk,bool net_admin,struct sk_buff *skb) { +struct inet_connection_sock *icsk =inet_csk (sk); +int err =0 ; +#ifdef CONFIG_TCP_MD5SIG if (net_admin) {struct tcp_md5sig_info *md5sig; -int err =0 ;rcu_read_lock (); md5sig =rcu_dereference (tcp_sk (sk)->md5sig_info);
@@ -103,11 +105,33 @@ static int tcp_diag_get_aux(struct sock *sk, bool net_admin, }#endif -return 0 ; +if (net_admin && icsk->icsk_ulp_ops) { +struct nlattr *nest; + + nest =nla_nest_start_noflag (skb,INET_DIAG_ULP_INFO ); +if (!nest) { + err = -EMSGSIZE ; + goto nla_failure; + } + err =nla_put_string (skb,ULP_INFO_NAME , + icsk->icsk_ulp_ops->name); +if (err <0 ) + goto nla_failure; +if (icsk->icsk_ulp_ops->get_info) + err = icsk->icsk_ulp_ops->get_info (sk, skb); +if (err <0 ) { +nla_failure: +nla_nest_cancel (skb, nest); +return err; + } +nla_nest_end (skb, nest); + } +return err; }static size_t tcp_diag_get_aux_size (struct sock *sk,bool net_admin) { +struct inet_connection_sock *icsk =inet_csk (sk);size_t size =0 ;#ifdef CONFIG_TCP_MD5SIG
@@ -128,6 +152,12 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) }#endif +if (net_admin && icsk->icsk_ulp_ops) { + size +=nla_total_size (0 )/* INET_DIAG_ULP_INFO */ + +nla_total_size (TCP_ULP_NAME_MAX );/* ULP_INFO_NAME */ +if (icsk->icsk_ulp_ops->get_info_size) + size += icsk->icsk_ulp_ops->get_info_size (sk); + }return size; }
Signature · 1 line
2.20.1
Re: [RFC PATCH net-next 1/2] tcp: ulp: add functions to dump ulp-specific information
Quoted 36 lines · Davide Caratti
currently, only
getsockopt(TCP_ULP)can be invoked to know if a ULP is on top of a TCP socket. Extendidiag_get_aux()andidiag_get_aux_size(), introduced by commitb37e88407c1d("inet_diag: allow protocols to provide additional data"), to report the ULP name and other information that can be made available by the ULP through optional functions.Users having
CAP_NET_ADMINprivileges will then be able to retrieve this information throughinet_diag_handler, if they specifyINET_DIAG_INFOin the request.Signed-off-by Davide Caratti <[email protected]>--- include/net/tcp.h | 3 +++ include/uapi/linux/inet_diag.h | 8 ++++++++ net/ipv4/tcp_diag.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-)include/net/tcp.h +3
-0@@ -2108,6 +2108,9 @@ struct tcp_ulp_ops {int (*init)(struct sock *sk);/* cleanup ulp */ void (*release)(struct sock *sk); +/* diagnostic */ +int (*get_info)(struct sock *sk,struct sk_buff *skb); +size_t (*get_info_size)(struct sock *sk);char name[TCP_ULP_NAME_MAX ];struct module *owner;include/uapi/linux/inet_diag.h +0
-0
include/uapi/linux/inet_diag.h enum { · line 162
Quoted 10 lines
include/uapi/linux/inet_diag.h +2
-0@@ -153,11 +153,19 @@ enum {INET_DIAG_BBRINFO ,/* request as INET_DIAG_VEGASINFO */ INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG , +INET_DIAG_ULP_INFO , __INET_DIAG_MAX, };#define INET_DIAG_MAX (__INET_DIAG_MAX - 1) +enum {
Value of 0 is commonly defined as UNSPEC (or NONE), so:
ULP_UNSPEC,
here. Also perhaps INET_ULP_..?
Quoted 33 lines
include/uapi/linux/inet_diag.h +6
-0+ULP_INFO_NAME , + __ULP_INFO_MAX, +}; + +#define ULP_INFO_MAX (__ULP_INFO_MAX - 1) +/* INET_DIAG_MEM */ struct inet_diag_meminfo {net/ipv4/tcp_diag.c +4
-2@@ -88,10 +88,12 @@ static int tcp_diag_put_md5sig(struct sk_buff *skb,static int tcp_diag_get_aux (struct sock *sk,bool net_admin,struct sk_buff *skb) { +struct inet_connection_sock *icsk =inet_csk (sk); +int err =0 ; +#ifdef CONFIG_TCP_MD5SIG if (net_admin) {struct tcp_md5sig_info *md5sig; -int err =0 ;rcu_read_lock (); md5sig =rcu_dereference (tcp_sk (sk)->md5sig_info);@@ -103,11 +105,33 @@ static int tcp_diag_get_aux(struct sock *sk, bool net_admin, }#endif -return 0 ; +if (net_admin && icsk->icsk_ulp_ops) {
net/ipv4/tcp_diag.c static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 118
Quoted 10 lines
net/ipv4/tcp_diag.c +10
-0+struct nlattr *nest; + + nest =nla_nest_start_noflag (skb,INET_DIAG_ULP_INFO ); +if (!nest) { + err = -EMSGSIZE ; + goto nla_failure; + } + err =nla_put_string (skb,ULP_INFO_NAME , + icsk->icsk_ulp_ops->name); +if (err <0 )
nit: nla_put_string() does not return positive non-zero codes
net/ipv4/tcp_diag.c static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 121
Quoted 3 lines
net/ipv4/tcp_diag.c +3
-0+ goto nla_failure; +if (icsk->icsk_ulp_ops->get_info) + err = icsk->icsk_ulp_ops->get_info (sk, skb);
And neither should this, probably.
net/ipv4/tcp_diag.c static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 129
Quoted 8 lines
net/ipv4/tcp_diag.c +8
-0+if (err <0 ) { +nla_failure: +nla_nest_cancel (skb, nest); +return err; + } +nla_nest_end (skb, nest); + } +return err;
So just return 0 here.
Quoted 9 lines
net/ipv4/tcp_diag.c +1
-0}static size_t tcp_diag_get_aux_size (struct sock *sk,bool net_admin) { +struct inet_connection_sock *icsk =inet_csk (sk);size_t size =0 ;#ifdef CONFIG_TCP_MD5SIG
net/ipv4/tcp_diag.c static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 156
Quoted 5 lines
net/ipv4/tcp_diag.c +2
-0@@ -128,6 +152,12 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) }#endif +if (net_admin && icsk->icsk_ulp_ops) { + size +=nla_total_size (0 )/* INET_DIAG_ULP_INFO */
^^^ not sure we want those multiple spaces here.
net/ipv4/tcp_diag.c static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 157
Quoted 1 line
net/ipv4/tcp_diag.c +1
-0+ +nla_total_size (TCP_ULP_NAME_MAX );/* ULP_INFO_NAME */
+ usually goes at the end of previous line
net/ipv4/tcp_diag.c static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 159
Quoted 2 lines
net/ipv4/tcp_diag.c +2
-0+if (icsk->icsk_ulp_ops->get_info_size) + size += icsk->icsk_ulp_ops->get_info_size (sk);
I don't know the diag code, is the socket locked at this point?
Quoted 4 lines
net/ipv4/tcp_diag.c +1
-0+ }return size; }
Re: [RFC PATCH net-next 1/2] tcp: ulp: add functions to dump ulp-specific information
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · Davide Caratti
currently, only
getsockopt(TCP_ULP)can be invoked to know if a ULP is on top of a TCP socket. Extendidiag_get_aux()andidiag_get_aux_size(), introduced by commitb37e88407c1d("inet_diag: allow protocols to provide additional data"), to report the ULP name and other information that can be made available by the ULP through optional functions.Users having
CAP_NET_ADMINprivileges will then be able to retrieve this information throughinet_diag_handler, if they specifyINET_DIAG_INFOin the request.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Davide Caratti <[email protected]>--- include/net/tcp.h | 3 +++ include/uapi/linux/inet_diag.h | 8 ++++++++ net/ipv4/tcp_diag.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-)
hi Jakub, thanks a lot for reviewing!
[...]
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/inet_diag.h +1
-0@@ -153,11 +153,19 @@ enum {INET_DIAG_BBRINFO ,/* request as INET_DIAG_VEGASINFO */ INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG , +INET_DIAG_ULP_INFO , __INET_DIAG_MAX, };#define INET_DIAG_MAX (__INET_DIAG_MAX - 1)
Quoted 7 lines
include/uapi/linux/inet_diag.h enum { · line 162
Quoted 1 line
include/uapi/linux/inet_diag.h +1
-0+enum {Value of 0 is commonly defined as UNSPEC (or NONE), so:
ULP_UNSPEC,here. Also perhaps
INET_ULP_..?
ok, will fix that in patch v1.
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/inet_diag.h +6
-0+ULP_INFO_NAME , + __ULP_INFO_MAX, +}; + +#define ULP_INFO_MAX (__ULP_INFO_MAX - 1) +/* INET_DIAG_MEM */
[...]
Quoted 4 lines
Quoted 4 lines
include/uapi/linux/inet_diag.h +0
-0@@ -103,11 +105,33 @@ static int tcp_diag_get_aux(struct sock *sk, bool net_admin, }#endif
Quoted 14 lines
include/uapi/linux/inet_diag.h static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 118
Quoted 12 lines
include/uapi/linux/inet_diag.h +11
-1-return 0 ; +if (net_admin && icsk->icsk_ulp_ops) { +struct nlattr *nest; + + nest =nla_nest_start_noflag (skb,INET_DIAG_ULP_INFO ); +if (!nest) { + err = -EMSGSIZE ; + goto nla_failure; + } + err =nla_put_string (skb,ULP_INFO_NAME , + icsk->icsk_ulp_ops->name); +if (err <0 )nit:
nla_put_string()does not return positive non-zero codes
so, I will replace the test above with
if (err)
Quoted 7 lines
include/uapi/linux/inet_diag.h static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 121
Quoted 3 lines
include/uapi/linux/inet_diag.h +3
-0+ goto nla_failure; +if (icsk->icsk_ulp_ops->get_info) + err = icsk->icsk_ulp_ops->get_info (sk, skb);And neither should this, probably.
include/uapi/linux/inet_diag.h static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 122
Quoted 1 line
include/uapi/linux/inet_diag.h +1
-0+if (err <0 ) {
same here.
Quoted 9 lines
include/uapi/linux/inet_diag.h static int tcp_diag_get_aux(struct sock *sk, bool net_admin, · line 129
Quoted 7 lines
include/uapi/linux/inet_diag.h +7
-0+nla_failure: +nla_nest_cancel (skb, nest); +return err; + } +nla_nest_end (skb, nest); + } +return err;So just return 0 here.
ok, I found comfortable with 'return err' because of the initialization at the beginning of the function (this patch extends the scope of 'err' to the whole function). But I'm not against return 0.
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/inet_diag.h +1
-0}static size_t tcp_diag_get_aux_size (struct sock *sk,bool net_admin) { +struct inet_connection_sock *icsk =inet_csk (sk);size_t size =0 ;#ifdef CONFIG_TCP_MD5SIG @@ -128,6 +152,12 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) }#endif
Quoted 8 lines
include/uapi/linux/inet_diag.h static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 156
Quoted 2 lines
include/uapi/linux/inet_diag.h +2
-0+if (net_admin && icsk->icsk_ulp_ops) { + size +=nla_total_size (0 )/* INET_DIAG_ULP_INFO */ ^^^ not sure we want those multiple spaces here.
include/uapi/linux/inet_diag.h static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 157
Quoted 1 line
include/uapi/linux/inet_diag.h +1
-0+ +nla_total_size (TCP_ULP_NAME_MAX );/* ULP_INFO_NAME */ + usually goes at the end of previous line
I took the inspiration from the caller of .idiag_get_aux_size(). But you are right, vxlan_get_size() has a better formatting: will fix that in patch v1.
Quoted 4 lines
include/uapi/linux/inet_diag.h static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 159
Quoted 2 lines
include/uapi/linux/inet_diag.h +2
-0+if (icsk->icsk_ulp_ops->get_info_size) + size += icsk->icsk_ulp_ops->get_info_size (sk);I don't know the diag code, is the socket locked at this point?
as far as I can see, it's not. Thanks a lot for noticing this!
anyway, I see a similar pattern for icsk_ca_ops: when we set the congestion control with do_tcp_setsockopt(), the socket is locked - but then, when 'ss' reads a diag request with INET_DIAG_CONG bit set, the value of icsk->icsk_ca_ops is accessed with READ_ONCE(), surrounded by rcu_read_{,un}lock().
Maybe it's sufficient to do something similar, and then the socket lock can be optionally taken within icsk_ulp_ops->get_info(), only in case we need to access members of sk that are protected with the socket lock?
Signature · 1 line
davide
Re: [RFC PATCH net-next 1/2] tcp: ulp: add functions to dump ulp-specific information
Quoted 7 lines · Davide Caratti
Quoted 4 lines
net/ipv4/tcp_diag.c static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) · line 159
Quoted 2 lines
net/ipv4/tcp_diag.c +2
-0+if (icsk->icsk_ulp_ops->get_info_size) + size += icsk->icsk_ulp_ops->get_info_size (sk);I don't know the diag code, is the socket locked at this point?
as far as I can see, it's not. Thanks a lot for noticing this!
Quoted 8 lines
anyway, I see a similar pattern for
icsk_ca_ops: when we set the congestion control withdo_tcp_setsockopt(), the socket is locked - but then, when 'ss' reads a diag request withINET_DIAG_CONGbit set, the value oficsk->icsk_ca_opsis accessed withREAD_ONCE(), surrounded by rcu_read_{,un}lock().Maybe it's sufficient to do something similar, and then the socket lock can be optionally taken within
icsk_ulp_ops->get_info(), only in case we need to access members of sk that are protected with the socket lock?
Sounds reasonable, we just need to keep that in mind as we extend TLS code do dump more information.
RFC PATCH 2/2 net: tls: export protocol version and cipher to socket diag
In reply to Davide CarattiWhen an application configures kernel TLS on top of a TCP socket, it's now possible for inet_diag_handler to collect information regarding the protocol version and the cipher, in case INET_DIAG_INFO is requested.
--- include/uapi/linux/inet_diag.h | 1 + include/uapi/linux/tls.h | 8 +++++++ net/tls/tls_main.c | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+)
include/uapi/linux/inet_diag.h +1 -0
@@ -161,6 +161,7 @@ enum {enum {ULP_INFO_NAME , +ULP_INFO_TLS , __ULP_INFO_MAX, };
include/uapi/linux/tls.h +8 -0
@@ -109,4 +109,12 @@ struct tls12_crypto_info_aes_ccm_128 { unsigned char rec_seq[TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE]; }; +enum { +TLS_INFO_VERSION , +TLS_INFO_CIPHER , + __TLS_INFO_MAX, +}; + +#define TLS_INFO_MAX (__TLS_INFO_MAX - 1) +#endif /* _UAPI_LINUX_TLS_H */
net/tls/tls_main.c +43 -0
61 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [RFC PATCH net-next 2/2] net: tls: export protocol version and cipher to socket diag
Quoted 28 lines · Davide Caratti
When an application configures kernel TLS on top of a TCP socket, it's now possible for
inet_diag_handlerto collect information regarding the protocol version and the cipher, in caseINET_DIAG_INFOis requested.Signed-off-by Davide Caratti <[email protected]>--- include/uapi/linux/inet_diag.h | 1 + include/uapi/linux/tls.h | 8 +++++++ net/tls/tls_main.c | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+)include/uapi/linux/inet_diag.h +1
-0@@ -161,6 +161,7 @@ enum {enum {ULP_INFO_NAME , +ULP_INFO_TLS , __ULP_INFO_MAX, };include/uapi/linux/tls.h +0
-0
include/uapi/linux/tls.h struct tls12_crypto_info_aes_ccm_128 { · line 112
Quoted 4 lines
include/uapi/linux/tls.h +1
-0@@ -109,4 +109,12 @@ struct tls12_crypto_info_aes_ccm_128 {unsigned char rec_seq[TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE ]; }; +enum {
USPEC
include/uapi/linux/tls.h struct tls12_crypto_info_aes_ccm_128 { · line 114
Quoted 2 lines
include/uapi/linux/tls.h +2
-0+TLS_INFO_VERSION , + TLS_INFO_CIPHER,
We need some indication of the directions in which kTLS is active (none, rx, tx, rx/tx).
Also perhaps could you add TLS_SW vs TLS_HW etc. ? :)
include/uapi/linux/tls.h struct tls12_crypto_info_aes_ccm_128 { · line 117
Quoted 3 lines
include/uapi/linux/tls.h +3
-0+ __TLS_INFO_MAX, +}; +
Traditionally we put no new line between enum and the max define.
Quoted 16 lines
include/uapi/linux/tls.h +2
-0+#define TLS_INFO_MAX (__TLS_INFO_MAX - 1) +#endif /* _UAPI_LINUX_TLS_H */ net/tls/tls_main.c +1
-0@@ -39,6 +39,7 @@#include <linux/netdevice.h> #include <linux/sched/signal.h> #include <linux/inetdevice.h> +#include <linux/inet_diag.h> #include <net/tls.h>
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 805
Quoted 7 lines
net/tls/tls_main.c +4
-0@@ -798,6 +799,46 @@ static int tls_init(struct sock *sk)return rc; } +static int tls_get_info (struct sock *sk,struct sk_buff *skb) +{ +struct tls_context *ctx =tls_get_ctx (sk); +struct nlattr *start =0 ;
Hm.. NULL? Does this not give you a warning?
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 806
Quoted 1 line
net/tls/tls_main.c +1
-0+int err =0 ;
There should be no need to init this.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 807
Quoted 1 line
net/tls/tls_main.c +1
-0+if (sk->sk_state !=TCP_ESTABLISHED )
Hmm.. why this check? We never clean up the state once installed until the socket dies completely (currently, pending John's unhash work).
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 808
Quoted 1 line
net/tls/tls_main.c +1
-0+ goto end;
Please don't do this, just return 0; here.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 813
Quoted 4 lines
net/tls/tls_main.c +4
-0+ start =nla_nest_start_noflag (skb,ULP_INFO_TLS ); +if (!start) { + err = -EMSGSIZE ; + goto nla_failure;
return -EMSGSIZE;
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 823
Quoted 10 lines
net/tls/tls_main.c +10
-0+ } + err =nla_put_u16 (skb,TLS_INFO_VERSION , ctx->prot_info.version); +if (err <0 ) + goto nla_failure; + err =nla_put_u16 (skb,TLS_INFO_CIPHER , ctx->prot_info.cipher_type); +if (err <0 ) + goto nla_failure; +nla_nest_end (skb, start); +end: +return err;
return 0;
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 826
Quoted 3 lines
net/tls/tls_main.c +3
-0+nla_failure: +nla_nest_cancel (skb, start); + goto end;
return err;
Quoted 4 lines
net/tls/tls_main.c +4
-0+} + +static size_t tls_get_info_size (struct sock *sk) +{
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 840
Quoted 10 lines
net/tls/tls_main.c +10
-0+size_t size =0 ; + +if (sk->sk_state !=TCP_ESTABLISHED ) +return size; + + size +=nla_total_size (0 )/* ULP_INFO_TLS */ + +nla_total_size (sizeof (__u16))/* TLS_INFO_VERSION */ + +nla_total_size (sizeof (__u16));/* TLS_INFO_CIPHER */ +return size; +}
Same comments as on patch 1 and above.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 844
Quoted 3 lines
net/tls/tls_main.c +0
-0void tls_register_device (struct tls_device *device) {spin_lock_bh (&device_spinlock);
Thanks for working on this, it was on my todo list! :)
Re: [RFC PATCH net-next 2/2] net: tls: export protocol version and cipher to socket diag
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Davide Caratti
When an application configures kernel TLS on top of a TCP socket, it's now possible for
inet_diag_handlerto collect information regarding the protocol version and the cipher, in caseINET_DIAG_INFOis requested.Signed-off-by Davide Caratti <[email protected]>
Quoted 7 lines
Quoted 1 line
+enum {
USPEC
include/uapi/linux/tls.h struct tls12_crypto_info_aes_ccm_128 { · line 114
Quoted 2 lines
include/uapi/linux/tls.h +2
-0+TLS_INFO_VERSION , + TLS_INFO_CIPHER,
Ok,
Quoted 4 lines
We need some indication of the directions in which kTLS is active (none, rx, tx, rx/tx).
Also perhaps could you add
TLS_SWvsTLS_HWetc. ? :)
I can add a couple of u16 (or larger?) bitmasks to dump txconf and rxconf. do you think this is sufficient?
Quoted 5 lines
include/uapi/linux/tls.h struct tls12_crypto_info_aes_ccm_128 { · line 117
Quoted 3 lines
include/uapi/linux/tls.h +3
-0+ __TLS_INFO_MAX, +}; +Traditionally we put no new line between enum and the max define.
Ok, will fix that in v1.
Quoted 19 lines
Quoted 19 lines
include/uapi/linux/tls.h +2
-0+#define TLS_INFO_MAX (__TLS_INFO_MAX - 1) +#endif /* _UAPI_LINUX_TLS_H */ net/tls/tls_main.c +1
-0@@ -39,6 +39,7 @@#include <linux/netdevice.h> #include <linux/sched/signal.h> #include <linux/inetdevice.h> +#include <linux/inet_diag.h> #include <net/tls.h> @@ -798,6 +799,46 @@ static int tls_init(struct sock *sk)return rc; }
Quoted 6 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 805
Quoted 4 lines
net/tls/tls_main.c +4
-0+static int tls_get_info (struct sock *sk,struct sk_buff *skb) +{ +struct tls_context *ctx =tls_get_ctx (sk); +struct nlattr *start =0 ;Hm.. NULL? Does this not give you a warning?
I didn't notice it, but sure. will fix in v1.
Quoted 8 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 806
Quoted 1 line
net/tls/tls_main.c +1
-0+int err =0 ;There should be no need to init this.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 807
Quoted 1 line
net/tls/tls_main.c +1
-0+if (sk->sk_state !=TCP_ESTABLISHED )Hmm.. why this check? We never clean up the state once installed until the socket dies completely (currently, pending John's unhash work).
the goal was to ensure that we don't read ctx anymore after tls_sk_proto_close() has freed ctx, and I thought that a test on the value of sk_state was sufficient.
If it's not, then we might invent something else. For example, we might defer freeing kTLS ctx, so that it's called as the very last thing with tcp_cleanup_ulp().
Quoted 24 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 808
Quoted 1 line
net/tls/tls_main.c +1
-0+ goto end;Please don't do this, just return 0; here.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 813
Quoted 4 lines
net/tls/tls_main.c +4
-0+ start =nla_nest_start_noflag (skb,ULP_INFO_TLS ); +if (!start) { + err = -EMSGSIZE ; + goto nla_failure;return -EMSGSIZE;net/tls/tls_main.c static int tls_init(struct sock *sk) · line 823
Quoted 10 lines
net/tls/tls_main.c +10
-0+ } + err =nla_put_u16 (skb,TLS_INFO_VERSION , ctx->prot_info.version); +if (err <0 ) + goto nla_failure; + err =nla_put_u16 (skb,TLS_INFO_CIPHER , ctx->prot_info.cipher_type); +if (err <0 ) + goto nla_failure; +nla_nest_end (skb, start); +end: +return err;return 0;
Quoted 5 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 826
Quoted 3 lines
net/tls/tls_main.c +3
-0+nla_failure: +nla_nest_cancel (skb, start); + goto end;return err;
Ok, i can remove that 'goto end'.
Quoted 8 lines
Quoted 8 lines
net/tls/tls_main.c +8
-0+} + +static size_t tls_get_info_size (struct sock *sk) +{ +size_t size =0 ; + +if (sk->sk_state !=TCP_ESTABLISHED ) +return size;
Quoted 8 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 840
Quoted 6 lines
net/tls/tls_main.c +6
-0+ + size +=nla_total_size (0 )/* ULP_INFO_TLS */ + +nla_total_size (sizeof (__u16))/* TLS_INFO_VERSION */ + +nla_total_size (sizeof (__u16));/* TLS_INFO_CIPHER */ +return size; +}Same comments as on patch 1 and above.
sure, ok.
Quoted 5 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 844
Quoted 3 lines
net/tls/tls_main.c +0
-0void tls_register_device (struct tls_device *device) {spin_lock_bh (&device_spinlock);Thanks for working on this, it was on my todo list! :)
thanks for the review!
Signature · 1 line
davide
Re: [RFC PATCH net-next 2/2] net: tls: export protocol version and cipher to socket diag
Quoted 9 lines · Davide Caratti
Quoted 5 lines · Jakub Kicinski
On Wed, 5 Jun 2019 17:39:23 +0200, Davide Caratti wrote:
We need some indication of the directions in which kTLS is active (none, rx, tx, rx/tx).Also perhaps could you add
TLS_SWvsTLS_HWetc. ? :)I can add a couple of u16 (or larger?) bitmasks to dump txconf and rxconf. do you think this is sufficient?
SGTM!
Quoted 9 lines
Quoted 8 lines
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 806
Quoted 1 line
net/tls/tls_main.c +1
-0+int err =0 ;There should be no need to init this.
Review
Quoted 1 line
(quoted diff) +1
-0+ if (sk->sk_state != TCP_ESTABLISHED)Hmm.. why this check? We never clean up the state once installed until the socket dies completely (currently, pending John's unhash work).
Quoted 7 lines
the goal was to ensure that we don't read ctx anymore after
tls_sk_proto_close()has freed ctx, and I thought that a test on the value ofsk_statewas sufficient.If it's not, then we might invent something else. For example, we might defer freeing kTLS ctx, so that it's called as the very last thing with
tcp_cleanup_ulp().
Mm.. I was hoping the user space can no longer access a socket once it reaches sk_prot->close :S Perhaps I got this wrong. If it can we need to make sure we don't free context before calling tcp_close() otherwise the state may still be established, no?
In particular:
#ifdef CONFIG_TLS_DEVICE
if (ctx->rx_conf == TLS_HW)
tls_device_offload_cleanup_rx(sk);
if (ctx->tx_conf != TLS_HW && ctx->rx_conf != TLS_HW) {
#else
{
#endif
tls_ctx_free(ctx); <<< <<< <<< <<< kfree()
ctx = NULL;
}skip_tx_cleanup:
release_sock(sk); sk_proto_close(sk, timeout); <<< <<< <<< <<< tcp_close() /* free ctx for TLS_HW_RECORD, used by tcp_set_state * for sk->sk_prot->unhash [tls_hw_unhash] */ if (free_ctx) tls_ctx_free(ctx);
Re: [RFC PATCH net-next 2/2] net: tls: export protocol version and cipher to socket diag
In reply to Davide CarattiHi Davide,
TLS statistics are long overdue. I'd like to extend this later for the tls_device code, e.g. device_decrypted vs. software_decrypted.
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 809
Quoted 9 lines · Davide Caratti
net/tls/tls_main.c +8
-0+static int tls_get_info (struct sock *sk,struct sk_buff *skb) +{ +struct tls_context *ctx =tls_get_ctx (sk); +struct nlattr *start =0 ; +int err =0 ; + +if (sk->sk_state !=TCP_ESTABLISHED ) + goto end;
Maybe it would be best to verify that the version and cipher have been initialized. As the TLS_ULP might be enabled but no socket option has been called to set its values.
Also, I suggest this check is placed in the tls_get_info_size to make this more explicit to the user.
Quoted 21 lines
net/tls/tls_main.c +21
-0+ start =nla_nest_start_noflag (skb,ULP_INFO_TLS ); +if (!start) { + err = -EMSGSIZE ; + goto nla_failure; + } + err =nla_put_u16 (skb,TLS_INFO_VERSION , ctx->prot_info.version); +if (err <0 ) + goto nla_failure; + err =nla_put_u16 (skb,TLS_INFO_CIPHER , ctx->prot_info.cipher_type); +if (err <0 ) + goto nla_failure; +nla_nest_end (skb, start); +end: +return err; +nla_failure: +nla_nest_cancel (skb, start); + goto end; +} + +static size_t tls_get_info_size (struct sock *sk) +{
net/tls/tls_main.c static int tls_init(struct sock *sk) · line 840
Quoted 10 lines
net/tls/tls_main.c +10
-0+size_t size =0 ; + +if (sk->sk_state !=TCP_ESTABLISHED ) +return size; + + size +=nla_total_size (0 )/* ULP_INFO_TLS */ + +nla_total_size (sizeof (__u16))/* TLS_INFO_VERSION */ + +nla_total_size (sizeof (__u16));/* TLS_INFO_CIPHER */ +return size; +}
Thanks,
Boris.