git: cd0525f615fe - main - ktls: Write-lock the INP when changing a transmit TLS session.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 11 Feb 2022 23:16:50 UTC
The branch main has been updated by jhb:

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

commit cd0525f615fe8fea750d2078b61026aabe0d0471
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-02-11 23:16:25 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-02-11 23:16:25 +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
---
 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 2495e940a6a0..466b64d01386 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -1454,6 +1454,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)
@@ -1475,7 +1476,6 @@ ktls_set_tx_mode(struct socket *so, int mode)
 	else
 		counter_u64_add(ktls_switch_to_sw, 1);
 
-	INP_WLOCK(inp);
 	return (0);
 }