[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2025042937-chemo-uprising-8524@gregkh>
Date: Tue, 29 Apr 2025 17:50:42 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Danilo Krummrich <kernel@...r.org>, Miguel Ojeda <ojeda@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/2] uaccess: rust: add
UserSliceReader::strcpy_into_buf
On Tue, Apr 29, 2025 at 03:15:01PM +0000, Alice Ryhl wrote:
> On Tue, Apr 29, 2025 at 01:48:19PM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Apr 29, 2025 at 01:38:26PM +0200, Danilo Krummrich wrote:
> > > On 2025-04-29 13:09, Greg Kroah-Hartman wrote:
> > > > On Tue, Apr 29, 2025 at 09:02:23AM +0000, Alice Ryhl wrote:
> > > > > + let mut len = raw_strncpy_from_user(self.ptr, dst)?;
> > > > > + if len < dst.len() {
> > > > > + // Add one to include the NUL-terminator.
> > > > > + len += 1;
> > > > > + } else if len < buf.len() {
> > > > > + // We hit the `self.length` limit before `buf.len()`.
> > > > > + return Err(EFAULT);
> > > >
> > > > How can this happen?
> > >
> > > See my reply here (if I did not get it wrong):
> > >
> > > https://lore.kernel.org/rust-for-linux/aBCrqJe4two4I45G@pollux/
> >
> > Ah, I should have read ahead :)
> >
> > I agree, some comments here would be good. We want everyone to be able
> > to easily read and understand this code, off-by-one errors are rough.
>
> I will add this comment:
>
> if len < dst.len() {
> // Add one to include the NUL-terminator.
> len += 1;
> } else if len < buf.len() {
> // This implies that len == dst.len() < buf.len().
> //
> // This means that we could not fill the entire buffer, but we had
> // to stop reading because we hit the `self.length` limit of this
> // `UserSliceReader`. Since we did not fill the buffer, we treat
> // this case as if we tried to read past the `self.length` limit and
> // received a page fault, which is consistent with other
> // `UserSliceReader` methods that also return page faults when you
> // exceed `self.length`.
> return Err(EFAULT);
Looks great, thanks!
Powered by blists - more mailing lists