From: Christian Schrefl <chrisi.schrefl@gmail.com>
To: Danilo Krummrich <dakr@redhat.com>,
mcgrof@kernel.org, russ.weight@linux.dev,
gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Gary Guo <gary@garyguo.net>
Subject: Re: [PATCH v2 2/2] firmware_loader: fix soundness issue in `request_internal`
Date: Tue, 9 Jul 2024 00:16:30 +0200 [thread overview]
Message-ID: <12a986aa-3fed-4686-b5bc-99cbe446cca6@gmail.com> (raw)
In-Reply-To: <20240708200724.3203-2-dakr@redhat.com>
Greetings
On 08.07.24 10:07 PM, Danilo Krummrich wrote:
> `request_internal` must be called with one of the following function
> pointers: request_firmware(), firmware_request_nowarn(),
> firmware_request_platform() or request_firmware_direct().
>
> The previous `FwFunc` alias did not guarantee this, which is unsound.
>
> In order to fix this up, implement `FwFunc` as new type with a
> corresponding type invariant.
>
> Reported-by: Gary Guo <gary@garyguo.net>
> Closes: https://lore.kernel.org/lkml/20240620143611.7995e0bb@eugeo/
> Signed-off-by: Danilo Krummrich <dakr@redhat.com>
> ---
> v2:
> - provide method for each wrapped `FwFunc` (Christian)> ---
> rust/kernel/firmware.rs | 27 ++++++++++++++++++++-------
> 1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
> index 106a928a535e..2ba03af9f036 100644
> --- a/rust/kernel/firmware.rs
> +++ b/rust/kernel/firmware.rs
> @@ -7,10 +7,23 @@
> use crate::{bindings, device::Device, error::Error, error::Result, str::CStr};
> use core::ptr::NonNull;
>
> -// One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`,
> -// `firmware_request_platform`, `bindings::request_firmware_direct`
> -type FwFunc =
> - unsafe extern "C" fn(*mut *const bindings::firmware, *const i8, *mut bindings::device) -> i32;
> +/// # Invariants
> +///
> +/// One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`,
> +/// `bindings::firmware_request_platform`, `bindings::request_firmware_direct`.
> +struct FwFunc(
> + unsafe extern "C" fn(*mut *const bindings::firmware, *const i8, *mut bindings::device) -> i32,
> +);
> +
> +impl FwFunc {
> + fn request() -> Self {
> + Self(bindings::request_firmware)
> + }
> +
> + fn request_nowarn() -> Self {
> + Self(bindings::firmware_request_nowarn)
> + }
I'm not sure if we should have a comment here that describes how the invariant is fulfilled.
In this case its not too bad since the Invariants are described just a few lines above, so:
Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Cheers,
Christian
prev parent reply other threads:[~2024-07-08 22:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 20:07 [PATCH v2 1/2] firmware_loader: annotate doctests as `no_run` Danilo Krummrich
2024-07-08 20:07 ` [PATCH v2 2/2] firmware_loader: fix soundness issue in `request_internal` Danilo Krummrich
2024-07-08 20:37 ` Luis Chamberlain
2024-07-08 21:07 ` Danilo Krummrich
2024-07-08 22:16 ` Christian Schrefl [this message]
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=12a986aa-3fed-4686-b5bc-99cbe446cca6@gmail.com \
--to=chrisi.schrefl@gmail.com \
--cc=dakr@redhat.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=russ.weight@linux.dev \
--cc=rust-for-linux@vger.kernel.org \
/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