Skip to content

mkdir -m creates directory with wrong permissions, briefly #10022

@sylvestre

Description

@sylvestre

Component

mkdir

Description

uutils mkdir with -m MODE creates the directory first, then changes permissions in a second syscall. The directory exists briefly with umask-based permissions (typically 0755) instead of the requested mode.

GNU mkdir avoids this by temporarily setting umask to 0 around the mkdir(2) call, passing the final mode directly to the kernel. The directory is created atomically with correct permissions.

Test / Reproduction Steps

umask 022
strace -e umask,mkdir,chmod mkdir -m 0700 testdir 2>&1

GNU mkdir shows:

umask(000) = 022
mkdir("testdir", 0700) = 0
umask(022) = 000

uutils mkdir shows:

mkdir("testdir", 0777) = 0
chmod("testdir", 0700) = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions