mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: "Georgios Androutsopoulos" <georgeandrout13@gmail.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Dave Ertman" <david.m.ertman@intel.com>,
	"Ira Weiny" <iweiny@kernel.org>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: auxiliary: validate DeviceId name length
Date: Wed, 9 Sep 2026 15:33:04 +0200	[thread overview]
Message-ID: <2026090941-salami-engraved-8eac@gregkh> (raw)
In-Reply-To: <DLAR1FIFL0Y5.22A7AJKNW0YQP@kernel.org>

On Wed, Sep 09, 2026 at 01:29:18PM +0200, Danilo Krummrich wrote:
> On Wed Sep 9, 2026 at 9:19 AM CEST, Greg Kroah-Hartman wrote:
> > On Tue, Sep 08, 2026 at 11:32:46PM -0400, Georgios Androutsopoulos wrote:
> >> `DeviceId::new()` copies `modname` and `name` into the fixed 40-byte
> >> `auxiliary_device_id::name` array without checking that they fit. An
> >> oversized name is caught by the array bounds check, but the error
> >> reports an out-of-bounds index in the copy loop rather than the
> >> constraint the caller violated.
> >> 
> >> Check the invariant explicitly instead, so the failure states the length
> >> limit rather than an array index.
> >> 
> >> In a constant context exceeding the limit leads to a build error; at
> >> runtime it panics, so add a `# Panics` section for it.
> >> 
> >> Fixes: ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")
> 
> It's not actually fixing a bug, so I don't think this needs a Fixes: tag.
> 
> >> Signed-off-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
> >> ---
> >>  rust/kernel/auxiliary.rs | 10 ++++++++++
> >>  1 file changed, 10 insertions(+)
> >> 
> >> diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
> >> index 60dfbec8f330..1f3ba86d6d96 100644
> >> --- a/rust/kernel/auxiliary.rs
> >> +++ b/rust/kernel/auxiliary.rs
> >> @@ -137,10 +137,20 @@ macro_rules! module_auxiliary_driver {
> >>  
> >>  impl DeviceId {
> >>      /// Create a new [`DeviceId`] from name.
> >> +    ///
> >> +    /// # Panics
> >> +    ///
> >> +    /// Panics if the combined module and device name, including the
> >> +    /// separator and trailing NUL, exceeds `AUXILIARY_NAME_SIZE` bytes.
> 
> I'd rather document that this is only intended to be called within device ID
> table creation; in const context a panic is just a compile time error.
> 
> >>      pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self {
> >>          let name = name.to_bytes_with_nul();
> >>          let modname = modname.to_bytes_with_nul();
> >>  
> >> +        assert!(
> >> +            modname.len().saturating_add(name.len()) <= bindings::AUXILIARY_NAME_SIZE as usize,
> >> +            "auxiliary device ID is too long"
> >> +        );
> 
> Isn't this missing to consider the separator and NULL terminator?
> 
> >
> > We really shouldn't panic, we should error out and fail the creation
> > instead.
> 
> This is only ever used from const context to construct the device ID table, e.g.
> as in
> 
> 	kernel::auxiliary_device_table!(
> 	    AUX_TABLE,
> 	    <NovaDriver as auxiliary::Driver>::IdInfo,
> 	    [(
> 	        auxiliary::DeviceId::new(NOVA_CORE_MODULE_NAME, AUXILIARY_NAME),
> 	        ()
> 	    )]
> 	);
> 
> and a panic in const context makes the compilation fail, so it works as
> intended.
> 
> Unfortunately, we can't enforce that is function can only be called from const
> context, so technically it could also be called outside of the device ID table
> in non-const context, but it would be odd to construct outside of a device ID
> table.
> 
> > But what is placing the constraint of the name size here?  The C api
> > just takes a pointer, it doesn't care about the size, why does the rust
> > binding care?
> 
> I assume you were thinking of something else? This struct represents
> 
> 	#define AUXILIARY_NAME_SIZE 40
> 	
> 	struct auxiliary_device_id {
> 		char name[AUXILIARY_NAME_SIZE];
> 		kernel_ulong_t driver_data;
> 	};
> 

Ah, sorry, I was looking at auxiliary_device_create() which just takes a
pointer to a name, which is not the device_id, but the name by which the
device_id gets created from, my bad.

greg k-h

  reply	other threads:[~2026-09-09 13:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  3:32 Georgios Androutsopoulos
2026-09-09  7:19 ` Greg Kroah-Hartman
2026-09-09 11:29   ` Alexandre Courbot
2026-09-09 12:40     ` Miguel Ojeda
2026-09-09 14:27     ` Gary Guo
2026-09-09 11:29   ` Danilo Krummrich
2026-09-09 13:33     ` Greg Kroah-Hartman [this message]
2026-09-09 20:32     ` George Androutsopoulos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026090941-salami-engraved-8eac@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=david.m.ertman@intel.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=georgeandrout13@gmail.com \
    --cc=iweiny@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®