]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: pin-init: add `?Sized` bounds to traits in `#[pin_data]` macro
authorBenno Lossin <lossin@kernel.org>
Fri, 16 Jan 2026 10:54:23 +0000 (11:54 +0100)
committerBenno Lossin <lossin@kernel.org>
Sat, 17 Jan 2026 09:51:42 +0000 (10:51 +0100)
The `#[pin_data]` macro uses some auxiliary traits to ensure that a user
does not implement `Drop` for the annotated struct, as that is unsound
and can lead to UB. However, if the struct that is annotated is
`!Sized`, the current bounds do not work, because `Sized` is an implicit
bound for generics.

This is *not* a soundness hole of pin-init, as it currently is
impossible to construct an unsized struct using pin-init.

Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <lossin@kernel.org>
rust/pin-init/internal/src/pin_data.rs

index 11ea3f8d8a1b6519fc6b8df8a549c80605e78260..7d871236b49c7ec25ca22a418c4b3d59454a50e8 100644 (file)
@@ -215,7 +215,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
             // if it also implements `Drop`
             trait MustNotImplDrop {}
             #[expect(drop_bounds)]
-            impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
+            impl<T: ::core::ops::Drop + ?::core::marker::Sized> MustNotImplDrop for T {}
             impl #impl_generics MustNotImplDrop for #ident #ty_generics
                 #whr
             {}
@@ -224,7 +224,7 @@ fn generate_drop_impl(ident: &Ident, generics: &Generics, args: Args) -> TokenSt
             // `PinnedDrop` as the parameter to `#[pin_data]`.
             #[expect(non_camel_case_types)]
             trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
-            impl<T: ::pin_init::PinnedDrop>
+            impl<T: ::pin_init::PinnedDrop + ?::core::marker::Sized>
                 UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
             impl #impl_generics
                 UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for #ident #ty_generics