git: 48e6b7ad3557 - stable/13 - ktls: Write-lock the INP when changing a transmit TLS session.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 11 May 2022 00:30:08 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=48e6b7ad3557d0c5b8f23db2b3d1a8f1d00d32a3

commit 48e6b7ad3557d0c5b8f23db2b3d1a8f1d00d32a3
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-02-11 23:16:25 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-11 00:10:56 +0000

    ktls: Write-lock the INP when changing a transmit TLS session.
    
    The TCP rate pacing code relies on being able to read this pointer
    safely while holding an INP lock.  The initial TLS session pointer is
    set while holding the write lock already.
    
    Reviewed by:    gallatin, hselasky
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D34086
    
    (cherry picked from commit cd0525f615fe8fea750d2078b61026aabe0d0471)
---
 sys/kern/uipc_ktls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c
index 6d436c72de2f..fa01113c7c8e 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -1317,6 +1317,7 @@ ktls_set_tx_mode(struct socket *so, int mode)
 		return (EBUSY);
 	}
 
+	INP_WLOCK(inp);
 	SOCKBUF_LOCK(&so->so_snd);
 	so->so_snd.sb_tls_info = tls_new;
 	if (tls_new->mode != TCP_TLS_MODE_SW)
@@ -1338,7 +1339,6 @@ ktls_set_tx_mode(struct socket *so, int mode)
 	else
 		counter_u64_add(ktls_switch_to_sw, 1);
 
-	INP_WLOCK(inp);
 	return (0);
 }