Skip to content

mtd: apple-sftl: accept iOS 9's flag-1 records on 16 GB media (fixes the -74 refusal) - #87

Merged
henrikklee merged 3 commits into
OrchardLinux:armv7from
17xande:p105-16gb-replay2
Dec 2, 2026
Merged

henrikklee merged 3 commits into
OrchardLinux:armv7from
17xande:p105-16gb-replay2

Conversation

@17xande

@17xande 17xande commented Dec 2, 2026

Copy link
Copy Markdown

Problem

The 16 GB iPad mini 1 reader merged in #33 refuses the medium (-EBADMSG at probe, no root) on many boots after iOS has written to the flash. In a loop of cold boots (iOS boot, then Linux) 9 of 13 boots were refused. Two causes were found in the kernel logs of refusing boots:

  • Older-epoch records. iOS's garbage collection writes type-1 flag-1 pages after the checkpoint that keep the epoch of the original write. The reader accepted an older epoch only below the checkpoint.
  • A type-2 flag-1 TRIM record taken for a torn tail. In the failing boot (block 900), replay condition=open-chunk-tag was raised at slot 1592 for the tag 020130dc1b2100000100ffff…: type 2, flag 1, key 0xffff0001 (SFTL_TRIM), epoch equal to its sequence's. The reader only accepts a TRIM as type 2 with flag 0, so it called the page a torn tail and then refused the valid page at slot 1596 (after-torn-page), because nothing may follow a torn page. The same tag appeared in two earlier boots (block 900 slot 48, block 912 slot 1008), always 79 to 95 sequences below the checkpoint.

Changes

  • mtd: apple-sftl: accept older-epoch flag-1 records after a 16 GB checkpoint
  • mtd: apple-sftl: accept iOS 9's type-2 flag-1 TRIM records on 16 GB media - open blocks and closed-block summaries; the epoch must equal the sequence's. Above the checkpoint replay consumes such a record's sequence but does not unmap anything: the flag-1 payload layout is unverified, and a missed TRIM only leaves stale data in LBAs the filesystem already treats as free. Whether closed-summary flag-1 TRIMs explain the other refusals is not confirmed.
  • mtd: apple-sftl: test refusal of a flag-1 TRIM in a 64 GB closed summary

Both rules are gated on the 16 GB geometry (hidden_tail_type2); 64 GB behaviour is unchanged and tested.

Testing

  • KUnit (UML): 93/93 apple-sftl* cases pass, including new cases for the failing sequences, for the 64 GB refusals and for the gate. Each rule was reverted in turn (flag-1 journal acceptance, epoch check, 16 GB gate, skip-apply, closed-summary acceptance): a test fails for every one.
  • Device, 16 GB iPad mini 1 (iOS 9.3.5, kDFU then orchard run --autogo, this branch on the merged armv7): 6 cold boots out of 6 read the flash (journal replayed, applesftl0 read-only, root mounted, system running, no -EBADMSG), at sequences 555842041 to 556104308. The same test on the merged series (with a debug build) failed 9 of 13.

Not covered

Six boots is good evidence, not proof: the refusal depends on what iOS has written recently. Only chunk 0 of the TRIM page was logged. Boots refused for another reason (earlier closed-summary conditions) are not located.

Written with LLM assistance (each commit carries Assisted-by: LLM); the results above were run, not inferred.

Note for review order: the draft #69 also changes apple-sftl-core.c and apple-sftl-test.c (iPhone 5 NAND work, much larger). This change is independent and small; I will rebase it if #69 lands first, and #69 will need to carry these journal rules if it lands second.

…kpoint

On a 16 GB iPad mini running iOS 9.3.5, journal collection failed one
or two page reads after a checkpoint-covered record in the flag-1
stream in two of nine failed boots. This timing suggests that iOS GC
continued the stream after the checkpoint with type-1/flag-1 records
that retained the original user epoch. GC is an inference: the rejected
tags have not been captured, and the hypothesis still needs device
confirmation. A later successful capture did show older-epoch flag-1
data above the checkpoint, including in a reused context block.

Boot f-1 later exposed an open-block torn-tail refusal caused by a
type-2 flag-1 TRIM; that case is fixed separately. Suspected
closed-summary refusals were never located.

Allow that record shape after the checkpoint on the 16 GB geometry.
The original epoch cannot exceed the sequence epoch and the key must be
within the exported disk. Replay still requires a gapless sequence run,
and the highest sequence for a key wins, as it already does for flag-0
relocations and for flag-1 runs in closed blocks, whose summary epochs
the reader does not check. The user epoch only feeds per-block age
statistics. The shared check also covers a context spare reused after
the checkpoint; a first page there that mixes checkpoint-covered and
newer records is still refused, as the checkpoint's role table would
have named such a block as data. Type-2 rules are unchanged.

A full open block ending in such records is now refused, where its last
page was taken as torn before.

Keep 64 GB unchanged: it is writable, so a checkpoint saved after a
wrong acceptance would persist it, and no 64 GB medium has shown the
shape. The 16 GB layout is read-only.

Exercise moves after a native checkpoint, including a reused context
spare and a block that straddles the checkpoint, and check that future
epochs, hidden keys and sequence gaps remain rejected.

Assisted-by: LLM
Signed-off-by: Alexandre Figueiredo <17xande@gmail.com>
…edia

A 16 GB iPad mini (P105) running iOS 9.3.5 refused the flash with
-EBADMSG at probe on boot f-1, with the older-epoch change applied:

  block=900 slot=1592 seq=555473968 checkpoint=555474063
    tag=020130dc1b2100000100ffff1b210000   (treated as a torn tail)
  block=900 slot=1596 seq=555488956 checkpoint=555474063
    tag=0100bc161c210000042f0500dd200000   (valid record after it)

The first tag is type 2, flag 1, key 0xffff0001 (SFTL_TRIM), with a
user epoch matching the sequence epoch. Two earlier boots logged the
same tag 79 sequences below their checkpoints. The reader accepted only
flag-0 TRIMs, so it mistook the page for a torn tail and refused the
next valid page in the open block.

Fix that open-block torn-tail cause by accepting the flag-1 tag with a
matching epoch on the 16 GB geometry, which already accepts iOS 9's
type-2 flag-1 hidden tail. Use the same journal validation for TRIMs
referenced by closed-block summaries. A flag-1 TRIM in such a summary
could plausibly explain a refusal, but the suspected closed-summary
refusals were never located and no capture confirms this.

Above the checkpoint, consume each accepted flag-1 TRIM sequence
without applying its payload. The payload format is unverified and
flag 1 may denote a relocated TRIM, which could discard newer data if
applied. A missed TRIM only leaves stale data in LBAs the filesystem
already treats as free. Leave flag-0 replay unchanged.

Test the observed open-block shape, sequence consumption with mappings
preserved in open and closed blocks, invalid tags and torn tails, and
refusal of a flag-1 TRIM followed by valid data on 64 GB media.

Assisted-by: LLM
Signed-off-by: Alexandre Figueiredo <17xande@gmail.com>
The 64 GB geometry accepts only flag-0 TRIMs. A closed block's
summary names its TRIM records, and each is validated like an open
block's. Cover that path with a summary whose last record is a TRIM:
flag 0 loads, flag 1 is refused with -EBADMSG.

Assisted-by: LLM
Signed-off-by: Alexandre Figueiredo <17xande@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants