Login
You're viewing the functional.cafe public feed.
  • Nov 11, 2026, 10:45 PM

    Actually I'm wrong about the particular 'race' in the OpenZFS test suite. What OpenZFS is doing is exercising a code path where the directory is created but then a thing goes wrong that causes mkdir(2) to return EIO. This is not a race exactly but a filesystem internal thing, where the filesystem may do work but not fully guarantee the mkdir(2) results.

    💬 1🔄 0⭐ 0

Replies

  • Nov 11, 2026, 11:03 PM

    However it turns out that I'm right in a sense, because uutils mkdir(1) would exit status 0 if the directory existed after a failed mkdir(2) call for any reason, including a concurrent race with another mkdir.

    💬 3🔄 0⭐ 0
  • 💬 1🔄 0⭐ 0
  • Nov 12, 2026, 12:46 AM

    @wolf480pl If I'm reading the code of the uutils fix correctly¹, uutils was basically applying 'mkdir -p' processing to all errors, even if you did plain mkdir. In 'mkdir -p', you skip reporting errors on directories that exist afterward.

    (The commit message talks about EEXIST but as far as I can see they don't check that that's the error they got from the mkdir(), they apply the processing to all errors.)

    ¹ github.com/uutils/coreutils/co

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 12:54 AM

    @cks
    oh, I read your previous post backwards - I thought they were trying to detect after mkdir that the dir exists, and if it does exist, fail to replicate GNU's behaviour, and that this was a TOCTOU.

    But yeah if it used to succeed when the dir exists - that's a much easier mistake to make.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 1:11 AM

    @wolf480pl @cks They still check path.is_dir() (`statx` on Linux) on recursive errors, instead of checking for EEXIST. So the current code is still buggy. The path might change after mkdir(2) fails and before statx(2) is called.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:04 AM

    @collinfunk
    hmm but how do you tell apart:
    1. mkdir -p a/b tries to create a, fails from EACCESS
    2. someone else creates a
    3. mkdir checks if a exists, it does, so it goes on to create a/b

    from

    1. someone else creates a
    2. mkdir tries to create a, fails from EEXISTS
    3. mkdir goes on to create a/b

    ?

    Oh, there's supposed to be a chmod, which would have to be tried (and potentially fail) after discovering the directory exists, not before...

    @cks

    💬 2🔄 0⭐ 0
  • Nov 12, 2026, 2:19 AM

    @collinfunk
    also, it seems to me what they're doing is fundamentally wrong: they're trying to implement POSIX semantics on top of a high-level filesystem API from Rust's stdlib, that AFAIK doesn't even make any promises wrt atomicity, so it might be mapping to some sequence of syscalls now and a semantically different sequence of syscalls in the future...
    @cks

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:29 AM

    @wolf480pl @cks I have similar concerns about that, but figured I was probably just being paranoid. I wonder how bad it would be for portability to just use rustix syscall wrappers.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 2:40 AM

    @collinfunk @wolf480pl In my view the only time 'mkdir -p' should fail is if at the end of its work, there is no 'a/b'. People using 'mkdir -p' care about whether or not the result exists, not how it got there. (Of course it could be renamed immediately afterward before your script does anything else, but so can anything.)

    I think POSIX can be read to be more narrow than this, but if so, deviation is likely to be extremely common in mkdirs in practice.

    💬 0🔄 0⭐ 0
  • Nov 12, 2026, 2:36 AM

    @wolf480pl @cks For 'mkdir -p', you generally don't check that the directory exists. You just create the directory, and try to enter it with chdir(2) or by opening a file descriptor (if you use a file descriptor, you'd use mkdirat(2) later to create the child relative to the parent that).

    💬 0🔄 0⭐ 0
  • 💬 1🔄 0⭐ 0
  • Nov 12, 2026, 4:43 PM

    @gnomon @mwl The specific situation seems to be a fairly obscure corner case; I'm honestly kind of impressed the ZFS test suite has a test for it. The commit¹ and the comments in the test script² have more details, and I think people are unlikely to hit this in practice (and if you do, it looks like things are already going wrong).

    ¹ github.com/openzfs/zfs/commit/
    ² github.com/openzfs/zfs/blob/ma

    💬 0🔄 0⭐ 0
  • Nov 12, 2026, 5:55 AM

    @cks flatpak does. And uses EEXIST on a read only filesystem. At least NFS a current Linux produces EROFS if the inode is not yet cached in this case, as it can't know if the directory exists without asking the server.

    💬 0🔄 0⭐ 0