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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a5679ca1-aa22-4a05-92fb-f1e95805c864@gmail.com>
Date: Mon, 30 Jun 2025 10:48:08 +0300
From: Abdiel Janulgue <abdiel.janulgue@...il.com>
To: Danilo Krummrich <dakr@...nel.org>, daniel.almeida@...labora.com,
 robin.murphy@....com, a.hindborg@...nel.org, ojeda@...nel.org,
 alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
 bjorn3_gh@...tonmail.com, lossin@...nel.org, aliceryhl@...gle.com,
 tmgross@...ch.edu, acourbot@...dia.com
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: dma: require mutable reference for as_slice_mut()
 and write()



On 28/06/2025 19:49, Danilo Krummrich wrote:
> Given the safety requirements of as_slice_mut() and write() taking an
> immutable reference is technically not incorrect.
> 
> However, let's leverage the compiler's capabilities and require a
> mutable reference to ensure exclusive access.
> 
> This also fixes a clippy warning introduced with 1.88:
> 
>    warning: mutable borrow from immutable input(s)
>       --> rust/kernel/dma.rs:297:78
>        |
>    297 |     pub unsafe fn as_slice_mut(&self, offset: usize, count: usize) -> Result<&mut [T]> {
>        |                                                                              ^^^^^^^^
> 
> Fixes: d37a39f607c4 ("rust: dma: add as_slice/write functions for CoherentAllocation")
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
>   rust/kernel/dma.rs | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index 25dfa0e6cc3c..2ac4c47aeed3 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -294,7 +294,7 @@ pub unsafe fn as_slice(&self, offset: usize, count: usize) -> Result<&[T]> {
>       ///   slice is live.
>       /// * Callers must ensure that this call does not race with a read or write to the same region
>       ///   while the returned slice is live.
> -    pub unsafe fn as_slice_mut(&self, offset: usize, count: usize) -> Result<&mut [T]> {
> +    pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> Result<&mut [T]> {
>           self.validate_range(offset, count)?;
>           // SAFETY:
>           // - The pointer is valid due to type invariant on `CoherentAllocation`,
> @@ -326,7 +326,7 @@ pub unsafe fn as_slice_mut(&self, offset: usize, count: usize) -> Result<&mut [T
>       /// unsafe { alloc.write(buf, 0)?; }
>       /// # Ok::<(), Error>(()) }
>       /// ```
> -    pub unsafe fn write(&self, src: &[T], offset: usize) -> Result {
> +    pub unsafe fn write(&mut self, src: &[T], offset: usize) -> Result {
>           self.validate_range(offset, src.len())?;
>           // SAFETY:
>           // - The pointer is valid due to type invariant on `CoherentAllocation`
> 
> base-commit: c7e03c5cf06a90ff234ae3c628c6b74e5cba7426

Reviewed-by: Abdiel Janulgue <abdiel.janulgue@...il.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ