Thread (8 messages) 8 messages, 6 authors, 6d ago

Re: [PATCH net-next v4] rust: net: netlink: validate attribute length before casting to `c_int`

From: "Gary Guo" <gary@garyguo.net>
Date: 2026-09-23 18:33:49
Also in: lkml, rust-for-linux

On Wed Sep 23, 2026 at 1:05 PM BST, Sagar Taunk wrote:
`put()` trusted an unchecked `as` cast from `usize` to `c_int`.
When the length exceeds `i32::MAX` that cast wraps around to a
negative value.

This ultimately resulted in a kernel panic when the reinterpreted
value via `__nla_reserve()` and `skb_put()` became enormous.

Validate payload and header both fit together in a `u16`, rejecting
any payload that wouldn't leave room for `NLA_HDRLEN`.

Fixes: 5eaa5fbb6e6c ("rust: netlink: add raw netlink abstraction")
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Sagar Taunk <redacted>
Reviewed-by: Gary Guo <gary@garyguo.net>
---
Changes Since V3: 
Rebased on the upstream rust-next tree. 
No functional changes. 

 rust/kernel/net/netlink.rs | 9 +++++++++
 1 file changed, 9 insertions(+)
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help