ACL check: ENOTSUP is not "no ACL
A POSIX ACL probe read "filesystem cannot answer" as "no ACL present". Only ENODATA proves absence. Here is the fix, the test, and a Clippy trap.
Contents
Our code refuses to publish files into a directory if the directory has a POSIX ACL, because
an ACL can give a second user write access without changing the mode bits. The check asks the
kernel for the system.posix_acl_access and system.posix_acl_default extended attributes.
The first version of that check had a fail-open bug: when the filesystem could not answer the
question, the code read that as "no ACL here". This post covers the rule that fixed it, the
test, and one Clippy error that came with the fix.
The rule that was wrong
The design note said, in one line, that getxattr returning ENODATA or ENOTSUP meant
"none". Those two errors are not the same thing.
ENODATAmeans the attribute does not exist on this file. The filesystem understood the question and the answer is no.ENOTSUP(also spelledEOPNOTSUPP) means this filesystem does not support the operation.ENOSYSmeans the call is not implemented. In both cases the filesystem did not look at all. It told us it cannot tell.
Treating "cannot tell" as "no" turns an unsupported probe into a pass. On a filesystem that cannot report ACLs, the check would say the directory is clean, and publication would go ahead, even though the whole purpose of the check is to be sure.
The fix
Only ENODATA proves absence. Everything else that is not a plain answer is an error. A small
function turns the raw result into a verdict, so it can be tested without a filesystem:
pub(crate) fn classify_acl_probe(r: Result<usize, Errno>) -> Result<bool, TrustError> {
match r {
// A size query: any value (even a too-small buffer) means the attribute exists.
Ok(_) | Err(Errno::RANGE) => Ok(true),
Err(Errno::NODATA) => Ok(false),
Err(Errno::NOTSUP) | Err(Errno::NOSYS) => Err(TrustError::UnsupportedFilesystem),
Err(e) => Err(io_kind(e)),
}
}
The probe asks with an empty buffer, so it only wants the size. A success, or ERANGE (the
buffer was too small), both mean the attribute is there. Permission errors and I/O errors
become an I/O error and the publish stops. A directory on a filesystem that cannot answer is
refused as a root, with UnsupportedFilesystem.
This is the usual fail-closed shape: the only road to "safe" is a positive statement from the system. Every other road ends in a refusal.
The test
The regression test calls the classifier with each errno and checks the verdict:
#[test]
fn acl_probe_only_enodata_proves_absence() {
use rustix::io::Errno as E;
assert_eq!(classify_acl_probe(Err(E::NODATA)), Ok(false));
assert_eq!(classify_acl_probe(Ok(0)), Ok(true));
assert_eq!(classify_acl_probe(Ok(28)), Ok(true));
assert_eq!(classify_acl_probe(Err(E::RANGE)), Ok(true));
for e in [E::NOTSUP, E::OPNOTSUPP, E::NOSYS] {
// each must be an UnsupportedFilesystem error, never Ok(false)
}
}
Splitting the classifier from the syscall is what makes this possible. You cannot easily make
a real filesystem return ENOSYS on demand, but you can hand the function an ENOSYS.
The Clippy error
Our first fix had two match arms, one for NOTSUP and one for OPNOTSUPP. It compiled on
macOS. On Linux, Clippy under -D warnings failed it. On Linux the two constants have the
same value, so the second arm can never match, and Clippy reports a duplicate pattern.
The same source compiles differently on two systems because the constants differ in value between them. We stopped listing both as match arms and compared values instead. The test above still lists both spellings in its loop, so if a platform ever splits them, a case is already there.
The lesson here is practical: if you match on errno constants, run Clippy on Linux, not just on your laptop.
Why a directory ACL matters here
Mode bits say who owns a directory and who in its group or in "other" can write. An ACL is a
separate list kept in an extended attribute, and it can name any extra user. A parent
directory with mode 0755 and an ACL entry that gives write access to one more account looks
safe to anyone reading ls -l. Our publish step creates and renames files in that parent, so
a second writer could swap what we publish. That is why the check looks at the ACL attributes
of every directory it walks, and again at the staging tree before the final rename.
What a filesystem that cannot answer looks like
Some mounts do not carry ACLs at all. Network and FUSE mounts are typical. Before this fix, a directory on such a mount passed the ACL check, since the probe errored and the code took the error as "none". Now that same directory is refused. We also only accept a short list of local filesystems for the walked directories to begin with, so the ACL rule is a second line behind that list, not the only one. The point of having both is that each one stays correct if the other has a hole.
What the check still does not cover
We kept the limits written down next to the rule:
- A default ACL set after our last check is not covered. We probe after sealing the staging tree and again right before the rename, which narrows the window but does not close it.
- On macOS we do not claim the guarantee. macOS ACLs, including inherited ones, cannot be
inspected without
unsafecode or libc calls. Our code returnsUncheckedon macOS, and nothing may turnUncheckedinto an unqualified pass. The publish still runs there with the owner, mode and filesystem checks, and the record says "unsupported", not "partial".
Reading the errors in order
If you write a probe like this, it helps to list what the kernel can say and decide each answer before writing any code:
| Result | Meaning | Our verdict |
|---|---|---|
a size, or ERANGE |
the attribute exists | ACL present, refuse |
ENODATA |
the attribute does not exist | no ACL |
ENOTSUP, ENOSYS |
this filesystem cannot answer | refuse, unsupported |
| anything else | permission or I/O trouble | refuse, I/O error |
Only one row leads to "go ahead". That is the whole design, and it fits in a table.
Takeaways
- A security check needs a positive answer. "The call failed" is not an answer.
- Name every error your probe can return, and decide each one on purpose. A catch-all that
maps errors to
falseis a fail-open bug waiting for a filesystem you did not test. - Put the decision in a pure function so a test can feed it every errno.
- Run Clippy on the platform where the constants differ.