Skip to content

Commit d064d63

Browse files
qsnMa Wupeng
authored andcommitted
tls: fix lockless read of strp->msg_ready in ->poll
stable inclusion from stable-v6.6.30 commit 4e40e624961a9858ac1412693987bb191ca5fe34 bugzilla: https://gitee.com/openeuler/kernel/issues/I9MPZ8 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4e40e624961a9858ac1412693987bb191ca5fe34 -------------------------------- [ Upstream commit 0844370f8945086eb9335739d10205dcea8d707b ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
1 parent 841fbc5 commit d064d63

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

include/net/tls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ struct tls_strparser {
111111
u32 stopped : 1;
112112
u32 copy_mode : 1;
113113
u32 mixed_decrypted : 1;
114-
u32 msg_ready : 1;
114+
115+
bool msg_ready;
115116

116117
struct strp_msg stm;
117118

net/tls/tls.h

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

213213
static inline bool tls_strp_msg_ready(struct tls_sw_context_rx *ctx)
214214
{
215-
return ctx->strp.msg_ready;
215+
return READ_ONCE(ctx->strp.msg_ready);
216216
}
217217

218218
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
@@ -360,7 +360,7 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
360360
if (strp->stm.full_len && strp->stm.full_len == skb->len) {
361361
desc->count = 0;
362362

363-
strp->msg_ready = 1;
363+
WRITE_ONCE(strp->msg_ready, 1);
364364
tls_rx_msg_ready(strp);
365365
}
366366

@@ -528,7 +528,7 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
528528
if (!tls_strp_check_queue_ok(strp))
529529
return tls_strp_read_copy(strp, false);
530530

531-
strp->msg_ready = 1;
531+
WRITE_ONCE(strp->msg_ready, 1);
532532
tls_rx_msg_ready(strp);
533533

534534
return 0;
@@ -580,7 +580,7 @@ void tls_strp_msg_done(struct tls_strparser *strp)
580580
else
581581
tls_strp_flush_anchor_copy(strp);
582582

583-
strp->msg_ready = 0;
583+
WRITE_ONCE(strp->msg_ready, 0);
584584
memset(&strp->stm, 0, sizeof(strp->stm));
585585

586586
tls_strp_check_rcv(strp);

0 commit comments

Comments
 (0)