Re: [PATCH] rust: net: netlink: Migrate to zerocopy's `IntoBytes`
From: Alexandre Courbot
Date: Sat Sep 12 2026 - 21:38:34 EST
On Sat Sep 12, 2026 at 3:25 PM JST, Sagar Taunk wrote:
> Replace the kernel's own `transmute::FromBytes` and `AsBytes` traits
> with their zerocopy equivalents. Specifically, this updates
> `GenlMsg::put` to rely on `IntoBytes` for converting attributes into
> byte slices.
>
> Also, add `Immutable` trait bound on `GenlMsg::put` as zerocopy
> splits the `no interior mutability` guarantee that `AsBytes` bundled
> together.
>
> Moreover, shashiko pointed out `put()` trusted an unchecked `as` cast
> from `usize` to `c_int` for the attribute length. A length larger than
> `i32::MAX` wraps to a negative value in that cast, which can pass
> `nla_put()`'s own signed `skb_tailroom()` check and then be reinterpreted
> as an enormous unsigned length via `__nla_reserve()`/`skb_put()`, leading
> to a kernel panic via `skb_over_panic()`. Validate the length with
> `c_int::try_from()` and reject it with `EMSGSIZE` instead.
The conversion and length validation are two different things and should
be split into their own patches.