{"record":{"id":"cf8217554dabc24c","repo":"Hmbown/CodeWhale","slug":"android-loaded-image-identity-changed-proc-self","errorCode":null,"errorMessage":"Android loaded-image identity changed: /proc/self/maps has device/inode {:x}:{:x}:{}, but update target {} is {:x}:{:x}:{}; refusing to replace it","messagePattern":"Android loaded-image identity changed: /proc/self/maps has device/inode (.+?):(.+?):(.+?), but update target (.+?) is (.+?):(.+?):(.+?); refusing to replace it","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/update.rs","lineNumber":519,"sourceCode":"#[cfg(any(target_os = \"android\", all(test, unix)))]\nfn validate_android_mapping_identity(\n    mapping: &AndroidImageMapping,\n    candidate: &Path,\n) -> Result<()> {\n    use std::os::unix::fs::MetadataExt;\n\n    let candidate_metadata = std::fs::metadata(candidate).with_context(|| {\n        format!(\n            \"failed to stat Android update target {}\",\n            candidate.display()\n        )\n    })?;\n    let (candidate_major, candidate_minor) = android_device_parts(candidate_metadata.dev());\n    let identity_matches = mapping.device_major == candidate_major\n        && mapping.device_minor == candidate_minor\n        && mapping.inode == candidate_metadata.ino();\n    if !identity_matches {\n        bail!(\n            \"Android loaded-image identity changed: /proc/self/maps has device/inode {:x}:{:x}:{}, but update target {} is {:x}:{:x}:{}; refusing to replace it\",\n            mapping.device_major,\n            mapping.device_minor,\n            mapping.inode,\n            candidate.display(),\n            candidate_major,\n            candidate_minor,\n            candidate_metadata.ino()\n        );\n    }\n    Ok(())\n}\n\n#[cfg(any(target_os = \"android\", all(test, unix)))]\nfn android_device_parts(device: u64) -> (u32, u32) {\n    // Linux/Bionic's dev_t encoding, matching makedev(3), major(3), and\n    // minor(3). `/proc/self/maps` renders these components in hexadecimal.\n    let major = ((device >> 8) & 0xfff) as u32;","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/update.rs#L501-L537","documentation":"After resolving the update target, the updater compares the device (major:minor) and inode recorded from the /proc/self/maps row against the stat() of the resolved file. If they differ, the file on disk is no longer the inode the process is executing from — the image was replaced or swapped underneath the running process — and the updater refuses to overwrite it, since the running binary could not be safely identified with the target path anymore.","triggerScenarios":"validate_android_mapping_identity, called from android_loaded_executable_proof_report during android_loaded_executable_proof, when mapping.device_major/device_minor/inode do not equal the stat dev/ino of the canonicalized target path.","commonSituations":"Another process (installer, sync client, prior updater instance) replaced the binary via rename while this process ran; a bind mount or overlay made canonicalize() resolve to a different inode than the mapped one; filesystem corruption or container layer weirdness.","solutions":["Stop whatever is replacing the binary, reinstall the intended release, and re-run the update from the freshly started process.","Verify identity manually: compare the device/inode from the error message against `stat` output for the target path.","Ensure the path is not on overlayfs/bind mounts that alias inodes; run the update from the real underlying storage.","Restart the device/app environment if a stale mapping is suspected, then retry once."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"use std::os::unix::fs::MetadataExt;\nlet md = std::fs::metadata(&target)?;\nif md.ino() != expected_inode || md.dev() != expected_dev {\n    eprintln!(\"target inode changed underneath the running process; refusing update\");\n    return Err(anyhow!(\"loaded-image identity changed\"));\n}","typeGuard":null,"tryCatchPattern":"match run_update() {\n    Err(e) if e.to_string().contains(\"identity changed\") => {\n        // restart the freshly installed binary by full path and retry\n    }\n    other => other?,\n}","preventionTips":["Serialize all installers/updaters that touch the binary path.","Avoid overlayfs/bind mounts for the install location.","Reinstall the release and restart the process after any suspected swap.","Compare stat dev/ino against maps before any manual replacement."],"tags":["android","self-update","inode","race-condition"],"backgroundTag":"internal-invariant-violation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}