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: <2025090849-tweak-conductor-f642@gregkh>
Date: Mon, 8 Sep 2025 14:48:53 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Matthew Maurer <mmaurer@...gle.com>, Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>,
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Andreas Hindborg <a.hindborg@...nel.org>,
	Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
	"Rafael J. Wysocki" <rafael@...nel.org>,
	Sami Tolvanen <samitolvanen@...gle.com>,
	Timur Tabi <ttabi@...dia.com>, Benno Lossin <lossin@...nel.org>,
	Dirk Beheme <dirk.behme@...bosch.com>, linux-kernel@...r.kernel.org,
	rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v11 2/7] rust: debugfs: Add support for read-only files

On Mon, Sep 08, 2025 at 12:54:46PM +0200, Danilo Krummrich wrote:
> On Mon Sep 8, 2025 at 12:17 PM CEST, Greg Kroah-Hartman wrote:
> > I tried using this in a "tiny" test module I had written, and I get the
> > following build error:
> >
> >    --> samples/rust/rust_debugfs2.rs:64:53
> >     |
> > 64  |         _file = root.read_only_file(c_str!("name"), &hw_soc_info.name);
> >     |                      --------------                 ^^^^^^^^^^^^^^^^^ expected `&u32`, found `&&CStr`
> >     |                      |
> >     |                      arguments to this method are incorrect
> >     |
> >     = note: expected reference `&u32`
> >                found reference `&&'static kernel::prelude::CStr`
> >
> > I'm trying to "just" print a CStr, which is defined as:
> >
> > struct HwSocInfo {
> >     id: u32,
> >     ver: u32,
> >     raw_id: u32,
> >     foundry: u32,
> >     name: &'static CStr,
> > }
> >
> > Is this just a "user is holding it wrong" error on my side, or can this api not
> > handle CStr values?
> 
> What you're doing should fundamentally work.
> 
> The above error suggests that your declaration of `_file` is File<&u32> rather
> than File<&'static CStr>.

Ah, ick, I missed that the return type would be different here.  Yes, I
was doing a bunch of file creation calls:
        let mut _file = root.read_only_file(c_str!("id"), &hw_soc_info.id);
        _file = root.read_only_file(c_str!("ver"), &hw_soc_info.ver);
        _file = root.read_only_file(c_str!("raw_id"), &hw_soc_info.raw_id);
        _file = root.read_only_file(c_str!("name"), &hw_soc_info.name);

As I don't care about the return value here at all.

But really, I should just write this as:
        root.read_only_file(c_str!("id"), &hw_soc_info.id);
        root.read_only_file(c_str!("ver"), &hw_soc_info.ver);
        root.read_only_file(c_str!("raw_id"), &hw_soc_info.raw_id);
        root.read_only_file(c_str!("name"), hw_soc_info.name);

with, as you point out:

> Also note the double reference you create with `&hw_soc_info.name`, this should
> just be `hw_soc_info.name`.

Yes, sorry, my fault there.

> You can also test this case by applying the following diff the the sample in v5:
> 
> diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
> index b26eea3ee723..475502f30b1a 100644
> --- a/samples/rust/rust_debugfs.rs
> +++ b/samples/rust/rust_debugfs.rs
> @@ -59,6 +59,8 @@ struct RustDebugFs {
>      #[pin]
>      _compatible: File<CString>,
>      #[pin]
> +    _test: File<&'static CStr>,
> +    #[pin]
>      counter: File<AtomicUsize>,
>      #[pin]
>      inner: File<Mutex<Inner>>,
> @@ -140,6 +142,7 @@ fn new(pdev: &platform::Device<Core>) -> impl PinInit<Self, Error> + '_ {
>                          .property_read::<CString>(c_str!("compatible"))
>                          .required_by(dev)?,
>                  ),
> +                _test <- debugfs.read_only_file(c_str!("test"), c_str!("some_value")),

Cool, but again, we do not want to ever be storing individual debugfs
files.  Well, we can, but for 90% of the cases, we do not, we only want
to remove the whole directory when that goes out of scope, which will
clean up the files then.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ