rust: bssl-tls: Change context method access into shared Context methods, which is a bag of vtable closures, can be accessed concurrently. This in particular applies to SSL_CTX and SSL_CREDENTIAL objects. Therefore, the mutability annotation has been wrong because access to them would be shared, not exclusive, most of the time. We would prefer the closures to handle the concurrent access and use appropriate locking mechanisms. Signed-off-by: Xiangfei Ding <xfding@google.com> Change-Id: I011fd5808ac7fe6b539be8a5f26cbcf86a6a6964 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/92087 Reviewed-by: Rudolf Polzer <rpolzer@google.com>
diff --git a/rust/bssl-tls/src/connection/methods.rs b/rust/bssl-tls/src/connection/methods.rs index d883d60..0970123 100644 --- a/rust/bssl-tls/src/connection/methods.rs +++ b/rust/bssl-tls/src/connection/methods.rs
@@ -61,7 +61,7 @@ } impl<Mode: HasTlsConnectionMethod> Methods for RustConnectionMethods<Mode> { - unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a mut Self> { + unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a Self> { unsafe { // Safety: `ssl` is originated from `TlsConnection::from_ssl`. let methods = bssl_sys::SSL_get_ex_data(ssl, Mode::registration());
diff --git a/rust/bssl-tls/src/context/methods.rs b/rust/bssl-tls/src/context/methods.rs index f99dfe8..947629c 100644 --- a/rust/bssl-tls/src/context/methods.rs +++ b/rust/bssl-tls/src/context/methods.rs
@@ -33,7 +33,7 @@ } impl<M: HasTlsContextMethod> Methods for RustContextMethods<M> { - unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a mut Self> { + unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a Self> { unsafe { // Safety: `ssl` must be still valid by BoringSSL invariant. let ctx = bssl_sys::SSL_get_SSL_CTX(ssl);
diff --git a/rust/bssl-tls/src/credentials/methods.rs b/rust/bssl-tls/src/credentials/methods.rs index 198a162..3c55c75 100644 --- a/rust/bssl-tls/src/credentials/methods.rs +++ b/rust/bssl-tls/src/credentials/methods.rs
@@ -38,7 +38,7 @@ pub(crate) struct RustCredentialMethods {} impl Methods for RustCredentialMethods { - unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a mut Self> { + unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a Self> { unsafe { // Safety: `ssl` is valid per BoringSSL invariant. let cred = bssl_sys::SSL_get0_selected_credential(ssl); @@ -51,7 +51,7 @@ return None; } // Safety: `cred` is originated from `Box::into_raw`. - Some(&mut *(methods as *mut RustCredentialMethods)) + Some(&*(methods as *mut RustCredentialMethods)) } } }
diff --git a/rust/bssl-tls/src/lib.rs b/rust/bssl-tls/src/lib.rs index bbe1fee..71e343e 100644 --- a/rust/bssl-tls/src/lib.rs +++ b/rust/bssl-tls/src/lib.rs
@@ -51,7 +51,7 @@ pub(crate) trait Methods { /// Safety: `ssl` must outlive `'a` and it must be passed in from BoringSSL /// through vtable calls. - unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a mut Self>; + unsafe extern "C" fn from_ssl<'a>(ssl: *mut bssl_sys::SSL) -> Option<&'a Self>; } #[inline]