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] [day] [month] [year] [list]
Message-ID: <2025043046-divisive-crawling-e4b9@gregkh>
Date: Wed, 30 Apr 2025 13:04:05 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: 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 Wed, Apr 30, 2025 at 10:58:10AM +0000, Alice Ryhl wrote:
> On Tue, Apr 29, 2025 at 01:09:18PM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Apr 29, 2025 at 09:02:23AM +0000, Alice Ryhl wrote:
> > > This patch adds a more convenient method for reading C strings from
> > > userspace. Logic is added to NUL-terminate the buffer when necessary so
> > > that a &CStr can be returned.
> > > 
> > > Note that we treat attempts to read past `self.length` as a fault, so
> > > this returns EFAULT if that limit is exceeded before `buf.len()` is
> > > reached.
> > > 
> > > Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> 
> > > +        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?  And if it does, why is that a memory fault?
> > Doesn't this just mean that we read smaller than our overall size of our
> > buffer?  Or am I misreading this completely?
> > 
> > Maybe a self-test would be good to exercise all of this :)
> 
> How can I test userspace access? Is there a way to create a kernel
> buffer that strncpy_from_user will let you read from for use in a kunit
> test?

I think you'll need to just wire up a misc device and test it from
userspace, sorry.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ