Skip to content

Apply stored directory modes after extraction - #157

Open
silversword411 wants to merge 2 commits into
AppImage:mainfrom
silversword411:restore-extracted-dir-modes
Open

silversword411 wants to merge 2 commits into
AppImage:mainfrom
silversword411:restore-extracted-dir-modes

Conversation

@silversword411

Copy link
Copy Markdown

Problem

After #152 (8f39b89), --appimage-extract makes all directories with mode 0700. It does not use the mode that the squashfs image stores for each directory. Files get the correct mode. The problem occurs only with directories.

#152 changed mkdir_p(). The goal of #152 was to protect the $TMPDIR/appimage_extracted_<digest> directory of --appimage-extract-and-run. But extract_appimage() uses mkdir_p() for each directory in the image, in both extract modes. After the extractor writes a file, it sets the stored mode on that file (L883). It does not do this for directories (L806-L815). Because of this, each directory keeps mode 0700.

Steps to reproduce

Use an AppImage that contains runtime 8f39b89. For example, use audacity-linux-4.0.1-x86_64.AppImage from the Audacity 4.0.1 release.

$ umask
0022
$ ./audacity-linux-4.0.1-x86_64.AppImage --appimage-version
AppImage runtime version: https://github.com/AppImage/type2-runtime/commit/8f39b89
$ ./audacity-linux-4.0.1-x86_64.AppImage --appimage-extract >/dev/null
$ stat -c "%a %n" squashfs-root squashfs-root/bin squashfs-root/lib squashfs-root/AppRun
700 squashfs-root
700 squashfs-root/bin
700 squashfs-root/lib
755 squashfs-root/AppRun
$ find squashfs-root -type d -printf "%m\n" | sort | uniq -c
    144 700

Mount the same image with --appimage-mount. All 144 directories show mode 755. Thus, the image is correct, and the extractor causes the problem.

Impact

Distribution packages frequently use --appimage-extract to repackage an AppImage. An example is the Arch AUR package audacity4-bin. This package extracts the AppImage. Then it copies the result into /opt with cp -a.

After you install the package as root, all directories are root:root 0700. Users that are not root cannot open /opt/audacity4-bin. Thus, /usr/bin/audacity4 points to a file that they cannot get access to. The application does not start, and it shows no error.

Other packages that extract and then copy with the modes (cp -a, rsync -a, tar) will have the same problem. The problem starts when a new build of their AppImage uses the current runtime.

Changes

This PR uses 0700 only where #152 needs it. This is the extract-and-run target.

  • Directories still get mode 0700 while the extractor writes their contents.
  • After extraction, the extractor sets the stored mode on each directory, deepest directory first. Thus, a directory without owner write permission (for example, 0555) does not stop the extraction of its contents.
  • The extractor also sets the stored mode on the parent directories of paths that match a pattern.
  • For --appimage-extract, squashfs-root gets the mode of the image root.
  • For --appimage-extract-and-run, the top-level $TMPDIR/appimage_extracted_<digest> directory keeps mode 0700. This mode alone prevents access by other users to all items below it.

Tests

I compiled the runtime with clang and the CFLAGS of src/runtime/Makefile (with -Wall -Werror, without -static), against squashfuse 0.5.2. I used appimagetool to make a test AppImage with these directory modes: 751 (image root), 755, 750, 555 (with a file and a subdirectory), 711, and 1777.

Test 8f39b89 This PR
--appimage-extract All directories 700 Same modes as the image
--appimage-extract again, into the same squashfs-root All directories 700 Same modes as the image, no errors
--appimage-extract usr/share/pub All directories 700 Same modes as the image, parent directories included
APPIMAGE_EXTRACT_AND_RUN=1 NO_CLEANUP=1 All directories 700 Prefix 700, contents with the same modes as the image
Normal run (FUSE mount) No change No change

With the Audacity 4.0.1 payload and the runtime of this PR, --appimage-extract gives 144 directories with mode 755.

Temporary workaround for packagers: after you extract the AppImage, use this command: find squashfs-root -type d -exec chmod 755 {} +.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Build for testing:
artifacts aarch64
artifacts x86_64
artifacts i686
artifacts armhf
Use at your own risk.

@probonopd probonopd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clear reproduction. The fix is correct; one regression should be addressed before merging.

What holds up. Since #152, mkdir_p() creates directories with 0700 and the extractor never applied the stored modes, so every extracted directory stayed 0700; the Audacity AUR breakage follows from that. The PR records the stored mode of every directory during traversal and applies them after extraction, deepest first, which is the right order (a parent's mode can then no longer block its children), and leaves the extract-and-run prefix at 0700 as #152 intends. The error paths free the new allocations, sqfs_dentry_is_dir() and sqfs_inode_get() are used correctly against squashfuse 0.5.2, and directories skipped by a pattern are handled through ENOENT. For --appimage-extract, applying the exact stored modes matches what unsquashfs does.

The regression. In extract-and-run mode the subdirectories now also get their stored modes. A directory stored without owner write permission (0555; some Python and Qt trees carry such directories) then cannot have its contents removed by rm_recursive(), which walks with nftw() and never changes modes, so the self-cleanup in /tmp fails and leaves the tree behind. Before this PR that could not happen, because the directories were always 0700 (and 0755 before #152). Two possible fixes: apply mode | S_IWUSR when private_prefix is set, or make rm_recursive_callback() chmod a directory before removing its contents.

Minor. dir_modes is allocated as inodes × sizeof(struct dir_mode) up front plus one strdup() per directory. Fine for typical images; a comment on the bound would help for very large ones.


Generated by Claude Code

silversword411 and others added 2 commits November 6, 2026 17:20
Since AppImage#152, mkdir_p() creates all directories with mode 0700, and
--appimage-extract never set the stored mode on directories. Thus all
extracted directories kept mode 0700.

Directories still get mode 0700 while the extractor writes their
contents. After extraction, the extractor now sets the stored mode on
each directory, deepest directory first. For --appimage-extract, the
prefix directory gets the mode of the image root. The extract-and-run
prefix keeps mode 0700.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Applying the stored modes in extract-and-run mode let a directory
without owner write permission (for example 0555) block rm_recursive(),
which never changes modes. The cleanup in $TMPDIR then failed and left
the extracted tree behind.

In extract-and-run mode, OR S_IRWXU into every directory's stored mode.
The prefix directory already stays 0700, so no other user can reach the
tree. --appimage-extract still reproduces the stored modes exactly.

Also fail cleanly when strdup() of a directory path fails, and document
the bound of the dir_modes allocation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@silversword411

Copy link
Copy Markdown
Author

Thanks for the review. Fixed in cb3c975: in extract-and-run mode the extractor now ORs S_IRWXU into each directory's stored mode (not just S_IWUSR, since nftw() also needs read and search permission to descend). The prefix stays 0700, so nothing below it becomes reachable for other users, and --appimage-extract still reproduces the stored modes exactly.

Also added the bound comment on dir_modes and a check for a failed strdup(). Rebased onto main.

Re-ran the test matrix from the description, plus a new case: extract-and-run with cleanup on an image with a 0555 directory. With 12c905a the cleanup fails with Permission denied and leaves the tree in $TMPDIR; with this commit $TMPDIR is empty afterwards. Plain --appimage-extract output is unchanged.

@silversword411
silversword411 force-pushed the restore-extracted-dir-modes branch from 12c905a to cb3c975 Compare November 19, 2026 08:12
@github-actions

Copy link
Copy Markdown

Build for testing:
artifacts i686
artifacts armhf
artifacts x86_64
artifacts aarch64
Use at your own risk.

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