lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250616-borrow_impls-v4-0-36f9beb3fe6a@nvidia.com>
Date: Mon, 16 Jun 2025 12:34:04 +0900
From: Alexandre Courbot <acourbot@...dia.com>
To: Danilo Krummrich <dakr@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, 
 Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, 
 Gary Guo <gary@...yguo.net>, 
 Björn Roy Baron <bjorn3_gh@...tonmail.com>, 
 Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>, 
 Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Alexandre Courbot <acourbot@...dia.com>
Subject: [PATCH v4 0/7] rust: a few common Borrow/BorrowMut implementations

The Borrow trait has multiple uses, one of them being to store either an
owned value or a reference to it inside a generic container. This series
adds these implementations for `Box`, `Arc`, `Vec`, and `CString`. I
came across the need for this while experimenting with the scatterlist
abstraction series [1].

In order to avoid an unsightly unsafe block in the doctest, this also
implements `from_bytes_with_nul_mut`. `from_bytes_with_nul` and
`from_bytes_with_nul_unchecked_mut` already exist, so it looked strange
to not have it anyway.

While doing this, I noticed that `from_bytes_with_nul_unchecked_mut` was
not const and not using `transmute`, which I attributed to the absence
of the `const_mut_refs` feature at the time the code was written. I've
tentatively fixed that, but my assumption for doing this might be wrong
so a double-check from someone more familiar with the timeline of this
code would be appreciated.

[1] https://lore.kernel.org/rust-for-linux/DA9JTYA0EQU8.26M0ZX80FOBWY@nvidia.com/

Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
---
Changes in v4:
- Implement `from_bytes_with_nul_mut` to avoid unsafe block in doctest.
- Make `from_bytes_with_nul_unchecked_mut` const and use transmute.
- Use more explicit names for variables in doctests.
- Link to v3: https://lore.kernel.org/r/20250615-borrow_impls-v3-0-621736de7f29@nvidia.com

Changes in v3:
- Remove undeeded first line of doccomments.
- Link to v2: https://lore.kernel.org/r/20250613-borrow_impls-v2-0-6120e1958199@nvidia.com

Changes in v2:
- Rebase on top of v6.16-rc1.
- Improve commit messages. (thanks Benno!)
- Add examples on each impl block.
- Link to v1: https://lore.kernel.org/r/20250601-borrow_impls-v1-0-e1caeb428db4@nvidia.com

---
Alexandre Courbot (7):
      rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
      rust: sync: implement `Borrow` and `BorrowMut` for `Arc` types
      rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`
      rust: str: make `from_bytes_with_nul_unchecked_mut` const
      rust: str: use transmute in `from_bytes_with_nul_unchecked_mut`
      rust: str: implement `from_bytes_with_nul_mut`
      rust: str: implement `Borrow` and `BorrowMut` for `CString`

 rust/kernel/alloc/kbox.rs | 57 +++++++++++++++++++++++++++++++
 rust/kernel/alloc/kvec.rs | 53 +++++++++++++++++++++++++++++
 rust/kernel/str.rs        | 86 ++++++++++++++++++++++++++++++++++++++++++-----
 rust/kernel/sync/arc.rs   | 78 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 265 insertions(+), 9 deletions(-)
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250531-borrow_impls-8dfef3fcee93

Best regards,
-- 
Alexandre Courbot <acourbot@...dia.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ