Skip to content

feat: restore extended attributes during file extraction - #138

Merged
qkaiser merged 2 commits into
onekey-sec:mainfrom
rikard-soderstrom:feat/preserve-xattr
Sep 1, 2026
Merged

feat: restore extended attributes during file extraction#138
qkaiser merged 2 commits into
onekey-sec:mainfrom
rikard-soderstrom:feat/preserve-xattr

Conversation

@rikard-soderstrom

Copy link
Copy Markdown
Contributor

ubireader_extract_files already parses each inode's xent (xattr entry) nodes while walking the filesystem, but silently discards them - no extended attribute is ever written to an extracted file, regardless of what the source UBIFS image actually contains (e.g. security.ima/ security.evm signatures, SMACK labels).

Add a --preserve-xattr flag (mirroring the existing --keep-permissions one, also root-only) that resolves each xent to its target inode and writes it via os.setxattr(). Xattr values are stored inline in their own inode's data field rather than as separate UBIFS_DATA_KEY nodes - the same mechanism decrypt_symlink_target() already relies on for symlink targets - so extraction reuses that same access pattern rather than the regular-file data-node reader.

@qkaiser
qkaiser self-requested a review August 31, 2026 12:00
@qkaiser qkaiser added enhancement python Pull requests that update python code labels Aug 31, 2026
Comment thread ubireader/ubifs/output.py
Comment thread ubireader/ubifs/output.py
Comment thread ubireader/ubifs/output.py Outdated
@qkaiser
qkaiser force-pushed the feat/preserve-xattr branch from 997d511 to f74c52c Compare September 1, 2026 07:18
@qkaiser

qkaiser commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Initial approach was a bit naive in regards to security.evm which requires ownership, timestamps, and metadata to be set before writing it otherwise later protected-xattr writes can be rejected by EVM validation or leave the copied EVM signature stale.

Fixed with f74c52c

ubireader_extract_files already parses each inode's xent (xattr entry)
nodes while walking the filesystem, but silently discards them - no
extended attribute is ever written to an extracted file, regardless of
what the source UBIFS image actually contains (e.g. security.ima/
security.evm signatures, SMACK labels).

Add a --preserve-xattr flag (mirroring the existing --keep-permissions
one, also root-only) that resolves each xent to its target inode and
writes it via os.setxattr(). Xattr values are stored inline in their
own inode's data field rather than as separate UBIFS_DATA_KEY nodes -
the same mechanism decrypt_symlink_target() already relies on for
symlink targets - so extraction reuses that same access pattern rather
than the regular-file data-node reader.

The extraction root's timestamps, ownership, and mode are restored
before its xattrs. security.evm is always written after all other
xattrs.
@qkaiser
qkaiser force-pushed the feat/preserve-xattr branch from ddf4a82 to b8b8bad Compare September 1, 2026 11:36
@qkaiser
qkaiser enabled auto-merge September 1, 2026 11:37
@qkaiser
qkaiser merged commit f2197d4 into onekey-sec:main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants