Skip to content

Commit 6509e27

Browse files
qsngregkh
authored andcommitted
tls: fix lockless read of strp->msg_ready in ->poll
commit 0844370 upstream. tls_sk_poll is called without locking the socket, and needs to read strp->msg_ready (via tls_strp_msg_ready). Convert msg_ready to a bool and use READ_ONCE/WRITE_ONCE where needed. The remaining reads are only performed when the socket is locked. Fixes: 121dca7 ("tls: suppress wakeups unless we have a full record") Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/0b7ee062319037cf86af6b317b3d72f7bfcd2e97.1713797701.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: 0844370 ("tls: fix lockless read of strp->msg_ready in ->poll") Assisted-by: Codex:GPT-5 Signed-off-by: Artem Dinaburg <artem@trailofbits.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 63d2230 commit 6509e27

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

include/net/tls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ struct tls_strparser {
122122
u32 stopped : 1;
123123
u32 copy_mode : 1;
124124
u32 mixed_decrypted : 1;
125-
u32 msg_ready : 1;
125+
126+
bool msg_ready;
126127

127128
struct strp_msg stm;
128129

net/tls/tls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static inline struct sk_buff *tls_strp_msg(struct tls_sw_context_rx *ctx)
167167

168168
static inline bool tls_strp_msg_ready(struct tls_sw_context_rx *ctx)
169169
{
170-
return ctx->strp.msg_ready;
170+
return READ_ONCE(ctx->strp.msg_ready);
171171
}
172172

173173
static inline bool tls_strp_msg_mixed_decrypted(struct tls_sw_context_rx *ctx)

net/tls/tls_strp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
366366
if (strp->stm.full_len && strp->stm.full_len == skb->len) {
367367
desc->count = 0;
368368

369-
strp->msg_ready = 1;
369+
WRITE_ONCE(strp->msg_ready, 1);
370370
tls_rx_msg_ready(strp);
371371
}
372372

@@ -533,7 +533,7 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
533533
if (!tls_strp_check_queue_ok(strp))
534534
return tls_strp_read_copy(strp, false);
535535

536-
strp->msg_ready = 1;
536+
WRITE_ONCE(strp->msg_ready, 1);
537537
tls_rx_msg_ready(strp);
538538

539539
return 0;
@@ -585,7 +585,7 @@ void tls_strp_msg_done(struct tls_strparser *strp)
585585
else
586586
tls_strp_flush_anchor_copy(strp);
587587

588-
strp->msg_ready = 0;
588+
WRITE_ONCE(strp->msg_ready, 0);
589589
memset(&strp->stm, 0, sizeof(strp->stm));
590590

591591
tls_strp_check_rcv(strp);

0 commit comments

Comments
 (0)