net/tls: Fix kernel panic when socket is in TLS ULP
Subsystems (4)
PATCH 1/1 net/tls: Fix kernel panic when socket is in TLS ULP
user can initialize tls ulp using setsockopt call on socket before listen() in case of tls-toe (TLS_HW_RECORD) and same setsockopt call on connected socket in case of kernel tls (TLS_SW). In presence of tls-toe devices, TLS ulp is initialized, tls context is allocated per listen socket and socket is listening at adapter as well as kernel tcp stack. now consider the scenario, connections are established in kernel stack.
on every connection close which is established in kernel stack, it clears tls context which is created on listen socket causing kernel panic.
Addressed the issue by setting child socket to base (non TLS ULP) when tls ulp is initialized on parent socket (listen socket).
--- .../chelsio/inline_crypto/chtls/chtls_cm.c | 3 +++ net/tls/tls_main.c | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +3 -0
@@ -1206,6 +1206,9 @@ static struct sock *chtls_recv_sock(struct sock *lsk,sk_setup_caps (newsk, dst); ctx =tls_get_ctx (lsk); newsk->sk_destruct = ctx->sk_destruct; + newsk->sk_prot = lsk->sk_prot; +inet_csk (newsk)->icsk_ulp_ops =inet_csk (lsk)->icsk_ulp_ops; +rcu_assign_pointer (inet_csk (newsk)->icsk_ulp_data, ctx); csk->sk = newsk; csk->passive_reap_next = oreq; csk->tx_chan =cxgb4_port_chan (ndev);
net/tls/tls_main.c +22 -1
@@ -715,7 +715,7 @@ static int tls_init(struct sock *sk)tls_build_proto (sk);#ifdef CONFIG_TLS_TOE -if (tls_toe_bypass (sk)) +if (sk->sk_state ==TCP_CLOSE &&tls_toe_bypass (sk))return 0 ;#endif
@@ -744,6 +744,24 @@ static int tls_init(struct sock *sk)return rc; } +#ifdef CONFIG_TLS_TOE +static void tls_clone (const struct request_sock *req, +struct sock *newsk,const gfp_t priority) +{ +struct tls_context *ctx =tls_get_ctx (newsk); +struct inet_connection_sock *icsk =inet_csk (newsk); + +/* In presence of TLS TOE devices, TLS ulp is initialized on listen +* socket so lets child socket back to non tls ULP mode because tcp +* connections can happen in non TLS TOE mode. +*/ + newsk->sk_prot = ctx->sk_proto; + newsk->sk_destruct = ctx->sk_destruct; + icsk->icsk_ulp_ops =NULL ; +rcu_assign_pointer (icsk->icsk_ulp_data,NULL ); +} +#endif +static void tls_update (struct sock *sk,struct proto *p,void (*write_space)(struct sock *sk)) {
@@ -857,6 +875,9 @@ static struct tcp_ulp_ops tcp_tls_ulp_ops __read_mostly = { .update = tls_update, .get_info = tls_get_info, .get_info_size = tls_get_info_size, +#ifdef CONFIG_TLS_TOE + .clone = tls_clone +#endif };static int __init tls_register (void )
Signature · 1 line
2.18.1
Jakub Kicinski
maintainerQuoted 13 lines · On Tue, 3 Nov 2020 16:17:03 +0530 Vinay Kumar Yadav wrote:
user can initialize tls ulp using setsockopt call on socket before
listen()in case of tls-toe (TLS_HW_RECORD) and same setsockopt call on connected socket in case of kernel tls (TLS_SW). In presence of tls-toe devices, TLS ulp is initialized, tls context is allocated per listen socket and socket is listening at adapter as well as kernel tcp stack. now consider the scenario, connections are established in kernel stack.
on every connection close which is established in kernel stack, it clears tls context which is created on listen socket causing kernel panic.
Addressed the issue by setting child socket to base (non TLS ULP) when tls ulp is initialized on parent socket (listen socket).
Quoted 2 lines
Fixes 76f7164d02d4 ("net/tls: free ctx in sock destruct")Signed-off-by Vinay Kumar Yadav <[email protected]>
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of proto_ops (like tls_sw_proto_ops) and set listen to sock_no_listen?
Quoted 14 lines · Jakub Kicinski
Quoted 13 lines · On Tue, 3 Nov 2020 16:17:03 +0530 Vinay Kumar Yadav wrote:
user can initialize tls ulp using setsockopt call on socket before
listen()in case of tls-toe (TLS_HW_RECORD) and same setsockopt call on connected socket in case of kernel tls (TLS_SW). In presence of tls-toe devices, TLS ulp is initialized, tls context is allocated per listen socket and socket is listening at adapter as well as kernel tcp stack. now consider the scenario, connections are established in kernel stack.
on every connection close which is established in kernel stack, it clears tls context which is created on listen socket causing kernel panic.
Addressed the issue by setting child socket to base (non TLS ULP) when tls ulp is initialized on parent socket (listen socket).
Quoted 7 lines
Quoted 2 lines
Fixes 76f7164d02d4 ("net/tls: free ctx in sock destruct")Signed-off-by Vinay Kumar Yadav <[email protected]>We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?
Once tls-toe (TLS_HW_RECORD) is configured on a socket, listen() call from user on same socket will create hash at two places.
tls_toe_hash() ---> ctx->sk_proto->hash(sk); dev->hash(dev, sk);
when connection establishes, same sock is cloned in case of both (connection in adapter or kernel stack).
Please suggest if we can handle it other way?
Jakub Kicinski
maintainerQuoted 18 lines · On Thu, 5 Nov 2020 23:20:13 +0530 Vinay Kumar Yadav wrote:
Quoted 17 lines · Jakub Kicinski
Quoted 15 lines · On Tue, 3 Nov 2020 16:17:03 +0530 Vinay Kumar Yadav wrote:
user can initialize tls ulp using setsockopt call on socket before
listen()in case of tls-toe (TLS_HW_RECORD) and same setsockopt call on connected socket in case of kernel tls (TLS_SW). In presence of tls-toe devices, TLS ulp is initialized, tls context is allocated per listen socket and socket is listening at adapter as well as kernel tcp stack. now consider the scenario, connections are established in kernel stack.
on every connection close which is established in kernel stack, it clears tls context which is created on listen socket causing kernel panic.
Addressed the issue by setting child socket to base (non TLS ULP) when tls ulp is initialized on parent socket (listen socket).Fixes 76f7164d02d4 ("net/tls: free ctx in sock destruct")Signed-off-by Vinay Kumar Yadav <[email protected]>
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.
What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
Quoted 6 lines
tls_toe_hash()--->ctx->sk_proto->hash(sk);dev->hash(dev, sk);when connection establishes, same sock is cloned in case of both (connection in adapter or kernel stack).
Please suggest if we can handle it other way?
Quoted 23 lines · Jakub Kicinski
Quoted 22 lines · On Thu, 5 Nov 2020 23:20:13 +0530 Vinay Kumar Yadav wrote:
Quoted 20 lines · Jakub Kicinski
Quoted 13 lines · On Tue, 3 Nov 2020 16:17:03 +0530 Vinay Kumar Yadav wrote:
user can initialize tls ulp using setsockopt call on socket before
listen()in case of tls-toe (TLS_HW_RECORD) and same setsockopt call on connected socket in case of kernel tls (TLS_SW). In presence of tls-toe devices, TLS ulp is initialized, tls context is allocated per listen socket and socket is listening at adapter as well as kernel tcp stack. now consider the scenario, connections are established in kernel stack.
on every connection close which is established in kernel stack, it clears tls context which is created on listen socket causing kernel panic.
Addressed the issue by setting child socket to base (non TLS ULP) when tls ulp is initialized on parent socket (listen socket).Quoted 2 lines
Fixes 76f7164d02d4 ("net/tls: free ctx in sock destruct")Signed-off-by Vinay Kumar Yadav <[email protected]>We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?
Quoted 6 lines
Quoted 2 lines
Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid ctx->sk_proto->hash(sk) call.
Quoted 7 lines
Quoted 6 lines
tls_toe_hash()--->ctx->sk_proto->hash(sk);dev->hash(dev, sk);when connection establishes, same sock is cloned in case of both (connection in adapter or kernel stack).
Please suggest if we can handle it other way?
Jakub Kicinski
maintainerQuoted 4 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.
No, replace the listen callback, like I said. Why are you talking about hash???
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
Quoted 6 lines
Quoted 2 lines
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.
Not sure how replacing listen callback solve the issue, can you please elaborate ?
Jakub Kicinski
maintainerQuoted 12 lines · On Sat, 7 Nov 2020 02:02:42 +0530 Vinay Kumar Yadav wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.Not sure how replacing listen callback solve the issue, can you please elaborate ?
TLS sockets are not supposed to get into listen state. IIUC the problem is that the user is able to set TLS TOE on a socket which then starts to listen and the state gets cloned improperly.
Jakub,
Quoted 19 lines · Jakub Kicinski
Quoted 18 lines · On Sat, 7 Nov 2020 02:02:42 +0530 Vinay Kumar Yadav wrote:
Quoted 17 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.
Quoted 7 lines
Quoted 2 lines
Not sure how replacing listen callback solve the issue, can you please elaborate ?
TLS sockets are not supposed to get into listen state. IIUC the problem is that the user is able to set TLS TOE on a socket which then starts to listen and the state gets cloned improperly.
TLS-TOE can go to listen mode, removing listen is not an option and
TLS-TOE support only server mode so if we remove listen then we will not have TLS-TOE support which we don't want.
Jakub Kicinski
maintainerQuoted 23 lines · On Tue, 10 Nov 2020 00:21:13 +0530 Vinay Kumar Yadav wrote:
Quoted 22 lines · Jakub Kicinski
Quoted 20 lines · On Sat, 7 Nov 2020 02:02:42 +0530 Vinay Kumar Yadav wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
Quoted 6 lines
Quoted 2 lines
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.Not sure how replacing listen callback solve the issue, can you please elaborate ?
Quoted 7 lines
Quoted 3 lines
TLS sockets are not supposed to get into listen state. IIUC the problem is that the user is able to set TLS TOE on a socket which then starts to listen and the state gets cloned improperly.
TLS-TOE can go to listen mode, removing listen is not an option and TLS-TOE support only server mode so if we remove listen then we will not have TLS-TOE support which we don't want.
Oh, so it's completely incompatible with kernel tls. How about we remove the support completely then? Clearly it's not an offload of kernel tls if it supports completely different mode of operation.
Quoted 28 lines · Jakub Kicinski
Quoted 27 lines · On Tue, 10 Nov 2020 00:21:13 +0530 Vinay Kumar Yadav wrote:
Quoted 25 lines · Jakub Kicinski
Quoted 12 lines · On Sat, 7 Nov 2020 02:02:42 +0530 Vinay Kumar Yadav wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.Not sure how replacing listen callback solve the issue, can you please elaborate ?
TLS sockets are not supposed to get into listen state. IIUC the problem is that the user is able to set TLS TOE on a socket which then starts to listen and the state gets cloned improperly.
Quoted 8 lines
Quoted 3 lines
TLS-TOE can go to listen mode, removing listen is not an option and TLS-TOE support only server mode so if we remove listen then we will not have TLS-TOE support which we don't want.
Oh, so it's completely incompatible with kernel tls. How about we remove the support completely then? Clearly it's not an offload of kernel tls if it supports completely different mode of operation.
It is not incompatible. It fits in k.org tls infrastructure (TLS-TOE mode). For the current issue we have proposed a fix. What is the issue with proposed fix, can you elaborate and we will address that?
Quoted 34 lines · Vinay Kumar Yadav
Quoted 31 lines · Jakub Kicinski
Quoted 29 lines · On Tue, 10 Nov 2020 00:21:13 +0530 Vinay Kumar Yadav wrote:
Quoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Sat, 7 Nov 2020 02:02:42 +0530 Vinay Kumar Yadav wrote:
Quoted 16 lines · Jakub Kicinski
Quoted 11 lines · On Thu, 5 Nov 2020 23:55:15 +0530 Vinay Kumar Yadav wrote:
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
We should prevent from the socket getting into LISTEN state in the first place. Can we make a copy of
proto_ops(liketls_sw_proto_ops) and set listen tosock_no_listen?Once tls-toe (
TLS_HW_RECORD) is configured on a socket,listen()call from user on same socket will create hash at two places.What I'm saying is - disallow listen calls on sockets with tls-toe installed on them. Is that not possible?
You mean socket with tls-toe installed shouldn't be listening at other than adapter? basically avoid
ctx->sk_proto->hash(sk)call.No, replace the listen callback, like I said. Why are you talking about hash???
As per my understanding we can't avoid socket listen.Quoted 6 lines
Quoted 2 lines
Not sure how replacing listen callback solve the issue, can you please elaborate ?
TLS sockets are not supposed to get into listen state. IIUC the problem is that the user is able to set TLS TOE on a socket which then starts to listen and the state gets cloned improperly.
TLS-TOE can go to listen mode, removing listen is not an option and TLS-TOE support only server mode so if we remove listen then we will not have TLS-TOE support which we don't want.
Quoted 6 lines
Quoted 4 lines
Oh, so it's completely incompatible with kernel tls. How about we remove the support completely then? Clearly it's not an offload of kernel tls if it supports completely different mode of operation.
It is not incompatible. It fits in k.org tls infrastructure (TLS-TOE mode). For the current issue we have proposed a fix. What is the issue with proposed fix, can you elaborate and we will address that?
and it is valid TLS offload mode.
Jakub Kicinski
maintainerQuoted 3 lines · On Tue, 10 Nov 2020 10:37:11 +0530 Vinay Kumar Yadav wrote:
It is not incompatible. It fits in k.org tls infrastructure (TLS-TOE mode). For the current issue we have proposed a fix. What is the issue with proposed fix, can you elaborate and we will address that?
Your lack of understanding of how netdev offloads are supposed to work is concerning. Application is not supposed to see any difference between offloaded and non-offloaded modes of operation.
Your offload was accepted based on the assumption that it works like the software kernel TLS mode. Nobody had the time to look at your thousands lines of driver code at the time.
Now you're telling us that the uAPI for the offload is completely different - it only works on listening sockets while software tls only works on established sockets. Ergo there is no software fallback for your offload.
Furthermore the severity of the bugs you just started to fix now, after the code has been in the kernel for over a year suggests there are no serious users and we can just remove this code.
Quoted 9 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 10 Nov 2020 10:37:11 +0530 Vinay Kumar Yadav wrote:
It is not incompatible. It fits in k.org tls infrastructure (TLS-TOE mode). For the current issue we have proposed a fix. What is the issue with proposed fix, can you elaborate and we will address that?
Your lack of understanding of how netdev offloads are supposed to work is concerning. Application is not supposed to see any difference between offloaded and non-offloaded modes of operation.
For application point of view there won't be any difference. kernel tls in tcp offload mode works exactly similar to software kTLS.
Quoted 9 lines
Your offload was accepted based on the assumption that it works like the software kernel TLS mode. Nobody had the time to look at your thousands lines of driver code at the time.
Now you're telling us that the uAPI for the offload is completely different - it only works on listening sockets while software tls only works on established sockets. Ergo there is no software fallback for your offload.
We can consider adding the capability to working with established sockets.The TOE has not needed that capability to date since it can establish the socket itself, but it makes sense to provide uniformity with the kTLS approach so we will look into that. For now, as you suggested replacing stack listen with toe listen makes more sense.
Quoted 4 lines
Furthermore the severity of the bugs you just started to fix now, after the code has been in the kernel for over a year suggests there are no serious users and we can just remove this code.
It’s been a slow process but with the new team it is picking up speed and the quality of the code will continue to get better.