alexcrichton opened PR #14729 from alexcrichton:fix-rename-trailing-slash to bytecodealliance:main:
renamestripped a trailing slash from the source to find its parent directory and then re-appended it to the unresolved leaf before callingrenameat. macOS and FreeBSD follow a symlink named with a trailing slash, so renamingup/, whereupis a relative symlink to../outside, moved a directory from outside the sandbox into it.Now a trailing slash on either path requires the source to be a directory, on every platform. Linux never follows a symlink named with a trailing slash in
renameatand fails withENOTDIRinstead, so there the slash is re-appended to the source whenever either path had one, and the kernel checks it atomically with the rename. Elsewhere, the source is checked without following symlinks and renamed by the plain names, so a symlink can't be followed out of the preopen. That check isn't atomic with the rename, but whatever replaces the source in between is still renamed by its plain name. Anything else fails withENOTDIR, so a trailing slash on the destination no longer lets a file or symlink be renamed either.Windows previously stripped the slashes and never re-appended them, so
rename("file\\", "new")andrename("file", "new\\")succeeded there. They now fail withERROR_DIRECTORY, consistent with Unix.The p1, p2 and p3 tests preopen a
sandboxdirectory next to anoutsidedirectory, rename a trailing-slash symlink to../outsidefrom inside the sandbox, and check thatoutsidestays in place. They also rename a real directory with trailing slashes, which must keep working. The p2 test absorbsp2_path_rename_dir_trailing_slashes, which covered those directory renames.Part of https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-m9f7-9w4p-gv38
alexcrichton requested rvolosatovs for a review on PR #14729.
alexcrichton requested wasmtime-wasi-reviewers for a review on PR #14729.
alexcrichton requested pchickey for a review on PR #14729.
alexcrichton requested wasmtime-core-reviewers for a review on PR #14729.
:thumbs_up: rvolosatovs submitted PR review.
rvolosatovs added PR #14729 wasi: don't follow a trailing-slash symlink in rename to the merge queue
:check: rvolosatovs merged PR #14729.
rvolosatovs removed PR #14729 wasi: don't follow a trailing-slash symlink in rename from the merge queue
Last updated: Oct 31 2026 at 23:03 UTC