Skip to content

Commit 267c77f

Browse files
committed
tls: fix replacing proto_ops
jira LE-1907 Rebuild_History Non-Buildable kernel-4.18.0-394.el8 commit-author Jakub Kicinski <[email protected]> commit f3911f7 We replace proto_ops whenever TLS is configured for RX. But our replacement also overrides sendpage_locked, which will crash unless TX is also configured. Similarly we plug both of those in for TLS_HW (NIC crypto offload) even tho TLS_HW has a completely different implementation for TX. Last but not least we always plug in something based on inet_stream_ops even though a few of the callbacks differ for IPv6 (getname, release, bind). Use a callback building method similar to what we do for struct proto. Fixes: c46234e ("tls: RX path for ktls") Fixes: d4ffb02 ("net/tls: enable sk_msg redirect to tls socket egress") Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit f3911f7) Signed-off-by: Jonathan Maple <[email protected]>
1 parent d09a0b1 commit 267c77f

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

net/tls/tls_main.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static DEFINE_MUTEX(tcpv6_prot_mutex);
6161
static const struct proto *saved_tcpv4_prot;
6262
static DEFINE_MUTEX(tcpv4_prot_mutex);
6363
static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG];
64-
static struct proto_ops tls_sw_proto_ops;
64+
static struct proto_ops tls_proto_ops[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG];
6565
static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
6666
const struct proto *base);
6767

@@ -71,6 +71,8 @@ void update_sk_prot(struct sock *sk, struct tls_context *ctx)
7171

7272
WRITE_ONCE(sk->sk_prot,
7373
&tls_prots[ip_ver][ctx->tx_conf][ctx->rx_conf]);
74+
WRITE_ONCE(sk->sk_socket->ops,
75+
&tls_proto_ops[ip_ver][ctx->tx_conf][ctx->rx_conf]);
7476
}
7577

7678
int wait_on_pending_writer(struct sock *sk, long *timeo)
@@ -577,8 +579,6 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
577579
if (tx) {
578580
ctx->sk_write_space = sk->sk_write_space;
579581
sk->sk_write_space = tls_write_space;
580-
} else {
581-
sk->sk_socket->ops = &tls_sw_proto_ops;
582582
}
583583
goto out;
584584

@@ -636,6 +636,39 @@ struct tls_context *tls_ctx_create(struct sock *sk)
636636
return ctx;
637637
}
638638

639+
static void build_proto_ops(struct proto_ops ops[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
640+
const struct proto_ops *base)
641+
{
642+
ops[TLS_BASE][TLS_BASE] = *base;
643+
644+
ops[TLS_SW ][TLS_BASE] = ops[TLS_BASE][TLS_BASE];
645+
ops[TLS_SW ][TLS_BASE].sendpage_locked = tls_sw_sendpage_locked;
646+
647+
ops[TLS_BASE][TLS_SW ] = ops[TLS_BASE][TLS_BASE];
648+
ops[TLS_BASE][TLS_SW ].splice_read = tls_sw_splice_read;
649+
650+
ops[TLS_SW ][TLS_SW ] = ops[TLS_SW ][TLS_BASE];
651+
ops[TLS_SW ][TLS_SW ].splice_read = tls_sw_splice_read;
652+
653+
#ifdef CONFIG_TLS_DEVICE
654+
ops[TLS_HW ][TLS_BASE] = ops[TLS_BASE][TLS_BASE];
655+
ops[TLS_HW ][TLS_BASE].sendpage_locked = NULL;
656+
657+
ops[TLS_HW ][TLS_SW ] = ops[TLS_BASE][TLS_SW ];
658+
ops[TLS_HW ][TLS_SW ].sendpage_locked = NULL;
659+
660+
ops[TLS_BASE][TLS_HW ] = ops[TLS_BASE][TLS_SW ];
661+
662+
ops[TLS_SW ][TLS_HW ] = ops[TLS_SW ][TLS_SW ];
663+
664+
ops[TLS_HW ][TLS_HW ] = ops[TLS_HW ][TLS_SW ];
665+
ops[TLS_HW ][TLS_HW ].sendpage_locked = NULL;
666+
#endif
667+
#ifdef CONFIG_TLS_TOE
668+
ops[TLS_HW_RECORD][TLS_HW_RECORD] = *base;
669+
#endif
670+
}
671+
639672
static void tls_build_proto(struct sock *sk)
640673
{
641674
int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4;
@@ -647,6 +680,8 @@ static void tls_build_proto(struct sock *sk)
647680
mutex_lock(&tcpv6_prot_mutex);
648681
if (likely(prot != saved_tcpv6_prot)) {
649682
build_protos(tls_prots[TLSV6], prot);
683+
build_proto_ops(tls_proto_ops[TLSV6],
684+
sk->sk_socket->ops);
650685
smp_store_release(&saved_tcpv6_prot, prot);
651686
}
652687
mutex_unlock(&tcpv6_prot_mutex);
@@ -657,6 +692,8 @@ static void tls_build_proto(struct sock *sk)
657692
mutex_lock(&tcpv4_prot_mutex);
658693
if (likely(prot != saved_tcpv4_prot)) {
659694
build_protos(tls_prots[TLSV4], prot);
695+
build_proto_ops(tls_proto_ops[TLSV4],
696+
sk->sk_socket->ops);
660697
smp_store_release(&saved_tcpv4_prot, prot);
661698
}
662699
mutex_unlock(&tcpv4_prot_mutex);
@@ -876,10 +913,6 @@ static int __init tls_register(void)
876913
if (err)
877914
return err;
878915

879-
tls_sw_proto_ops = inet_stream_ops;
880-
tls_sw_proto_ops.splice_read = tls_sw_splice_read;
881-
tls_sw_proto_ops.sendpage_locked = tls_sw_sendpage_locked;
882-
883916
tls_device_init();
884917
tcp_register_ulp(&tcp_tls_ulp_ops);
885918

0 commit comments

Comments
 (0)