0005-posix-no-symlinks.patch makes VersityGW's posix backend resolve every path below its root and versioning directory from a descriptor of that directory, opened once at start: each directory on the way with openat2 and RESOLVE_NO_SYMLINKS|RESOLVE_BENEATH (one O_NOFOLLOW open per element where openat2 is missing), the last element acted on without following it. Upstream followed a link anywhere on a key's way, so on a host that mounts more than one namespace a link planted in a bucket served, overwrote and deleted another namespace's objects (Norn M5 stage 13). A link, FIFO, socket or device is no object: at the end of a key it reads as missing (404) and is never opened, on the way it answers as a file there does (404, 409 ObjectParentIsFile), listings skip it and never enter it, and PUT, copy, complete and DELETE act on the entry itself, never on what a link points to (owner, 2026-11-27). --bucketlinks still follows a link at the bucket level only. Proven on leil-rig on 2026-11-27, against a stock 0001-0004 control: - tests/no-symlinks/proof.sh, throwaway gateways on leil-test-1: 87/87 (control 38/87). - tests/no-symlinks/rig-replay.sh, with the build pinned on the rig's four instances: 75/75 twice (control 17/75). - rig-gateway-check.sh 20/20 in both namespaces. - go test, every package but plugins/: 35/35. The rig was put back on 26e5a763. docs/no-symlinks.md has the rules, the proof and what it costs: GET +3-9%, HEAD +8-25%, listings 2x on a local disk and within noise on LeilFS. README.md and docs/multi-version-pipeline.md name the patch and how to check a rebase of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 KiB
The posix backend never follows a symbolic link (0005-posix-no-symlinks.patch)
patches/v1.11.0/0005-posix-no-symlinks.patch applies after 0004. It changes how VersityGW's posix backend reaches
the files under its root. No path is followed through a symbolic link any more, and a link, FIFO, socket or device is no
object. Requested through Norn (owner, 2026-11-26) after Norn's M5 stage 13 found links planted in a home and a bucket
served across namespaces on leil-rig. The owner settled the design on 2026-11-27.
| Touches | backend/posix/ (new: nofollow_unix.go, nofollow_linux.go, nofollow_other.go, nofollow_windows.go, nofollow_mtim.go, nofollow_mtimespec.go, nofollow_linux_test.go), backend/mkdir.go, backend/common.go, backend/meta/xattr.go |
| Base | upstream v1.11.0 (e42ae7ab) + 0001–0004 |
| Unit tests | go test ./backend/posix/ -run 'NoFollow|RootFS', on Linux only, on a file system with user xattrs (xfs, ext4; not tmpfs before Linux 6.6). Run them as root too, for the device case. |
| Proof tests | tests/no-symlinks/proof.sh (throwaway gateways on leil-test-1) and tests/no-symlinks/rig-replay.sh (leil-rig's installed gateways), below |
The problem
Stock 1.11.0 builds every path from the gateway root, its working directory. It hands the path to path-based calls:
stat, open, getxattr, os.MkdirAll and so on. So the kernel follows a symbolic link at any directory on a
key's way, for every operation. At the last element it follows one too, for every call but lstat, unlink,
rmdir, rename, mkdir and link. On a host that mounts more than one namespace, or the whole LeilFS tree (the
rig's gateway hosts, and sto-1's single node), a link in a bucket reaches another namespace:
| Operation | Link as the last element | Link as a directory on the way |
|---|---|---|
| GET, HEAD, GetObjectAttributes | the target is served | followed |
| CopyObject and UploadPartCopy source | the target is copied | followed |
| PUT, CopyObject destination, CompleteMultipartUpload | the rename replaces the link, but the stat before it follows it (a link to a directory answers 409, and If-Match compares the target's ETag) | the object is written in the directory the link reaches; across mounts, through MoveFile's copy fallback |
| DeleteObject, DeleteObjects | the link itself is removed | the target's file is removed, and empty directories of the key below the link |
| Tagging, retention, legal hold | the target's attributes are read and written | followed |
| Listings | listed as an object with the link's own size, and the target's ETag and checksums | a full walk does not enter it, but a prefix through it lists the directory it reaches, and those keys are then served |
Multipart staging, .sgwtmp |
none | followed: a link at .sgwtmp or below moves the staging into the target |
| Bucket-level settings | the bucket is lstated (a link is refused unless --bucketlinks), then read by path: a link swapped in after the lstat is followed |
none: one element |
A FIFO GET opens the FIFO and blocks until a writer comes, which can be never. That leaves a goroutine stuck in each gateway it was sent to until the gateway restarts. A socket GET answers 500.
The change
| Resolution | rootFS (nofollow_unix.go) takes every path the backend builds under the root or the versioning directory. It resolves the path from a descriptor of that directory, opened once at start. Each directory on the way is opened with openat2(…, RESOLVE_NO_SYMLINKS | RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS). The call on the last element is made relative to its directory, without following it: O_NOFOLLOW, AT_SYMLINK_NOFOLLOW, the *at calls. Extended attributes use the l-calls on /proc/self/fd/<dir>/<name>. So a link swapped in while a request runs is refused too. |
| Fallback | Where openat2 is missing (ENOSYS, Linux before 5.6), refused by seccomp (EPERM), or keeps answering EAGAIN, the directories are opened one element at a time with O_PATH|O_DIRECTORY|O_NOFOLLOW. The guarantee is the same; it takes one call per element. RESOLVE_BENEATH alone would not do: it still follows a link that stays under the root, such as one home's link into another home of the same namespace, or a link from a granted folder to an ungranted one in the same bucket. |
| Not an object | A symbolic link, FIFO, socket or device as the last element reads as missing: 404 NoSuchKey, NoSuchVersion with a version id. It is never opened: an existing file is first opened with O_PATH, which opens no FIFO or device, then checked, and only then opened through its descriptor. Extended attribute calls on it report it missing too. |
| On the way | Such an entry as a directory of the key answers as a file there does: reads 404, writes 409 ObjectParentIsFile. Nothing is written or removed through it. |
| Listings | The listings' file system holds only regular files and directories. A link is neither listed nor entered, and a prefix through one lists nothing. |
| Writes and deletes | PUT, a CopyObject destination and CompleteMultipartUpload replace the entry itself: the rename never follows it. A DELETE of its key with no version id and no preconditions removes the entry itself and answers 204, then goes on as for a missing object. A key with a trailing slash names a directory object, and leaves a link at that name alone. What a link points to is never touched. |
| What is still followed | The root and the versioning directory, which are opened as the operator named them. With --bucketlinks (off everywhere), a link at the bucket level, as that option promises; nothing below a bucket is followed even then. A bucket that is a link without that option is refused as before, now without the race. |
| Shared helpers | backend.MkdirAll and backend.MoveFile take the file system they work on (MkdirAllFS, MoveFileFS, the FS interface; backend.OS is the os package's). The posix backend then makes parent directories and moves temporary files through rootFS. The xattr metadata storer passed to posix.New is wrapped to resolve through rootFS. |
A link met on the way, or an entry that is no object, is logged at debug level (--debug), with its path.
What it does not change
- The sidecar storer (
--sidecar) and ScoutFS's own calls are as upstream has them. Neither is deployed. The sidecar directory is outside every namespace mount, and the posix half of the ScoutFS backend is covered. - Windows:
rootFSis the os package's there, as upstream has it. - darwin and FreeBSD use the element-by-element walk, since they have no
openat2. With noO_PATHeither, an existing file is opened withO_NONBLOCKand then checked, so a FIFO is opened for that moment, though never read and never waited on. - Linux needs
/proc:posix.Newrefuses to start without/proc/self/fd. Upstream'sO_TMPFILEpath already needed it. - A bucket that holds only a link answers
BucketNotEmptyto DeleteBucket while its listing is empty. Remove the link on the host (Norn's agents already skip links), or DELETE its key by name.
What it costs
Each call on a path opens the directory of its last element and closes it again, a few more system calls than before.
They are mostly lookups the kernel serves from its caches. Measured with
tests/no-symlinks/bench.sh on leil-test-1 (local xfs, one throwaway gateway,
1 KiB objects four directories deep). On LeilFS it was measured through the rig's own instances
(rig-replay.sh … 300). Medians, patched vs stock; xfs over three runs each, LeilFS over two patched runs and one stock run:
| Call | xfs: stock | xfs: patched | LeilFS: stock | LeilFS: patched |
|---|---|---|---|---|
| PUT | 3.0–3.1 ms | 3.0–3.3 ms | 23.2 ms | 22.5–22.8 ms |
| GET | 2.3–2.4 ms | 2.5–2.6 ms | 15.9 ms | 16.3–16.4 ms |
| HEAD | 2.2–2.4 ms | 2.7–2.8 ms | 12.1 ms | 13.1 ms |
| LIST (a 500-key page on xfs, 300 on LeilFS) | 51–52 ms | 103–105 ms | 598 ms | 584–616 ms |
| DELETE | 2.0 ms | 2.2 ms | 6.9 ms | 6.6–7.3 ms |
| system calls in the gateway per GET / HEAD (strace) | 102–104 / 85–88 | 124–126 / 150–153 |
On LeilFS, where the FUSE round trips dominate, the difference is within the noise except HEAD (+8%). On a local disk, listings take twice as long. They resolve each entry's directory again for its stat and its three attribute reads, so reading those relative to the listed directory is the place to win it back if it ever matters. HEAD makes 14 path-based attribute reads.
Proving the patch is in (on leil-rig)
--version reads 1.11.0 with or without the patch, so the proof is behaviour. Two stages, both under the lease:
RIG_LEASE_WHO="<you>: s3-gateway 0005 proof" ./bin/rig-lease.sh claim --why "s3-gateway 0005 proof" --minutes 120
VGW_SRC_DIR=build-src VGW_TAG=v1.11.0 bash ci/run.sh
Stage 1: throwaway gateways on leil-test-1
tests/no-symlinks/proof.sh runs as root. It starts two gateways from the given
binary: A on 127.0.0.1:7393 and B on :7394. Each is on posix, rooted at its own namespace directory under
/var/tmp/s3gw-no-symlinks, with its own internal IAM, --chuid --chgid --dir-perms 0700 as the rig's gateways run.
It replays Norn's stage 13 layout with two accounts on the reserved test band: ns-user (UID 74990) owns home on A
and data on B, and ns-other (74991) owns sibling on A. As root, owned by the UID, it plants in A's
home/escape/ and B's data/escape/:
- links to the other namespace's marker, absolute and relative (
../../../ns-b/…); - a link to the other side's directory;
- a FIFO, a socket and a device;
- in A, a link to
sibling's object, another home of the same namespace.
It removes everything at exit; KEEP=1 keeps it.
cd ../leil-rig && source bin/rig-lib.sh
on leil-test-1 'install -d -o leil -g leil /var/tmp/s3gw-0005'
rig_scp ../s3-gateway/build-src/dist/versitygw_linux_amd64_v1/versitygw leil-test-1 /var/tmp/s3gw-0005/versitygw
tar -czf /tmp/no-symlinks.tgz -C ../s3-gateway/tests owner-scope no-symlinks
rig_scp /tmp/no-symlinks.tgz leil-test-1 /var/tmp/s3gw-0005/no-symlinks.tgz
on leil-test-1 'cd /var/tmp/s3gw-0005 && chmod 0755 versitygw && tar -xzf no-symlinks.tgz && bash no-symlinks/proof.sh $PWD/versitygw'
| Checks | Shows |
|---|---|
| S1–S12 | the accounts, buckets and markers; the entries planted; the links resolve on the host |
| R1–R30 | GET and HEAD of every link, the FIFO, the socket and the device, at the end of the key and through the directory link, on both gateways: 404, each within 20 s |
| R50–R56 | GetObjectTagging, GetObjectAttributes and CopyObject from a link: 404; the bucket's own object still reads |
| L1–L6 | ListObjectsV2, ListObjects and ListObjectVersions, with and without a delimiter: only the marker; a prefix through the link: nothing |
| W1–W17 | PUT, CopyObject and CompleteMultipartUpload replace a link or FIFO with a file of the user's UID; PUT and CopyObject under a link or socket: 409, nothing written on the other side; PutObjectTagging of a link: 404 |
| D1–D9 | DELETE and DeleteObjects remove the link, socket and device themselves, and remove nothing through the directory link |
| X0–X2 | race.py: for 3 s a directory of the bucket and a link to the other namespace's directory swap names (renameat2 RENAME_EXCHANGE) as fast as they can, while GET, PUT and DELETE run under it. No GET serves the other side, and its directory holds only what it held. |
| Z1–Z2 | the markers and their attributes are unchanged; no gateway panicked |
Stage 2: the rig's installed gateways, on LeilFS
Pin the build on the rig's four instances through a git-ignored versitygw.auto.tfvars with the build's three
versitygw_* pins, and run bin/rig-versitygw.sh --rpm <rpm>. Then bin/rig-gateway-check.sh, and
tests/no-symlinks/rig-replay.sh as root on leil-mst-1, with s3req.py and
bench.py beside it. Its arguments are the peer's IP, a UID from the test band and the mount cache time:
on leil-mst-1 'bash /var/tmp/s3gw-nf-tools/rig-replay.sh 192.168.100.43 74995 5 300'
It makes a throwaway account in 0x0 and 0x1, a home nf-home-<stamp> and a bucket nf-data-<stamp>. Each root
key is read from /etc/versitygw.d/<ns>.conf only inside the admin calls, and never printed. It plants Norn's links
across the two mounts (../../../0x1/… and back), a directory link, a FIFO and a socket, waits out the mount cache,
and drives GET, HEAD, CopyObject, listings, PUT and DELETE at them through all four instances. It then removes
everything through the mounts, with the account. The fourth argument also times that many calls on LeilFS. Then remove
versitygw.auto.tfvars, run bin/rig-versitygw.sh, bin/rig-gateway-check.sh and bin/rig-status.sh, and release
the lease.
Result on leil-rig, 2026-11-27: PASSED
Run under the lease. leil-test-1 and the gateway hosts run AlmaLinux 9.8 with kernel 5.14.0-687.53.1; the rig has
LeilFS 274875f2, OpenBao 2.6.2 and Vault IAM:
| Build | VGW_TAG=v1.11.0 bash ci/run.sh (fresh clone of v1.11.0, 0001–0005 by git am --3way, GoReleaser, go1.27.3); --version 1.11.0, Build a4152e88 |
versitygw (linux amd64) sha256 |
7213faedd150294b2890d986392b20ff5b6e5d24dfa317cc956913451e9ab7a9 |
versitygw_1.11.0_linux_amd64.rpm sha256 |
1148ed7a8f079b2da60530a9b139a7cacd82cffc5349a4c293cf16510d63990a (built locally; not published, not pinned) |
| Unit tests on leil-test-1 (go1.27.3 linux/amd64) | the new tests: ok, as leil and as root, with openat2 and with the walk, with relative and absolute paths, and with -race. The swap test made about 120 000 swaps a run, and every GET that answered served the bucket's own data. Every package but plugins/: 35 of 35 ok. |
proof.sh (stage 1) |
87 passed, 0 failed. Race: 53 344 swaps, 258 rounds; GET 200 ×42 (own data), 404 ×216; PUT 200 ×175, 409 ×82, 500 ×1; the other side untouched. |
rig-replay.sh (stage 2), patched build pinned |
75 passed, 0 failed, twice: 44 reads through the four instances answered 404, the listings showed the marker alone, and the writes and deletes acted on the entry itself. rig-gateway-check.sh passed 0x0 20/20 and 0x1 20/20. |
Control: stock 0001–0004. Same scripts. On leil-test-1 the control was built by ci/run.sh from the same
repository state, with PATCH_DIR holding 0001–0004 (binary c522187e…). On the rig it was the pinned release
26e5a763….
proof.sh: 38 passed, 49 failed.- Every link GET and HEAD answered 200 with the other namespace's marker, and so did the other home's.
- The FIFO GET and the copy from it did not answer in 20 s. The socket GET answered 500, and the device GET 200.
- The listings showed every planted entry, and the prefix through the link listed the other side.
- PUT and CopyObject under the link answered 200, written in the other namespace.
- DELETE under it removed the other namespace's marker.
- Tagging went through to the target.
- In the race, 165 GETs served the other side.
rig-replay.sh: 17 passed, 58 failed, Norn's finding on all four instances and more:- all 44 reads were served;
- the FIFO GETs did not answer;
- the listings entered the link;
- PUT under the link wrote into the other namespace;
- DELETE under the link removed 0x0's marker.
The rig was put back after the trial. Every node runs 26e5a763ab3f again; rig-gateway-check.sh passed 20/20 in both
namespaces, and rig-status.sh reads as before. Under a swap race as fast as race.py's, a PUT can answer 500 rather
than 409, as one did in one of two runs; nothing is written through the link.
Run this test again before pinning any build that carries 0005, in leil-rig or leil-cluster.