rust: fwctl: declare cfi_encoding for fwctl_rpc_scope
Subsystems (3)
Alice Ryhl
reviewerPATCH 1/1 rust: fwctl: declare cfi_encoding for fwctl_rpc_scope
Currently, VTable::fw_rpc_callback() takes scope as a u32, whereas C calls fwctl_ops::fw_rpc with enum fwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing every fw_rpc indirect call into a Rust fwctl driver to trip a CFI failure. Thus, generate fwctl_rpc_scope as a newtype with a cfi_encoding attribute and use it in fw_rpc_callback().
--- rust/bindgen_parameters | 2 ++ rust/kernel/fwctl.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-)
rust/bindgen_parameters +2 -0
@@ -27,6 +27,8 @@ --opaque-type spinlock # enums that appear in indirect function calls should specify a cfi type +--newtype-enum fwctl_rpc_scope +--with-attribute-custom-enum=fwctl_rpc_scope='#[cfi_encoding="15fwctl_rpc_scope"]' --newtype-enum lru_status --with-attribute-custom-enum=lru_status='#[cfi_encoding="10lru_status"]'
rust/kernel/fwctl.rs +6 -6
@@ -53,13 +53,13 @@ pub enum DeviceType {#[derive( Copy , Clone , Debug , Eq , PartialEq )] pub enum RpcScope {/// Read/write access to device configuration. -Configuration = bindings::fwctl_rpc_scope_FWCTL_RPC_CONFIGURATION, +Configuration = bindings::fwctl_rpc_scope::FWCTL_RPC_CONFIGURATION .0 ,/// Read-only access to debug information. -DebugReadOnly = bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_READ_ONLY, +DebugReadOnly = bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_READ_ONLY .0 ,/// Write access to lockdown-compatible debug information. -DebugWrite = bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_WRITE, +DebugWrite = bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_WRITE .0 ,/// Full read/write access to all debug information (requires `CAP_SYS_RAWIO`). -DebugWriteFull = bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_WRITE_FULL, +DebugWriteFull = bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_WRITE_FULL .0 , }impl TryFrom <u32 >for RpcScope {
@@ -539,12 +539,12 @@ impl<T: Operations> VTable<T> {/// - `out_len` must be valid for reading and writing an initialised `usize`. unsafe extern "C" fn fw_rpc_callback ( uctx: *mut bindings::fwctl_uctx , - scope:u32 , + scope: bindings::fwctl_rpc_scope , rpc_in: *mut ffi::c_void , in_len:usize , out_len: *mut usize , ) -> *mut ffi::c_void { -let scope =match RpcScope ::try_from (scope) { +let scope =match RpcScope ::try_from (scope.0 ) {Ok (s) => s,Err (e) =>return Error ::to_ptr (e), };
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261020-fwctl-cfi-encoding-70766ce0a03a
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Quoted 7 lines · On Tue, 20 Oct 2026 08:28:37 +0000 Alice Ryhl <[email protected]> wrote:
Currently,
VTable::fw_rpc_callback()takes scope as a u32, whereas C callsfwctl_ops::fw_rpcwith enumfwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing everyfw_rpcindirect call into a Rust fwctl driver to trip a CFI failure. Thus, generatefwctl_rpc_scopeas a newtype with acfi_encodingattribute and use it infw_rpc_callback().
Thanks for the fix. Looks good to me.
BTW: I saw this “lru_status” needs the same treatment, guess bindgen will someday automatically handle this?
Z.
Quoted 70 lines
Fixes e052daab94ee ("rust: introduce abstractions for fwctl")Signed-off-by Alice Ryhl <[email protected]>--- rust/bindgen_parameters | 2 ++ rust/kernel/fwctl.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-)rust/bindgen_parameters +0
-0@@ -27,6 +27,8 @@ --opaque-type spinlock # enums that appear in indirect function calls should specify a cfitype +--newtype-enum
fwctl_rpc_scope+--with-attribute-custom-enum=fwctl_rpc_scope='#[cfi_encoding="15fwctl_rpc_scope"]'
--newtype-enumlru_status--with-attribute-custom-enum=lru_status='#[cfi_encoding="10lru_status"]'rust/kernel/fwctl.rs +1
-1@@ -53,13 +53,13 @@ pub enum DeviceType {#[derive( Copy , Clone , Debug , Eq , PartialEq )] pub enum RpcScope {/// Read/write access to device configuration. -Configuration = bindings::fwctl_rpc_scope_FWCTL_RPC_CONFIGURATION, + Configuration =bindings::fwctl_rpc_scope::FWCTL_RPC_CONFIGURATION.0, /// Read-only access to debug information.
- DebugReadOnly =bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_READ_ONLY,
+ DebugReadOnly =
bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_READ_ONLY.0, /// Write access to lockdown-compatible debug information.rust/kernel/fwctl.rs +1
-1- DebugWrite = bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_WRITE, + DebugWrite = bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_WRITE.0,/// Full read/write access to all debug information (requires
CAP_SYS_RAWIO).
- DebugWriteFull =bindings::fwctl_rpc_scope_FWCTL_RPC_DEBUG_WRITE_FULL,
+ DebugWriteFull =
bindings::fwctl_rpc_scope::FWCTL_RPC_DEBUG_WRITE_FULL.0, }impl TryFrom<u32> for RpcScope {
rust/kernel/fwctl.rs +0
-0@@ -539,12 +539,12 @@ impl<T: Operations> VTable<T> {/// - `out_len` must be valid for reading and writing an initialised
usize. unsafe extern "C" fn fw_rpc_callback(
uctx: *mutbindings::fwctl_uctx,rust/kernel/fwctl.rs +2
-3- scope: u32, + scope: bindings::fwctl_rpc_scope, rpc_in: *mut ffi::c_void, in_len: usize, out_len: *mut usize, ) -> *mut ffi::c_void { - let scope = match RpcScope::try_from(scope) { + let scope = match RpcScope::try_from(scope.0) {Ok (s) => s,Err (e) =>return Error ::to_ptr (e), }; ---base-commit:
c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261020-fwctl-cfi-encoding-70766ce0a03aBest regards,
Alice Ryhl
reviewerQuoted 12 lines · Zhi Wang
Quoted 7 lines · On Tue, 20 Oct 2026 08:28:37 +0000 Alice Ryhl <[email protected]> wrote:
Currently,
VTable::fw_rpc_callback()takes scope as a u32, whereas C callsfwctl_ops::fw_rpcwith enumfwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing everyfw_rpcindirect call into a Rust fwctl driver to trip a CFI failure. Thus, generatefwctl_rpc_scopeas a newtype with acfi_encodingattribute and use it infw_rpc_callback().
Quoted 6 lines
Thanks for the fix. Looks good to me.
Reviewed-by Zhi Wang <[email protected]>BTW: I saw this “lru_status” needs the same treatment, guess bindgen will someday automatically handle this?
I believe lru_status is already handled.
Alice
Zhi Wang
maintainerQuoted 13 lines · On Tue, 20 Oct 2026 11:04:43 +0200 Alice Ryhl <[email protected]> wrote:
Quoted 12 lines · Zhi Wang
Quoted 7 lines · On Tue, 20 Oct 2026 08:28:37 +0000 Alice Ryhl <[email protected]> wrote:
Currently,
VTable::fw_rpc_callback()takes scope as a u32, whereas C callsfwctl_ops::fw_rpcwith enumfwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing everyfw_rpcindirect call into a Rust fwctl driver to trip a CFI failure. Thus, generatefwctl_rpc_scopeas a newtype with acfi_encodingattribute and use it infw_rpc_callback().
Quoted 9 lines
Quoted 6 lines
Thanks for the fix. Looks good to me.
Reviewed-by Zhi Wang <[email protected]>BTW: I saw this “lru_status” needs the same treatment, guess bindgen will someday automatically handle this?
I believe
lru_statusis already handled.
Yes, lru_status is already handled.
I meant that both lru_status and fwctl_rpc_scope need explicit entries in rust/bindgen_parameters. I was wondering whether there are plans for bindgen to generate the newtype and matching CFI encoding automatically for enums used in function-pointer signatures, so future additions wouldn't need the same manual setup.
Quoted 2 lines
Alice
Alice Ryhl
reviewerQuoted 27 lines · Zhi Wang
Quoted 13 lines · On Tue, 20 Oct 2026 11:04:43 +0200 Alice Ryhl <[email protected]> wrote:
Quoted 12 lines · Zhi Wang
Quoted 7 lines · On Tue, 20 Oct 2026 08:28:37 +0000 Alice Ryhl <[email protected]> wrote:
Currently,
VTable::fw_rpc_callback()takes scope as a u32, whereas C callsfwctl_ops::fw_rpcwith enumfwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing everyfw_rpcindirect call into a Rust fwctl driver to trip a CFI failure. Thus, generatefwctl_rpc_scopeas a newtype with acfi_encodingattribute and use it infw_rpc_callback().Quoted 9 lines
Quoted 6 lines
Thanks for the fix. Looks good to me.
Reviewed-by Zhi Wang <[email protected]>BTW: I saw this “lru_status” needs the same treatment, guess bindgen will someday automatically handle this?
I believe
lru_statusis already handled.
Quoted 7 lines
Yes,
lru_statusis already handled.I meant that both
lru_statusandfwctl_rpc_scopeneed explicit entries inrust/bindgen_parameters. I was wondering whether there are plans for bindgen to generate the newtype and matching CFI encoding automatically for enums used in function-pointer signatures, so future additions wouldn't need the same manual setup.
That would be nice, but I'm not aware of anyone working on it.
Alice
Jason Gunthorpe
AppliedQuoted 7 lines · Alice Ryhl
Currently,
VTable::fw_rpc_callback()takes scope as a u32, whereas C callsfwctl_ops::fw_rpcwith enumfwctl_rpc_scope. With kCFI enabled, enum types are encoded distinctly from integers, causing everyfw_rpcindirect call into a Rust fwctl driver to trip a CFI failure. Thus, generatefwctl_rpc_scopeas a newtype with acfi_encodingattribute and use it infw_rpc_callback().
Quoted 7 lines
Fixes e052daab94ee ("rust: introduce abstractions for fwctl")Signed-off-by Alice Ryhl <[email protected]>--- rust/bindgen_parameters | 2 ++ rust/kernel/fwctl.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-)
Applied
Thanks,
Jason