Message ID | Zkx4vjSFp0mfpjQ2@libra05 (mailing list archive) |
---|---|
State | Accepted |
Commit | 91e61dd7a0af660408e87372d8330ceb218be302 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net,v2] tls: fix missing memory barrier in tls_init | expand |
Hello: This patch was applied to netdev/net.git (main) by Paolo Abeni <pabeni@redhat.com>: On Tue, 21 May 2024 19:34:38 +0900 you wrote: > From: Dae R. Jeong <threeearcat@gmail.com> > > In tls_init(), a write memory barrier is missing, and store-store > reordering may cause NULL dereference in tls_{setsockopt,getsockopt}. > > CPU0 CPU1 > > [...] Here is the summary with links: - [net,v2] tls: fix missing memory barrier in tls_init https://git.kernel.org/netdev/net/c/91e61dd7a0af You are awesome, thank you!
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index b4674f03d71a..90b7f253d363 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -816,9 +816,17 @@ struct tls_context *tls_ctx_create(struct sock *sk) return NULL; mutex_init(&ctx->tx_lock); - rcu_assign_pointer(icsk->icsk_ulp_data, ctx); ctx->sk_proto = READ_ONCE(sk->sk_prot); ctx->sk = sk; + /* Release semantic of rcu_assign_pointer() ensures that + * ctx->sk_proto is visible before changing sk->sk_prot in + * update_sk_prot(), and prevents reading uninitialized value in + * tls_{getsockopt, setsockopt}. Note that we do not need a + * read barrier in tls_{getsockopt,setsockopt} as there is an + * address dependency between sk->sk_proto->{getsockopt,setsockopt} + * and ctx->sk_proto. + */ + rcu_assign_pointer(icsk->icsk_ulp_data, ctx); return ctx; }