From: Jakub Kicinski <kuba@xxxxxxxxxx> commit e01e3934a1b2d122919f73bc6ddbe1cdafc4bbdb upstream. Similarly to previous commit, the submitting thread (recvmsg/sendmsg) may exit as soon as the async crypto handler calls complete(). Reorder scheduling the work before calling complete(). This seems more logical in the first place, as it's the inverse order of what the submitting thread will do. Reported-by: valis <sec@valis.email> Fixes: a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance") Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> Reviewed-by: Simon Horman <horms@xxxxxxxxxx> Reviewed-by: Sabrina Dubroca <sd@xxxxxxxxxxxxxxx> Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx> [ Lee: Fixed merge-conflict in Stable branches linux-6.1.y and older ] Signed-off-by: Lee Jones <lee@xxxxxxxxxx> [ Harshit: bp to 5.15.y, minor conflict resolutin due to missing commit: 8ae187386420 ("tls: Only use data field in crypto completion function") in 5.15.y] Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- net/tls/tls_sw.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -468,7 +468,6 @@ static void tls_encrypt_done(struct cryp struct scatterlist *sge; struct sk_msg *msg_en; struct tls_rec *rec; - bool ready = false; if (err == -EINPROGRESS) /* see the comment in tls_decrypt_done() */ return; @@ -502,19 +501,16 @@ static void tls_encrypt_done(struct cryp /* If received record is at head of tx_list, schedule tx */ first_rec = list_first_entry(&ctx->tx_list, struct tls_rec, list); - if (rec == first_rec) - ready = true; + if (rec == first_rec) { + /* Schedule the transmission */ + if (!test_and_set_bit(BIT_TX_SCHEDULED, + &ctx->tx_bitmask)) + schedule_delayed_work(&ctx->tx_work.work, 1); + } } if (atomic_dec_and_test(&ctx->encrypt_pending)) complete(&ctx->async_wait.completion); - - if (!ready) - return; - - /* Schedule the transmission */ - if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) - schedule_delayed_work(&ctx->tx_work.work, 1); } static int tls_encrypt_async_wait(struct tls_sw_context_tx *ctx) Patches currently in stable-queue which might be from kuba@xxxxxxxxxx are queue-5.15/af_packet-handle-outgoing-vlan-packets-without-hardware-offloading.patch queue-5.15/misdn-fix-a-use-after-free-in-hfcmulti_tx.patch queue-5.15/net-mlx5e-add-a-check-for-the-return-value-from-mlx5.patch queue-5.15/selftests-forwarding-devlink_lib-wait-for-udev-event.patch queue-5.15/net-add-l3mdev-index-to-flow-struct-and-avoid-oif-re.patch queue-5.15/vhost-vsock-always-initialize-seqpacket_allow.patch queue-5.15/tcp-fix-races-in-tcp_v-46-_err.patch queue-5.15/net-fec-refactor-define-magic-constants.patch queue-5.15/tcp-fix-race-in-tcp_write_err.patch queue-5.15/sctp-fix-null-ptr-deref-in-reuseport_add_sock.patch queue-5.15/r8169-don-t-increment-tx_dropped-in-case-of-netdev_tx_busy.patch queue-5.15/mlxsw-spectrum_acl_bloom_filter-make-mlxsw_sp_acl_bf.patch queue-5.15/gve-fix-an-edge-case-for-tso-skb-validity-check.patch queue-5.15/tcp-add-tcp_done_with_error-helper.patch queue-5.15/net-dsa-bcm_sf2-fix-a-possible-memory-leak-in-bcm_sf.patch queue-5.15/ipv6-take-care-of-scope-when-choosing-the-src-addr.patch queue-5.15/l2tp-fix-lockdep-splat.patch queue-5.15/mptcp-export-local_address.patch queue-5.15/ipv6-fix-source-address-selection-with-route-leak.patch queue-5.15/net-linkwatch-use-system_unbound_wq.patch queue-5.15/net-mvpp2-don-t-re-use-loop-iterator.patch queue-5.15/net-netconsole-disable-target-before-netpoll-cleanup.patch queue-5.15/xdp-fix-invalid-wait-context-of-page_pool_destroy.patch queue-5.15/net-fec-stop-pps-on-driver-remove.patch queue-5.15/ipv6-fix-ndisc_is_useropt-handling-for-pio.patch queue-5.15/pci-add-edimax-vendor-id-to-pci_ids.h.patch queue-5.15/net-bridge-mcast-wait-for-previous-gc-cycles-when-re.patch queue-5.15/rtnetlink-don-t-ignore-ifla_target_netnsid-when-ifna.patch queue-5.15/tls-fix-race-between-tx-work-scheduling-and-socket-close.patch queue-5.15/rtnetlink-enable-alt_ifname-for-setlink-newlink.patch queue-5.15/ipv4-fix-source-address-selection-with-route-leak.patch