From: "Gary Guo" <gary@garyguo.net>
To: <sashiko-reviews@lists.linux.dev>, "Gary Guo" <gary@garyguo.net>
Cc: <ojeda@kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH 16/20] rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance
Date: Thu, 08 Oct 2026 16:52:51 +0100 [thread overview]
Message-ID: <DLZKT0KCED3C.2XOP0UCKDOF4M@garyguo.net> (raw)
In-Reply-To: <sashiko-outbox-164164@kernel.org>
(Cc list)
TLDR: false positive. Explanations below.
On Thu Oct 8, 2026 at 1:40 PM BST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Critical] rust: pin_data macro drop order check bypassed for covariant fields
> --
>
> commit f9d502571fb94f74de22024871d23b994623a8b0
> Author: Gary Guo <gary@garyguo.net>
>
> rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance
>
> The commit modifies pin_data to ensure invariant capturing of fields.
> It splits the outlive chain into covariant and invariant fields to avoid
> outlive relationships issues. It calculates an invariant closure and
> handles type invariance.
>
>> diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
>> index d42d86ffd8538..b35d32ff2bb2d 100644
>> --- a/rust/pin-init/internal/src/pin_data.rs
>> +++ b/rust/pin-init/internal/src/pin_data.rs
>
> [ ... ]
>
>> @@ -520,6 +581,96 @@ fn expand(
>> }
>> }
>>
>> + let mut field_lts_split_variance_outlive_chain = Generics {
>> + lt_token: Some(Default::default()),
>> + params: borrowed_covariant_fields
>
> [Severity: Critical]
> Does splitting the chains by variance in expand() erase the relative
> declaration-order bounds between covariant and invariant fields?
>
> The drop-order check relies on the outlive chains, and without
> declaration-order bounds, the compiler might not be able to safely enforce
> drop ordering.
Omitting a bound can never cause soundness issue (at most they will cause
something that is safe fail to compile).
Here, these bounds are deliberately split, so we cannot arrive with a `Param:
'invariant_field` bound transitively.
>
>> + .iter()
>> + .zip(std::iter::once(None).chain(borrowed_covariant_fields.iter().map(Some)))
>
> [ ... ]
>
>> + for capture in field.captures.iter() {
>> + let Some(&idx) = field_idx_map.get(&capture.lifetime.ident) else {
>> + continue;
>> + };
>> +
>> + let prev_borrowed = fields[idx].borrowed.as_ref().unwrap();
>> +
>> + // If borrowed field is covariant, it's already captured in
>> + // `field_lts_split_variance_outlive_chain`.
>> + if prev_borrowed.lt_variance == Variance::Invariant {
>> + // Covariant field borrowing an invariant field. This is not captured in the chain
>> + // so we need to add additional bound. This bound is okay, as the invariant lifetime
>> + // is the longer living one, so arbitrary shortening of the covariant one does not
>> + // violate their relation.
>> + let param = field_lts_split_variance_outlive_chain
>> + .lifetimes_mut()
>> + .find(|l| l.lifetime == prev_borrowed.lifetime)
>> + .unwrap();
>> + param.bounds.push(borrowed.lifetime.clone());
>
> [Severity: Critical]
> By injecting this bound unconditionally in expand(), is the declaration order
> check bypassed?
>
> This could effectively blind the compiler to drop-order inversions between
> these fields, potentially allowing fields to access freed memory during Drop.
The field-lifetime-outliving-captured-lifetime check is a custom check in
drop_order_check and not bypassed. We do not rely on compiler to capture this.
Best,
Gary
>
>> + }
>> + }
>> + }
next prev parent reply other threads:[~2026-10-08 15:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 12:23 [PATCH 00/20] rust: pin-init: create self references safely Gary Guo
2026-10-08 12:23 ` [PATCH 01/20] kbuild: rust: allow `clippy::comparison_chain` globally Gary Guo
2026-10-08 12:23 ` [PATCH 02/20] rust: pin-init: internal: pin_data: infer self-referential struct Gary Guo
2026-10-08 12:23 ` [PATCH 03/20] rust: pin-init: internal: pin_data: rewrite fields that borrow others Gary Guo
2026-10-08 12:23 ` [PATCH 04/20] rust: pin-init: internal: pin_data: pin borrowed fields with wrapper Gary Guo
2026-10-08 12:23 ` [PATCH 05/20] rust: pin-init: internal: pin_data: teach drop check about generics that cannot dangle Gary Guo
2026-10-08 12:23 ` [PATCH 06/20] rust: pin-init: internal: pin_data: self-referential drop order checks Gary Guo
2026-10-08 12:23 ` [PATCH 07/20] rust: pin-init: internal: pin_data: check covariance of self-referential fields Gary Guo
2026-10-08 12:23 ` [PATCH 08/20] rust: pin-init: internal: pin_data: implement initialization of borrowed structs Gary Guo
2026-10-08 12:23 ` [PATCH 09/20] rust: pin-init: internal: pin_data: project self-referential fields Gary Guo
2026-10-08 12:23 ` [PATCH 10/20] rust: pin-init: internal: pin_data: add `with_project` method Gary Guo
2026-10-08 12:23 ` [PATCH 11/20] rust: pin-init: internal: pin_data: enable self-referential support Gary Guo
2026-10-08 12:23 ` [PATCH 12/20] rust: pin-init: internal: pin_data: allow lifetime to be shortened per field drop order Gary Guo
2026-10-08 12:24 ` [PATCH 13/20] rust: pin-init: internal: pin_data: parse explicit `#[borrowed]` annotation Gary Guo
2026-10-08 12:24 ` [PATCH 14/20] rust: pin-init: internal: pin_data: support mutable borrows Gary Guo
2026-10-08 12:24 ` [PATCH 15/20] rust: pin-init: internal: pin_data: parse explicit `#[uses]` annotation Gary Guo
2026-10-08 12:24 ` [PATCH 16/20] rust: pin-init: internal: pin_data: make field lifetime invariance imply type invariance Gary Guo
[not found] ` <sashiko-outbox-164164@kernel.org>
2026-10-08 15:52 ` Gary Guo [this message]
2026-10-08 12:24 ` [PATCH 17/20] rust: pin-init: internal: pin_data: complete invariant borrow support Gary Guo
2026-10-08 12:24 ` [PATCH 18/20] rust: pin-init: internal: pin_data: perform AST lifetime replacement if possible Gary Guo
2026-10-08 12:24 ` [PATCH 19/20] rust: pin-init: internal: pin_data: support shared projection Gary Guo
2026-10-08 12:24 ` [PATCH 20/20] rust: pin-init: internal: pin_data: support existential lifetimes Gary Guo
2026-10-08 16:20 ` [PATCH 00/20] rust: pin-init: create self references safely 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=DLZKT0KCED3C.2XOP0UCKDOF4M@garyguo.net \
--to=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.