From: Benno Lossin <benno.lossin@proton.me>
To: "Benno Lossin" <benno.lossin@proton.me>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 4/6] rust: pin-init: add `?Sized` bounds to traits in `#[pin_data]` macro
Date: Tue, 04 Mar 2025 22:57:18 +0000 [thread overview]
Message-ID: <20250304225536.2033853-5-benno.lossin@proton.me> (raw)
In-Reply-To: <20250304225536.2033853-1-benno.lossin@proton.me>
`#[pin_data]` 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 value using pin-init.
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
---
rust/pin-init/internal/src/syn_pin_data.rs | 6 +++---
rust/pin-init/src/macros.rs | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/pin-init/internal/src/syn_pin_data.rs b/rust/pin-init/internal/src/syn_pin_data.rs
index d95176389e17..30cd4bc35fd0 100644
--- a/rust/pin-init/internal/src/syn_pin_data.rs
+++ b/rust/pin-init/internal/src/syn_pin_data.rs
@@ -293,7 +293,7 @@ fn drop(&mut self) {
// 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
{}
@@ -302,8 +302,8 @@ impl #impl_generics MustNotImplDrop for #ident #ty_generics
// `PinnedDrop` as the parameter to `#[pin_data]`.
#[expect(non_camel_case_types)]
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
- impl<T: ::pin_init::PinnedDrop> UselessPinnedDropImpl_you_need_to_specify_PinnedDrop
- for T {}
+ 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
#whr
diff --git a/rust/pin-init/src/macros.rs b/rust/pin-init/src/macros.rs
index 361623324d5c..03e2588423cc 100644
--- a/rust/pin-init/src/macros.rs
+++ b/rust/pin-init/src/macros.rs
@@ -931,7 +931,7 @@ impl<'__pin, $($impl_generics)*> ::core::marker::Unpin for $name<$($ty_generics)
// 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 $name<$($ty_generics)*>
where $($whr)* {}
// We also take care to prevent users from writing a useless `PinnedDrop` implementation.
@@ -939,7 +939,7 @@ impl<$($impl_generics)*> MustNotImplDrop for $name<$($ty_generics)*>
// `PinnedDrop` as the parameter to `#[pin_data]`.
#[expect(non_camel_case_types)]
trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}
- impl<T: $crate::PinnedDrop>
+ impl<T: $crate::PinnedDrop + ?::core::marker::Sized>
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
impl<$($impl_generics)*>
UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for $name<$($ty_generics)*>
--
2.48.1
next prev parent reply other threads:[~2025-03-04 22:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 22:56 [RFC PATCH 0/6] add `syn` versions of pin-init macros Benno Lossin
2025-03-04 22:56 ` [RFC PATCH 1/6] rust: pin-init: internal: add syn version of the `Zeroable` derive macro Benno Lossin
2025-03-04 22:57 ` [RFC PATCH 2/6] rust: pin-init: internal: add syn version of `pinned_drop` proc macro Benno Lossin
2025-03-04 22:57 ` [RFC PATCH 3/6] rust: pin-init: internal: add syn version of the `pin_data` " Benno Lossin
2025-03-04 22:57 ` Benno Lossin [this message]
2025-03-04 22:57 ` [RFC PATCH 5/6] rust: pin-init: allow doctests to refer to the pin-init crate Benno Lossin
2025-03-04 22:57 ` [RFC PATCH 6/6] rust: pin-init: internal: add syn version of `[try_][pin_]init!` macros Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250304225536.2033853-5-benno.lossin@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).