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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <D8A73PQELZV8.24M3P13CM0062@proton.me>
Date: Fri, 07 Mar 2025 17:04:20 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Tamir Duberstein <tamird@...il.com>, Masahiro Yamada <masahiroy@...nel.org>, Nathan Chancellor <nathan@...nel.org>, Nicolas Schier <nicolas@...sle.eu>, 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>, Danilo Krummrich <dakr@...nel.org>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>, Brendan Higgins <brendan.higgins@...ux.dev>, David Gow <davidgow@...gle.com>, Rae Moar <rmoar@...gle.com>, Bjorn Helgaas <bhelgaas@...gle.com>
Cc: linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com, linux-pci@...r.kernel.org
Subject: Re: [PATCH] rust: enable `clippy::ptr_as_ptr` lint

On Fri Mar 7, 2025 at 5:58 PM CET, Benno Lossin wrote:
> On Fri Mar 7, 2025 at 5:41 PM CET, Tamir Duberstein wrote:
>> In Rust 1.51.0, Clippy introduced the `ignored_unit_patterns` lint [1]:
>
> You link to the `ptr_as_ptr` lint though, is this a typo?
>
>>> Though `as` casts between raw pointers are not terrible,
>>> `pointer::cast` is safer because it cannot accidentally change the
>>> pointer's mutability, nor cast the pointer to other types like `usize`.
>>
>> There are a few classes of changes required:
>> - Modules generated by bindgen are marked
>>   `#[allow(clippy::ptr_as_ptr)]`.
>> - Inferred casts (` as _`) are replaced with `.cast()`.
>> - Ascribed casts (` as *... T`) are replaced with `.cast::<T>()`.
>> - Multistep casts from references (` as *const _ as *const T`) are
>>   replaced with `let x: *const _ = &x;` and `.cast()` or `.cast::<T>()`
>>   according to the previous rules. The intermediate `let` binding is
>>   required because `(x as *const _).cast::<T>()` results in inference
>>   failure.
>> - Native literal C strings are replaced with `c_str!().as_char_ptr()`.
>
> These all seem very nice, thanks! I think it would also be a good idea
> to enable `ptr_cast_constness` [1], since those are the other kind of
> `as` usage that we should be doing via `cast_mut`/`cast_const`.

I didn't mean to make this sound like you *have* to do the work. If you
find the time and want to do it, then great, otherwise we can turn this
into a good-first-issue :)

---
Cheers,
Benno

> There are still some legitimate uses of `as` casts, when unsizing
> values. I don't know if these two lints can trigger on those, it would
> be nice if they don't. So those should continue to use `as`, but other
> than that, there shouldn't be any `as` in our code :)
>
> [1]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness
>
> (I will take a look at the patch itself a bit later)
>
> ---
> Cheers,
> Benno
>
>> Apply these changes and enable the lint -- no functional change
>> intended.
>>
>> Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr [1]
>> Signed-off-by: Tamir Duberstein <tamird@...il.com>
>> ---
>>  Makefile                               |  1 +
>>  rust/bindings/lib.rs                   |  1 +
>>  rust/kernel/alloc/allocator_test.rs    |  2 +-
>>  rust/kernel/alloc/kvec.rs              |  4 ++--
>>  rust/kernel/device.rs                  |  5 +++--
>>  rust/kernel/devres.rs                  |  2 +-
>>  rust/kernel/error.rs                   |  2 +-
>>  rust/kernel/fs/file.rs                 |  2 +-
>>  rust/kernel/kunit.rs                   | 15 +++++++--------
>>  rust/kernel/lib.rs                     |  4 ++--
>>  rust/kernel/list/impl_list_item_mod.rs |  2 +-
>>  rust/kernel/pci.rs                     |  2 +-
>>  rust/kernel/platform.rs                |  4 +++-
>>  rust/kernel/print.rs                   | 11 +++++------
>>  rust/kernel/seq_file.rs                |  3 ++-
>>  rust/kernel/str.rs                     |  2 +-
>>  rust/kernel/sync/poll.rs               |  2 +-
>>  rust/kernel/workqueue.rs               | 10 +++++-----
>>  rust/uapi/lib.rs                       |  1 +
>>  19 files changed, 40 insertions(+), 35 deletions(-)



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ