Commit a075082
rust: pin-init: internal: init: remove
Gary noticed [1] that the initializer macros as well as the `[Pin]Init`
traits cannot support unaligned fields, since they use operations that
require aligned pointers. This means that any code using structs with
unaligned fields in pin-init is unsound.
By default, the `init!` macro generates references to initialized fields,
which makes the compiler check that those fields are aligned. However,
we added the `#[disable_initialized_field_access]` attribute to avoid
this behavior in commit ceca298 ("rust: pin-init: internal: init:
add escape hatch for referencing initialized fields"). Thus remove the
`#[disable_initialized_field_access]` attribute from `init!`, which is
the only safe way to create an initializer handling unaligned fields.
If support for in-place initializing structs with unaligned fields is
required in the future, we could figure out a solution. This is tracked
in [2].
Reported-by: Gary Guo <gary@garyguo.net>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/561532-pin-init/topic/initialized.20field.20accessor.20detection/with/576210658 [1]
Link: Rust-for-Linux/pin-init#112 [2]
Fixes: ceca298 ("rust: pin-init: internal: init: add escape hatch for referencing initialized fields")
Signed-off-by: Benno Lossin <lossin@kernel.org>
Acked-by: Janne Grunau <j@jannau.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260302140424.4097655-1-lossin@kernel.org
[ Adjusted tags and reworded as discussed. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>#[disable_initialized_field_access]
1 parent dda1350 commit a075082
1 file changed
Lines changed: 8 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
| |||
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 148 | + | |
157 | 149 | | |
158 | 150 | | |
159 | 151 | | |
| |||
236 | 228 | | |
237 | 229 | | |
238 | 230 | | |
239 | | - | |
240 | 231 | | |
241 | 232 | | |
242 | 233 | | |
| |||
272 | 263 | | |
273 | 264 | | |
274 | 265 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | 266 | | |
283 | 267 | | |
284 | 268 | | |
285 | 269 | | |
286 | 270 | | |
287 | 271 | | |
288 | 272 | | |
289 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
290 | 276 | | |
291 | 277 | | |
292 | 278 | | |
| |||
326 | 312 | | |
327 | 313 | | |
328 | 314 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | 315 | | |
337 | 316 | | |
338 | 317 | | |
339 | 318 | | |
340 | 319 | | |
341 | 320 | | |
342 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
343 | 324 | | |
344 | 325 | | |
345 | 326 | | |
| |||
466 | 447 | | |
467 | 448 | | |
468 | 449 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | 450 | | |
474 | 451 | | |
475 | 452 | | |
| |||
0 commit comments