On a TLS 1.3 rekey, do_tls_setsockopt_conf() must not set up a brand-new device offload: reject the rekey with -EOPNOTSUPP for a HW-offloaded connection (HW KeyUpdate is not supported yet, and we must not fall back to software mid-connection), and for a SW-offloaded one re-init the software crypto state via tls_set_sw_offload() directly. Do this by moving the reject into the device-offload helpers and shaping the dispatch in its final form: - tls_set_device_offload() and tls_set_device_offload_rx() reject any non-initial call (tx_conf / rx_conf != TLS_BASE) with -EOPNOTSUPP. - do_tls_setsockopt_conf() always calls the device helper and, on failure, either propagates the error (rekey on a HW connection) or falls back to tls_set_sw_offload() (initial install, or rekey on a SW connection). Prep for the following patches: "tls: add TLS 1.3 hardware offload support" drops the TLS_1_2_VERSION guards in those helpers (which today also happen to reject a TLS 1.3 rekey), and the KeyUpdate patches replace the reject guards above with real rekey handling in the helpers, leaving the do_tls_setsockopt_conf() dispatch unchanged. Signed-off-by: Rishikesh Jethwani --- net/tls/tls_device.c | 18 ++++++++++++++++++ net/tls/tls_main.c | 22 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index f11d0528fc43..f5e1b6b61ce3 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1077,6 +1077,15 @@ int tls_set_device_offload(struct sock *sk) ctx = tls_get_ctx(sk); prot = &ctx->prot_info; + /* A rekey (setsockopt on an already-configured socket) is not + * supported on the device offload path yet; reject it here so the + * caller can decide (propagate the error for a HW connection, or + * re-init software crypto for a SW one). KeyUpdate support replaces + * this guard with real rekey handling. + */ + if (ctx->tx_conf != TLS_BASE) + return -EOPNOTSUPP; + if (ctx->priv_ctx_tx) return -EEXIST; @@ -1202,6 +1211,15 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx) if (ctx->crypto_recv.info.version != TLS_1_2_VERSION) return -EOPNOTSUPP; + /* A rekey (setsockopt on an already-configured socket) is not + * supported on the device offload path yet; reject it here so the + * caller can decide (propagate the error for a HW connection, or + * re-init software crypto for a SW one). KeyUpdate support replaces + * this guard with real rekey handling. + */ + if (ctx->rx_conf != TLS_BASE) + return -EOPNOTSUPP; + netdev = get_netdev_for_sock(sk); if (!netdev) { pr_err_ratelimited("%s: netdev not found\n", __func__); diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index fbb274287aa5..15e83e853f22 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -713,8 +713,15 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, rc = tls_set_device_offload(sk); conf = TLS_HW; if (!rc) { - TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSTXDEVICE); - TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRTXDEVICE); + if (!update) { + TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSTXDEVICE); + TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRTXDEVICE); + } + } else if (update && ctx->tx_conf == TLS_HW) { + /* HW rekey failed - return the actual error. + * Cannot fall back to SW for an existing HW connection. + */ + goto err_crypto_info; } else { rc = tls_set_sw_offload(sk, 1, update ? crypto_info : NULL); @@ -733,8 +740,15 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, rc = tls_set_device_offload_rx(sk, ctx); conf = TLS_HW; if (!rc) { - TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXDEVICE); - TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRRXDEVICE); + if (!update) { + TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSRXDEVICE); + TLS_INC_STATS(sock_net(sk), LINUX_MIB_TLSCURRRXDEVICE); + } + } else if (update && ctx->rx_conf == TLS_HW) { + /* HW rekey failed - return the actual error. + * Cannot fall back to SW for an existing HW connection. + */ + goto err_crypto_info; } else { rc = tls_set_sw_offload(sk, 0, update ? crypto_info : NULL); -- 2.50.1