[PATCH v2 0/2] rust: debugfs: fix callback file unsoundness
From: Tamir Duberstein
Date: Tue May 26 2026 - 14:11:32 EST
Commit 40ecc49466c8 ("rust: debugfs: Add support for callback-based
files") introduced two ways to construct references whose requirements
are not met.
First, `write()` constructed an `&mut seq_file` although file operation
callbacks may run concurrently for the same open file. It only needs
`seq_file::private`, so patch 1 reads that field through a raw pointer.
Second, `FileOps::adapt()` transmuted a reference between different
generic instantiations of a default-representation type, despite there
being no layout guarantee. Patch 2 replaces this with an explicit
adapter safety contract.
I discovered the second issue while looking to remove
reference-to-reference transmutes after discussing with Alice [1] and
the first issue was found by Sashiko in the v1 review.
Link: https://lore.kernel.org/all/CAH5fLgibt_BQmOtkfEfo1=48zUeoWBJ-=u5gzw_a3X6Q7=aUSA@xxxxxxxxxxxxxx/ [1]
Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>
---
Changes in v2:
- Fix the pre-existing `write()` aliasing issue reported during review
of v1.
- Link to v1: https://patch.msgid.link/20260526-fileops-unsound-redesign-v1-1-bd1685cbaf56@xxxxxxxxxx
To: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
To: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
To: Danilo Krummrich <dakr@xxxxxxxxxx>
To: Miguel Ojeda <ojeda@xxxxxxxxxx>
To: Boqun Feng <boqun@xxxxxxxxxx>
To: Gary Guo <gary@xxxxxxxxxxx>
To: Björn Roy Baron <bjorn3_gh@xxxxxxxxxxxxxx>
To: Benno Lossin <lossin@xxxxxxxxxx>
To: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
To: Alice Ryhl <aliceryhl@xxxxxxxxxx>
To: Trevor Gross <tmgross@xxxxxxxxx>
To: Matthew Maurer <mmaurer@xxxxxxxxxx>
Cc: driver-core@xxxxxxxxxxxxxxx
Cc: rust-for-linux@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
Tamir Duberstein (2):
rust: debugfs: avoid borrowing seq_file in write
rust: debugfs: avoid transmuting FileOps
rust/kernel/debugfs.rs | 20 ++-----
rust/kernel/debugfs/callback_adapters.rs | 67 +++++++++++-----------
rust/kernel/debugfs/file_ops.rs | 96 ++++++++++++++++----------------
3 files changed, 90 insertions(+), 93 deletions(-)
---
base-commit: fc1ce3afa2e61b4b15e71436ece91b0441a9f4f0
change-id: 20260526-fileops-unsound-redesign-51a81b17f552
Best regards,
--
Tamir Duberstein <tamird@xxxxxxxxxx>