Skip to content

Disallow mounting folders on the guest's root for WASIX modules#5475

Merged
Arshia001 merged 2 commits intomainfrom
feat/disallow-mount-on-root
Jan 8, 2026
Merged

Disallow mounting folders on the guest's root for WASIX modules#5475
Arshia001 merged 2 commits intomainfrom
feat/disallow-mount-on-root

Conversation

@Arshia001
Copy link
Member

No description provided.

@Arshia001 Arshia001 requested a review from syrusakbary as a code owner March 12, 2025 11:34
@Arshia001 Arshia001 requested review from charmitro and theduke March 12, 2025 11:34
@promptless
Copy link

promptless bot commented Mar 12, 2025

📝 Documentation updates detected! A separate PR for documentation updates has been made here: wasmerio/docs.wasmer.io#122

@charmitro
Copy link
Contributor

Also,

Tested-by: Charalampos Mitrodimas charalampos@wasmer.io

@syrusakbary
Copy link
Member

This PR might have some implications, that we don't want. I remember other programs using mapdir=.:/ to make Python work for example. We may want to use that directory instead (and not mount any other dir) if / is provided. Lets follow up in a sync

@Arshia001
Copy link
Member Author

Arshia001 commented Mar 12, 2025

@syrusakbary in fact, that's exactly what this PR is trying to prevent. Mounting things on / messes up a lot of assumptions in WASIX, including:

  • We put commands from packages in /bin and /usr/bin. If / is mounted, those will get overwritten and be inaccessible.
  • Packages mount volumes, which contain necessary files without which they won't run. Python is in fact a great example of this. If I were to just mount something on /, I'd lose all the data files that came with the python package, ending up with a broken application.
    • Same with PHP, if I mount a website's root on /, I lose all the openssl data files and HTTPS will be broken for example.
    • I do believe python was the motivation behind the custom behavior of mounting . on /home with --dir .. I think that's what you're thinking of as well.

@marxin marxin added this to the v7.0 milestone Dec 16, 2025
@marxin
Copy link
Contributor

marxin commented Dec 18, 2025

@Arshia001 The PR seems to be pretty close to be merged, can you rebase it?

Copilot AI review requested due to automatic review settings January 5, 2026 14:58
@Arshia001 Arshia001 force-pushed the feat/disallow-mount-on-root branch from 3d9591b to e83e944 Compare January 5, 2026 14:58
@Arshia001 Arshia001 requested review from zebreus and removed request for syrusakbary and theduke January 5, 2026 14:59
@Arshia001 Arshia001 force-pushed the feat/disallow-mount-on-root branch from e83e944 to db04d04 Compare January 5, 2026 15:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds validation to prevent mounting folders on the guest's root directory ("/") for WASIX modules, addressing a security and filesystem organization concern. The restriction is enforced at multiple levels of the stack to ensure comprehensive coverage.

  • Added is_wasix parameter throughout the call chain to differentiate WASIX from regular WASI modules
  • Implemented validation checks in package loading, filesystem mounting, and CLI argument processing
  • Created a new error type MountOnRoot for clear error reporting

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lib/wasix/src/runtime/package_loader/load_package_tree.rs Added validation in filesystem_v3 and filesystem_v2 to reject mounts at "/"; removed unused sorting code
lib/package/src/package/package.rs Added MountOnRoot error variant and validation check in Package construction for wasmer.toml files
lib/cli/src/commands/run/wasi.rs Added is_wasix parameter to build_mapped_directories with validation for --dir=/ and --mapdir /:<HOST_PATH> flags; adjusted default guest paths based on module type
lib/cli/src/commands/run/mod.rs Added is_wasix parameter to build_wasi_runner and updated all call sites to pass appropriate value (hardcoded true for webcs, dynamically determined for modules)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marxin marxin requested a review from syrusakbary January 8, 2026 08:36
Copy link
Member

@syrusakbary syrusakbary left a comment

Choose a reason for hiding this comment

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

Need tests (and convert this into a warning)

@Arshia001
Copy link
Member Author

@syrusakbary since we turned the errors into warnings, there's not much we can actually test.

Copy link
Contributor

@zebreus zebreus left a comment

Choose a reason for hiding this comment

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

The only thing that really changed is

if is_wasix {
                        MAPPED_CURRENT_DIR_DEFAULT_PATH.to_string()
                    } else {
                        "/".to_string()
                    },

Comment on lines -572 to +596
guest: MAPPED_CURRENT_DIR_DEFAULT_PATH.to_string(),
guest: if is_wasix {
MAPPED_CURRENT_DIR_DEFAULT_PATH.to_string()
} else {
"/".to_string()
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only thing that really changed. I don't understand why this change is made and if it is an improvement.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Arshia001 If you are 100% certain this is a good idea, then go ahead and merge

Copy link
Member Author

Choose a reason for hiding this comment

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

@zebreus this is kind of the main issue! With WASI modules, nothing is mounted in the module's FS by default, so it's OK to mount wherever. With WASIX, we mount a lot of stuff in by default, so you don't want a mount on the root.

Now, with WASI, since there is no host-side CWD and you're at / by default, you just have to mount directly in / to make the files available to the module with relative paths. With WASIX, we mount into /home and cd into it.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I don't understand is that when MAPPED_CURRENT_DIR_DEFAULT_PATH is already defined to /home and that seems to work just fine.

If I understand you correctly the reason for the change is to make sure that the mountpoint is always the CWD, which it can't be for WASI. But we also can't always mount to / because that won't work for WASIX...

Copy link
Contributor

Choose a reason for hiding this comment

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

So in the past, the dir was just mounted to /home for WASI and now it isn't anymore. While this could be breaking, it's probably an improvement. However I don't like that it's one more inconsistency.

@Arshia001 Arshia001 merged commit bd91673 into main Jan 8, 2026
95 of 98 checks passed
@Arshia001 Arshia001 deleted the feat/disallow-mount-on-root branch January 8, 2026 14:50
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.

6 participants