Repository navigation
iio: aop_motion, aop_devmotion: free the IIO device with the device's resources; write the whole buffer scan - #2936
Conversation
The triggered buffer and the trigger of each sensor are resources of the platform device, and the release of the triggered buffer reads the poll function and the buffer out of the IIO device. The IIO device, though, was freed when the driver's data was dropped, which the driver core does before it releases the resources of the device, both on unbind and when a probe fails after the buffer is set up. The buffer release then read an IIO device that was already freed. Hand the IIO device, its private data and the channel table it points to to the resources of the platform device, right after the allocation and before the trigger and the buffer are set up. Resources are released in reverse order, so the buffer and the trigger now go first and the IIO device last. Dropping the driver's data only unregisters the device. MotionIio::new() takes the bound device instead of the platform device, so that a KUnit test can run it on a faux device: the test checks that the private data of the IIO device is still there when the release of the device's resources begins and gone when it has ended. Signed-off-by: Ryan Murray <[email protected]>
A scan is a quaternion and a timestamp: 24 bytes, which the 16-byte alignment of the quaternion rounds up to 32. The IIO core computes the same 32 bytes and copies them all into the buffer, but the last eight were padding of the scan structure, which nothing wrote. Make the tail a field and build the scan in one place that zeroes it, as the accelerometer, gyroscope and temperature drivers already do for their scans. Add a KUnit test that derives the scan size from the channels as the IIO core does, compares it with the structure, and checks that every byte after the timestamp of a freshly built scan is zero. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 6d16ae0.
Rows owed at this head (none posted): aop_motion unbind/rebind under KASAN, plus a devmotion buffered read, on J616s, J713 and M1 Pro. #2910 touches the same |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at 6d16ae09a46537f0588dd12c5208a8a0cdb63c1b.
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready: Pass.
- §3 Safety: Pass —
aop_motion.rs:IioAlloc(owningindio_dev, the foreignArc<State>inpriv_, and pinnedSpec) is registered withdevres::register()immediately afteriio_device_alloc()and before__devm_iio_trigger_alloc(),devm_iio_trigger_register(), anddevm_iio_triggered_buffer_setup_ext(). Ifdevres::register()fails,IioAlloc::drop()freespriv_andindio_devcleanly; otherwise devres unwinds in reverse order (triggered buffer -> trigger ->IioAlloc), eliminating the unbind / late-probe-failure UAF whereiio_triggered_buffer_cleanup()read a freedindio_dev. InIioAlloc::drop(),Drop::dropreclaimspriv_and callsiio_device_free(self.dev)before_specis dropped.aop_devmotion.rs:Scan(#[repr(C, align(16))]) now explicitly declares and zeroespad: u64inScan::new(), closing the 8-byte uninitialized stack-padding leak copied into IIO buffers.
- §4 Clean-room & attribution: Pass — both commits (
4bc3a3cc7f39,6d16ae09a465) carry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:, zero AI trailers in commits. - §5 Evidence: Pending — Rust KUnit cases (
iio_device_is_freed_with_the_device_resources,scan_is_written_in_full) pass (59/60, 1 unrelated skip), but hardware rows (unbind/rebind + KASAN, andaop_devmotionbuffered read on M1 Pro / M2 / J616s / J713) are still owed. - §6 Naming: Pass.
- CI (at review time):
host-testsgreen.
Non-blocking Note
- As noted in the PR body, this touches the same
use kernel::{...}import line inaop_motion.rsas #2910 / #2927; whichever merges second will need a trivial rebase.
Verdict
COMMENT — 0 code/policy blockers and CI is green; waiting on the owed §5 hardware rows before approval.
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at 6d16ae09a465. The lifetime change moves the IIO device below its trigger and buffer in the resource release order. Please extend user-path evidence to an active triggered scan on J413 followed by close or unbind, and check that each scan supplies the full channel layout and timestamp. Coordinate this row with #2927 because both change the same motion drivers.
Keep the device-resource imports for the IIO lifetime fix and the delayed-work import from the current AOP motion driver. Both AOP Rust objects compile for arm64. Signed-off-by: Ryan Murray <[email protected]>
|
The integration conflict is resolved at Both Rust objects compiled for arm64 using the fleet85 configuration and the kernel's corrected bindgen. The previous KUnit result is documented in the body. The physical unbind/rebind and buffered-read rows on J616s, J713 and J316s are still open. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at verified live head dbb9d5a05b87416fac24b48835aad840e6c673be (CI 1/1 green: Host tests / host-tests).
Technical Audit
aop_motion.rslifetime & open-handle safety:IioAlloc(owningindio_dev, the foreignArc<State>inpriv_, and pinnedSpec) is registered viadevres::register()immediately afteriio_device_alloc()and before__devm_iio_trigger_alloc(),devm_iio_trigger_register(), anddevm_iio_triggered_buffer_setup_ext(). Reverse-order devres teardown now runsiio_triggered_buffer_cleanup(indio_dev)-> trigger cleanup ->IioAlloc::drop(), eliminating the unbind and late-probe-failure UAF onindio_dev. Verified againstdrivers/iio/industrialio-core.candindustrialio-buffer.c:MotionIio::drop()callsiio_device_unregister()(cdev_device_deldrains sysfs, disables buffers underinfo_exist_lock, clearsindio_dev->info = NULL, wakes pollers), so any open/dev/iio:deviceXhandle holds&indio_dev->devand returns-ENODEVwithout touchingpriv_orSpec, andiio_dev_release()only puts trigger/buffer refs and frees attribute lists.aop_devmotion.rsparity & scan padding: Verifiedaop_devmotion.rsdoes not share theindio_devUAF becausedevm_iio_kfifo_buffer_setup_ext()registersdevm_iio_kfifo_release(buffer)(referencingbuffer, notindio_dev, withiio_device_attach_buffer()holding its owniio_buffer_get()ref). Adding explicit zeroedpad: u64inScan::new()cleanly closes the 8-byte stack-padding leak into the 32-byte IIO scan buffer, covered by KUnitscan_is_written_in_full.- Merge resolution (
dbb9d5a05b87): Cleanly keeps bothdevresandnew_delayed_workimports inaop_motion.rs.
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready: Pass.
- §3 Safety: Pass (0 code blockers).
- §4 Clean-room & attribution: Pass (all 3 commits including merge
dbb9d5a05b87carry human author/committerRyan Murray <[email protected]>and humanSigned-off-by:only, zero AI trailers in commits; PR body disclosure present). - §5 Evidence: Blocked — see below.
- §6 Naming: Pass.
Remaining Blocker
- §5 — Owed hardware rows & exact-head KUnit rerun: Zero physical hardware rows have been posted yet (both
### Hardware rowsand your comment atdbb9d5a05b87note that physicalaop_motionunbind/rebind andaop_devmotionbuffered-read rows on J616s, J713/J413, and J316s remain open), and the cited KUnit run predates merge commitdbb9d5a05b87(CI only ranhost-tests). Please post the physical hardware rows with the full §5 regression triad (SELinux Enforcing, 0 AVC denials, 0 failed units, 0 new kernel errors) and confirm the Rust KUnit pass atdbb9d5a05b87.
Non-blocking Nit
- Pre-existing OOM error-path nit in
aop_motion.rs:877-897:(*indio_dev).trig = iio_trigger_get(trig)runs beforedevm_iio_triggered_buffer_setup_ext()setsINDIO_BUFFER_TRIGGEREDinindio_dev->modes; if buffer setup fails before setting that mode bit,iio_dev_release()skipsiio_device_unregister_trigger_consumer()and leaks that extra trigger ref. Moving theiio_trigger_get()assignment afterdevm_iio_triggered_buffer_setup_ext()(or checking cleanup) would close that edge case.
Verdict
REQUEST_CHANGES — code is clean; blocked solely on owed §5 hardware evidence (and exact-head KUnit confirmation at dbb9d5a05b87).
|
Physical rows for
All 18 open buffered descriptors returned The exact-head Rust KUnit build found a fixture regression after the merge. Assisted-by: LLM (Codex) |
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at dbb9d5a05b87
Blockers: none.
Checked: no Apple material, no gates. The IIO device is freed with the device's resources (after the trigger and buffer), and the devmotion scan tail is zeroed. Physical rows from modules built at this head on J616s, J713/J413 and J316s: accelerometer and gyroscope unbind/rebind, devmotion buffered reads, Enforcing, 0 AVC, 0 failed units.
Superseded by the review at dbb9d5a
Two lifetime/initialisation fixes in the AOP motion sensor drivers.
Problem and change
No behaviour change beyond the fixes: start/stop and direct-read logic are untouched.
Testing
integration/auroraa7638d5 + this series: Rust group 60 run, 59 passed, 1 skipped (unrelated).iio_device_is_freed_with_the_device_resourcesandscan_is_written_in_fullpass and each FAILS without its fix.Still to run
Hardware rows
Pending: one-shot boots of fleet82 + this series on the default cmdline (M1 Pro, M2, J616s, J473), compared with the same rows on the production kernel. They will be added here.
Reviewer detail
IioAllocowns theiio_dev, theArc<State>inpriv_and the channel table. It is registered withdevres::register()right afteriio_device_alloc(); on failure the allocation is dropped and freed. Devres releases in reverse order: buffer, trigger, thenIioAlloc.MotionIio::droponly unregisters.MotionIio::new()takes&Device<Bound>so the test can run it on a faux device.Scan::new()zeroes the tail; the test derives the scan size the wayiio_compute_scan_bytes()does and checks the tail over a 0xa5-filled slot.use kernel::{...}line (whichever lands second keeps both import sets).