Skip to contentSkip to conversation

rust: kernel: fix lifetime of copy_from_iter_raw

PATCH Superseded Marwan Mohamed Zein 3 participants 6 messages Nov 14 – Nov 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: kernel: fix lifetime of copy_from_iter_raw

From: martell0x1 <[email protected]>

The returned slice is derived from out, but lifetime elision ties it to self because this is a method. Explicitly bind the return lifetime to out so the returned slice cannot outlive its backing buffer.

---
 rust/kernel/iov.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/iov.rs +1 -1
index 43bae8923..8caf04518 100644
@@ -161,7 +161,7 @@ pub fn copy_from_iter_vec<A: Allocator>(
     ///
     /// This will never write uninitialized bytes to the provided buffer.
     #[inline]
-    pub fn copy_from_iter_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> &mut [u8] {
+    pub fn copy_from_iter_raw<'a>(&mut self, out: &'a mut [MaybeUninit<u8>]) -> &'a mut [u8] {
         let capacity = out.len();
         let out = out.as_mut_ptr().cast::<u8>();
 

base-commit: ee83899302a0457a3ba47464a13e8682bd7ba27d

Signature · 1 line
2.47.3
#1 lore raw
Quoted 1 line · Marwan Mohamed Zein

From: martell0x1 <[email protected]>

Please sign with a full name.

Quoted 9 lines

The returned slice is derived from out, but lifetime elision ties it to self because this is a method. Explicitly bind the return lifetime to out so the returned slice cannot outlive its backing buffer.

On these tags as well.

#2 lore raw
In reply to Marwan Mohamed Zein
Quoted 4 lines · Marwan Mohamed Zein

Thanks for the patch!

On top of what Alexandre said, for fixes, please try to find which commit introduced the issue and then add a Fixes tag to it. Then, please consider if it is something that may need to be backported:

https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
https://docs.kernel.org/process/stable-kernel-rules.html

So we would have written:

Fixes 06cb58b310ea ("rust: iov: add iov_iter abstractions for ITER_SOURCE")

Cheers,
Miguel

#3 lore raw
Quoted 7 lines · Miguel Ojeda

Thanks for the patch!

On top of what Alexandre said, for fixes, please try to find which commit introduced the issue and then add a Fixes tag to it. Then, please consider if it is something that may need to be backported:

Quoted 7 lines

https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
https://docs.kernel.org/process/stable-kernel-rules.html

So we would have written:

Fixes 06cb58b310ea ("rust: iov: add iov_iter abstractions for ITER_SOURCE")

By the way, Tamir's email address in the Cc list has a typo -- correcting it here in case it helps.

Cheers,
Miguel

#4 lore raw

PATCH v2 1/1 rust: kernel: fix lifetime of copy_from_iter_raw

The returned slice is derived from out, but lifetime elision ties it to self because this is a method. Explicitly bind the return lifetime to out so the returned slice cannot outlive its backing buffer.

Fixes 06cb58b310ea ("rust: iov: add iov_iter abstractions for ITER_SOURCE")

---
v2:
- Use full name in author and sign-off.
- Add Fixes and Cc: stable tags as suggested by Miguel Ojeda.

 rust/kernel/iov.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/iov.rs +1 -1
index 43bae8923..8caf04518 100644
@@ -161,7 +161,7 @@ pub fn copy_from_iter_vec<A: Allocator>(
     ///
     /// This will never write uninitialized bytes to the provided buffer.
     #[inline]
-    pub fn copy_from_iter_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> &mut [u8] {
+    pub fn copy_from_iter_raw<'a>(&mut self, out: &'a mut [MaybeUninit<u8>]) -> &'a mut [u8] {
         let capacity = out.len();
         let out = out.as_mut_ptr().cast::<u8>();
 

base-commit: ee83899302a0457a3ba47464a13e8682bd7ba27d

Signature · 1 line
2.47.3
Applied
#5 lore raw
Quoted 11 lines · Marwan Mohamed Zein

The returned slice is derived from out, but lifetime elision ties it to self because this is a method. Explicitly bind the return lifetime to out so the returned slice cannot outlive its backing buffer.

Fixes 06cb58b310ea ("rust: iov: add iov_iter abstractions for ITER_SOURCE")

Applied to rust-fixes -- tags still welcome for a day or so!

[ Reworded title. - Miguel ]

Cheers,
Miguel