Skip to content

worker: restore and archive safety fixes - #19

Open
ash-iir wants to merge 12 commits into
VD171:mainfrom
ash-iir:up-restore-safety
Open

ash-iir wants to merge 12 commits into
VD171:mainfrom
ash-iir:up-restore-safety

Conversation

@ash-iir

@ash-iir ash-iir commented Nov 19, 2026

Copy link
Copy Markdown

What

Fixes in the restore and archive paths of worker.sh (plus the shared package-name check in helper.sh): restores no longer wipe data they then fail to restore, archives are checked (readable, members inside the app's own dir) before anything is deleted, a wrong passphrase is reported up front, failed APK installs fail the restore, and operation secrets stay off process argv.

One commit per fix, so any of them can be dropped on its own. Each line links the draft PR on my fork that has the full write-up and repro for that fix.

  • worker: stop restores from wiping data they cannot restore (details)
  • scripts: share one package-name check (details)
  • worker: verify special archives before replacing provider data (details)
  • worker: keep remote-only staging root-only (details)
  • worker: freeze only app uids, in the right user (details)
  • worker: refuse path restores onto whole storage roots (details)
  • worker: harden archive member validation on restore (details)
  • worker, helper: keep operation arguments off process argv (details)
  • worker: report a wrong passphrase before an encrypted restore (details)
  • worker: fail snapshot, mirror and import restores when the APK install fails (details)
  • worker: fail a special backup that is incomplete or empty (details)

Checklist

  • The project banner header is present on every new/changed source file. (no new files)
  • Code and comments are in English; no em/en-dashes.
  • If a UI label changed, all lang/<code>.json and README.<code>.md were updated. (no UI label changes)
  • No real feature (SELinux/uid-gid/modes preservation, etc.) was weakened.
  • Commits are signed off (git commit -s).
  • Tested on a rooted device/emulator (note which). Not tested on a rooted device or emulator. Checked with sh -n, mksh -n, busybox sh -n and shellcheck -s sh (no new warnings), small mksh/busybox repro scripts per fix, and the tools/screenshots Playwright mocks (en and ar) for WebUI changes.

Notes

list_safe reads the tar listing from a here-doc: under mksh printf is external, and a listing above ARG_MAX (tested with 30,000 members) made the check pass without scanning. The Telegram 2FA password is still passed on argv; moving it needs mtproto-store to read it from a file or env (VictorGabriel7Dev/mtproto-store#1 is related).

The five grouped PRs (restore safety, scheduler, destinations, WebUI fixes, performance) merge cleanly together in any order; I checked that combining all of them gives the same tree as my test build.

- Encrypted special restore piped the decrypted stream into decomp, which
  reads its file argument and ignores stdin, so tar got no input after the
  live data was already removed. Add decomp_in (stdin, codec by filename)
  and use it there and in archive_safe.
- archive_safe only checked member paths, so a listing that failed or was
  empty (wrong passphrase, unreadable archive) passed and the target was
  wiped before extraction failed. list_safe now also requires tar -t to
  succeed and list at least one member; the Neo import check uses it too.
- cleanup() removed staging files matching *$OPID*, so op-1 also removed
  op-10/op-11 files of running workers. Match .$OPID and .$OPID.* only.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit 534a2f0)
Under mksh printf is an external command, so a large listing passed as
one argument hit ARG_MAX, printf failed and scan_members read an empty
stdin and returned 0. Read the listing from a here-doc instead, and fail
on an empty listing directly.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit a818ee6)
worker.sh and helper.sh each repeated a slightly different case pattern
for package names. Replace them with valid_pkg, which accepts only
[A-Za-z0-9._] without a leading dot, the same rule Android uses.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit 42fff6b)
do_special_restore wiped the target before checking the item's sha256,
and accepted any /data path from the manifest. Check the sha256 first, as
restore() does, and only restore into a path the category owns
(special_candidates, split out of special_paths).

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit 2aa52d7)
The staging dir was created with the inherited umask and media_own -R then
handed the finished backup to media_rw, so it was not root-only while it
waited for upload. Create the staging root 0700 and skip media_own for
remote-only backups, which are never listed under /sdcard.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit e3ec8d6)
freeze() killed every process of the uid that owns /data/data/<pkg>. For
a system app sharing uid 1000 that includes system_server (soft reboot),
and /data/data is always user 0, so a secondary-user op stopped the
user-0 instance. Read /data/user/$U and fall back to pidof below 10000.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit 0d143f8)
do_path_restore wipes its target before extracting. Refuse targets that
would take a whole user or storage root with it (/sdcard, /data/media/N,
/data/user/N, /data/<dir>) and /data/adb.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit b72a4a3)
App archives are extracted into a shared parent directory (the user's
data dir, Android/data, the profiles dir). Validate that every member of
such an archive stays under the app's own top-level entry before it is
extracted: <pkg> for data, data_de, external, obb and media archives,
ref/<pkg> and cur/<user>/<pkg> for ART profiles. The same check is used
by restore-test and the DataBackup import. Archives without a base keep
the existing absolute-path and '..' check.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit 24aa5b9)
detach() now hands the worker its arguments in a 0600 file under the
root-only state dir instead of argv; the worker reads it once and removes
it. jget and the age passphrase feed use here-docs instead of printf,
which is not a builtin in mksh and would otherwise run as an external
command with the data in its arguments.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit a32aabc)
Add age_pass_ok, which decrypts a short prefix of an age file (one
scrypt KDF, no full decrypt) to tell whether the passphrase opens it.
App, special and path restores run it before the archive check and the
wipe, so a wrong passphrase ends with ERR_CRYPTO_PASS and the WebUI asks
for the passphrase again. restore-test reports it as pass:<archive>.
The adb restore probe uses the same helper instead of a full decrypt.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit a8f6f1a)
…l fails

Only restore() checked that the package was installed after the install
session. Snapshot and Mirror restores and the Neo-Backup and DataBackup
imports ignored a failed install, then restored the data and reported
success.

- New install_ok: the same pm path --user check as restore(), with
  ERR_INSTALL on failure; used after each of the four install steps.
- Create the install session only when there are APKs to write.
- Neo import: a decrypt failure (APK or data archive) now ends with
  ERR_IMPORT_ENCRYPTED, so the WebUI asks for the password again,
  instead of skipping the item and reporting success. A session opened
  for the APKs is abandoned.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit e12faab)
A special backup reported success even when nothing usable was written:
there was no crypto check, archive failures were dropped silently, the
tar exit status was masked, and the only test was a non-empty manifest.

- Check crypto_available up front when a passphrase is set.
- Use the same .trc sentinel and read-back check as archive_dir for
  each archive; a failure removes that archive and fails the backup.
- Fail when a selected category produced no item.
- A failed special backup removes its incomplete directory.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
(cherry picked from commit ea24deb)
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.

1 participant