Skip to content

Commit 1a97edc

Browse files
committed
tls: fix missing memory barrier in tls_init
jira LE-1907 cve CVE-2024-36489 Rebuild_History Non-Buildable kernel-5.14.0-427.31.1.el9_4 commit-author Dae R. Jeong <threeearcat@gmail.com> commit 91e61dd In tls_init(), a write memory barrier is missing, and store-store reordering may cause NULL dereference in tls_{setsockopt,getsockopt}. CPU0 CPU1 ----- ----- // In tls_init() // In tls_ctx_create() ctx = kzalloc() ctx->sk_proto = READ_ONCE(sk->sk_prot) -(1) // In update_sk_prot() WRITE_ONCE(sk->sk_prot, tls_prots) -(2) // In sock_common_setsockopt() READ_ONCE(sk->sk_prot)->setsockopt() // In tls_{setsockopt,getsockopt}() ctx->sk_proto->setsockopt() -(3) In the above scenario, when (1) and (2) are reordered, (3) can observe the NULL value of ctx->sk_proto, causing NULL dereference. To fix it, we rely on rcu_assign_pointer() which implies the release barrier semantic. By moving rcu_assign_pointer() after ctx->sk_proto is initialized, we can ensure that ctx->sk_proto are visible when changing sk->sk_prot. Fixes: d5bee73 ("net/tls: Annotate access to sk_prot with READ_ONCE/WRITE_ONCE") Signed-off-by: Yewon Choi <woni9911@gmail.com> Signed-off-by: Dae R. Jeong <threeearcat@gmail.com> Link: https://lore.kernel.org/netdev/ZU4OJG56g2V9z_H7@dragonet/T/ Link: https://lore.kernel.org/r/Zkx4vjSFp0mfpjQ2@libra05 Signed-off-by: Paolo Abeni <pabeni@redhat.com> (cherry picked from commit 91e61dd) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent ed390e1 commit 1a97edc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

net/tls/tls_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,17 @@ struct tls_context *tls_ctx_create(struct sock *sk)
813813
return NULL;
814814

815815
mutex_init(&ctx->tx_lock);
816-
rcu_assign_pointer(icsk->icsk_ulp_data, ctx);
817816
ctx->sk_proto = READ_ONCE(sk->sk_prot);
818817
ctx->sk = sk;
818+
/* Release semantic of rcu_assign_pointer() ensures that
819+
* ctx->sk_proto is visible before changing sk->sk_prot in
820+
* update_sk_prot(), and prevents reading uninitialized value in
821+
* tls_{getsockopt, setsockopt}. Note that we do not need a
822+
* read barrier in tls_{getsockopt,setsockopt} as there is an
823+
* address dependency between sk->sk_proto->{getsockopt,setsockopt}
824+
* and ctx->sk_proto.
825+
*/
826+
rcu_assign_pointer(icsk->icsk_ulp_data, ctx);
819827
return ctx;
820828
}
821829

0 commit comments

Comments
 (0)