Re: [PATCH v2] rust: dma: return zero for Coherent reads past EOF
Onur Özkan <[email protected]> Sun, 2 Aug 2026 16:54:40 +0300
| Newsgroups | dev.linux.lists.driver-core,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 30 Jul 2026 18:34:38 +0200=0D Younes Akhouayri via B4 Relay <[email protected]> wrote:=0D =0D > From: Younes Akhouayri <[email protected]>=0D > =0D > Coherent<T>::write_to_slice() calculates a zero-byte copy when the file=0D > offset is beyond the allocation, but still calls=0D > UserSliceWriter::write_dma(). The latter rejects offsets beyond the=0D > allocation even when the copy length is zero, so a debugfs read past EOF= =0D > returns -ERANGE.=0D > =0D > Return before calling write_dma() when the offset is at or beyond the=0D > allocation, matching simple_read_from_buffer() EOF semantics.=0D > =0D > Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]= >")=0D > Cc: [email protected]=0D > Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library= /topic/.E2.9C.94.20Possible.20past-EOF.20bug.20in.20Coherent.3CT.3E.3A.3Awr= ite_to_slice/near/611677095=0D > Signed-off-by: Younes Akhouayri <[email protected]>=0D > ---=0D > Changes in v2:=0D > - Use ordinary subtraction after the explicit EOF check, which makes=0D > underflow impossible.=0D > - Link to v1: https://patch.msgid.link/20260720-fix-dma-coherent-eof-v1-1= [email protected]=0D > ---=0D > rust/kernel/dma.rs | 6 +++++-=0D > 1 file changed, 5 insertions(+), 1 deletion(-)=0D > =0D > diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs=0D > index 200def84fb69..556424b88fb9 100644=0D > --- a/rust/kernel/dma.rs=0D > +++ b/rust/kernel/dma.rs=0D > @@ -1005,7 +1005,11 @@ fn write_to_slice(=0D > return Ok(0);=0D > };=0D > =0D > - let count =3D self.size().saturating_sub(offset_val).min(writer.= len());=0D =0D Nit: I would probably just check if `count` is zero next to this line.=0D =0D > + if offset_val >=3D self.size() {=0D > + return Ok(0);=0D > + }=0D > +=0D > + let count =3D (self.size() - offset_val).min(writer.len());=0D > =0D > writer.write_dma(self, offset_val, count)?;=0D > =0D > =0D > ---=0D > base-commit: 667d0fb32149f023b8b34a1f6f3d384556eafb5a=0D > change-id: 20260720-fix-dma-coherent-eof-d0d08c91e013=0D > =0D > Best regards,=0D > -- =0D > Younes Akhouayri <[email protected]>=0D > =0D > =0D