FreeBSD Bugzilla – Attachment 246821 Details for
Bug 275570
self-referential nullfs mount over tmpfs in combination with MNT_UPDATE results in a hang
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
deadlock.c
file_275570.txt (text/plain), 2.12 KB, created by
Alex S
on 2023-12-06 13:48:25 UTC
(
hide
)
Description:
deadlock.c
Filename:
MIME Type:
Creator:
Alex S
Created:
2023-12-06 13:48:25 UTC
Size:
2.12 KB
patch
obsolete
>#include <assert.h> >#include <err.h> >#include <errno.h> >#include <stdlib.h> >#include <stdio.h> >#include <string.h> >#include <unistd.h> >#include <sys/_iovec.h> >#include <sys/file.h> >#include <sys/mount.h> > >static void xmount(const char* fstype, const char* from, const char* to, int flags) { > > char errmsg[255]; > errmsg[0] = '\0'; > > int capacity = 8; > > struct iovec* iov = malloc(sizeof(struct iovec) * capacity); > > iov[0].iov_base = "fstype"; > iov[0].iov_len = sizeof("fstype"); > iov[1].iov_base = __DECONST(char*, fstype); > iov[1].iov_len = strlen(fstype) + 1; > > iov[2].iov_base = "fspath"; > iov[2].iov_len = sizeof("fspath"); > iov[3].iov_base = __DECONST(char*, to); > iov[3].iov_len = strlen(to) + 1; > > iov[4].iov_base = "from"; > iov[4].iov_len = sizeof("from"); > iov[5].iov_base = __DECONST(char*, from); > iov[5].iov_len = strlen(from) + 1; > > iov[6].iov_base = "errmsg"; > iov[6].iov_len = sizeof("errmsg"); > iov[7].iov_base = errmsg; > iov[7].iov_len = sizeof(errmsg); > > int len = 8; > > if (flags & MNT_NOCOVER) { > > assert(len + 2 <= capacity); > > iov[len].iov_base = "nocover"; > iov[len].iov_len = sizeof("nocover"); > len++; > > iov[len].iov_base = NULL; > iov[len].iov_len = 0; > len++; > } > > assert(len == capacity); > > if (nmount(iov, len, (int)flags) == -1) { > err(EXIT_FAILURE, "nmount %s -> %s: %s", from, to, errmsg); > } > > free(iov); >} > >static void xchdir(const char* path) { > if (chdir(path) == -1) { > err(EXIT_FAILURE, "chdir(\"%s\")", path); > } >} > >static void xcreat(char* path, int mode) { > int fd = open(path, O_CREAT | O_WRONLY, mode); > if (fd == -1) { > err(EXIT_FAILURE, "can't create %s", path); > } > close(fd); >} > >#define ROOT_DIR "/mnt" > >int main(int argc, char* argv[]) { > > xchdir(ROOT_DIR); > > xmount("tmpfs", "tmpfs", ".", MNT_NOEXEC); > > xcreat(".setup-done", 0444); > xmount("nullfs", ".setup-done", ".setup-done", 0); > > xmount("tmpfs", "tmpfs", ".", MNT_RDONLY | MNT_NOEXEC | MNT_UPDATE); > > unmount(ROOT_DIR "/.setup-done", MNT_FORCE); > unmount(ROOT_DIR, MNT_FORCE); > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 275570
: 246821