On Fri, Oct 9, 2020 at 11:27 PM Bart Schaefer wrote: > > The document linked by Matthew asserts that "mkdir -m mode" should behave "as if" chmod() is called after creating the directory. This applies only when mkdir creates a directory but not when the directory already existed prior to the call. Here's the relevant part: Each dir operand that names an existing directory shall be ignored without error. On Fri, Oct 9, 2020 at 11:40 PM Matthew Martin wrote: > > For a sufficiently well timed attacker, the target could be created and > deleted so that this loop never exits. Even if pathological, I don't > think it should be possible for mkdir to loop forever. Perhaps try N times instead of forever? The patch you've posted uses N = 1 (which is already better than the existing code) but it can be any other number. Roman.