mkdir(2) and mkdirat(2) might set errno to EOVERFLOW when UID or GID
mapping has not been configured.
Here's a small program that shows this behavior:
#define _GNU_SOURCE
#include <err.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
static int
childFunc(void *_)
{
if (mount("tmpfs", "/tmp", "tmpfs", 0, NULL))
err(EXIT_FAILURE, "mount");
if (mkdir("/tmp/test", 0755) == -1)
err(EXIT_FAILURE, "mkdir");
return 0;
}
#define STACK_SIZE (1024 * 1024)
int
main(void)
{
char *stack; /* Start of stack buffer */
char *stackTop; /* End of stack buffer */
pid_t pid;
stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,
-1, 0);
if (stack == MAP_FAILED)
err(EXIT_FAILURE, "mmap");
stackTop = stack + STACK_SIZE;
pid = clone(childFunc, stackTop, CLONE_NEWUSER |
CLONE_NEWNS | SIGCHLD, NULL);
if (munmap(stack, STACK_SIZE) == -1)
err(EXIT_FAILURE, "munmap");
if (pid == -1)
err(EXIT_FAILURE, "clone");
if (waitpid(pid, NULL, 0) == -1)
err(EXIT_FAILURE, "waitpid");
exit(EXIT_SUCCESS);
}
Link: <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=
036d523641c66bef713042894a17f4335f199e49>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Message-ID: <
F22A2B1500170B63+
20250202135733.11800-1-chenlinxuan@uniontech.com>
[alx: wfix]
Signed-off-by: Alejandro Colomar <alx@kernel.org>