[PATCH v3] rust: bindgen: Preserve sched_statistics alignment
From: Peder Bergan via B4 Relay
Date: Mon Nov 23 2026 - 11:43:49 EST
From: Peder Bergan <peder.bergan@xxxxxxxxx>
With CONFIG_SCHEDSTATS disabled, struct sched_statistics is empty but
still cache-line aligned. Bindgen omits the alignment of the empty
type. Bindgen 0.73.2 also stopped forcing padding before over-aligned
fields, so fields following stats can be misplaced in the generated
task_struct. On the reported arm64 build, Rust Binder reads the wrong
pointer via CurrentTask::mm() and rejects mmap() with -EINVAL.
Make sched_statistics opaque so bindgen uses the C size and alignment.
Rust has no callers that access the fields of this type.
Reported-by: Jules Mercier <jules@xxxxxxxxxxxxxx>
Closes: https://github.com/Rust-for-Linux/linux/issues/1269
Link: https://github.com/rust-lang/rust-bindgen/issues/3549
Tested-by: Jules Mercier <jules@xxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx # 6.12.x
Signed-off-by: Peder Bergan <peder.bergan@xxxxxxxxx>
---
Changes in v3:
- I generalized the comment to cover any types listed below it.
- Link to v2: https://lore.kernel.org/rust-for-linux/20261120-fix-schedstats-bindgen-layout-v2-1-1c42e4a996ae@xxxxxxxxx/
OpenAI Codex assisted with the bindgen change, validation and drafting.
---
rust/bindgen_parameters | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters
index 5bab3cf063360..ef9379312fce9 100644
--- a/rust/bindgen_parameters
+++ b/rust/bindgen_parameters
@@ -26,6 +26,12 @@
# warning. We don't need to peek into it anyway.
--opaque-type spinlock
+# Bindgen omits the alignment of empty structs. Bindgen 0.73.2 also stopped
+# forcing padding before over-aligned fields, so following fields can be
+# misplaced. Making the types below opaque preserves their C alignment.
+# https://github.com/rust-lang/rust-bindgen/issues/3549
+--opaque-type sched_statistics
+
# 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"]'
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261119-fix-schedstats-bindgen-layout-0935b6434707
Best regards,
--
Peder Bergan <peder.bergan@xxxxxxxxx>