From: Peder Bergan via B4 Relay <devnull+peder.bergan.gmail.com@kernel.org>
To: Miguel Ojeda <ojeda@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Carlos Llamas" <cmllamas@google.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Jules Mercier" <jules@les-mercier.fr>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v2] rust: bindgen: Preserve sched_statistics alignment
Date: Fri, 20 Nov 2026 18:19:17 +0100 [thread overview]
Message-ID: <20261120-fix-schedstats-bindgen-layout-v2-1-1c42e4a996ae@gmail.com> (raw)
From: Peder Bergan <peder.bergan@gmail.com>
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@les-mercier.fr>
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@les-mercier.fr>
Cc: stable@vger.kernel.org # 6.12.x
Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
---
Changes in v2
- Explain how the bindgen 0.73.2 padding change exposes the missing alignment.
- Link the bindgen bug and request stable backports starting with 6.12.x.
- Credit Jules Mercier's report and OnePlus 6T test, and expand the Binder Cc list.
I kept the opaque rule unconditional as discussed. On bindgen 0.73.1,
I found an offset mismatch at task_struct.se before sched_statistics.
I also checked an arm64 6.12.y build with bindgen 0.73.2 and schedstats
disabled. With the rule applied in the 6.12.y context, the Rust
task_struct.pid offset moved from 1208 to 1216, matching C.
v1 on lore.kernel.org
https://lore.kernel.org/rust-for-linux/20261119-fix-schedstats-bindgen-layout-v1-1-0599dd230ffd@gmail.com/
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..65c308d4b603b 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 sched_statistics opaque preserves its 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@gmail.com>
reply other threads:[~2026-11-20 17:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120-fix-schedstats-bindgen-layout-v2-1-1c42e4a996ae@gmail.com \
--to=devnull+peder.bergan.gmail.com@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jules@les-mercier.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=peder.bergan@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®