diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-08-05 15:16:40 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-08-05 15:16:40 +0000 |
commit | 229dcc9543cb5641487a3c6df0b9ca072200815a (patch) | |
tree | 56dfa5785ec8f58b0b69f1678d283f8f1d05df25 | |
parent | 45b3aa1aacff56e54a465a23e43814c6665c3426 (diff) |
Call realpath(3) in combination with chroot(2) and chdir(2).
Use umount(8) to check that the mountpoint leaks no vnode.
from Moritz Buhl
-rw-r--r-- | regress/sys/kern/realpath-unmount/Makefile | 92 | ||||
-rw-r--r-- | regress/sys/kern/realpath-unmount/realpath-chdir.c | 44 | ||||
-rw-r--r-- | regress/sys/kern/realpath-unmount/realpath-chroot.c | 44 |
3 files changed, 180 insertions, 0 deletions
diff --git a/regress/sys/kern/realpath-unmount/Makefile b/regress/sys/kern/realpath-unmount/Makefile new file mode 100644 index 00000000000..351650022d0 --- /dev/null +++ b/regress/sys/kern/realpath-unmount/Makefile @@ -0,0 +1,92 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2019/08/05 15:16:39 bluhm Exp $ + +# Call realpath(3) in combination with chroot(2), chdir(2). +# Use umount(8) to check that the mountpoint leaks no vnode. +# There were vnode reference counting bugs in the kernel. + +PROGS= realpath-chroot realpath-chdir +CLEANFILES= diskimage + +.PHONY: mount unconfig clean + +diskimage: unconfig + @echo '\n======== $@ ========' + ${SUDO} dd if=/dev/zero of=diskimage bs=512 count=4k + ${SUDO} vnconfig vnd0 diskimage + ${SUDO} newfs vnd0c + +mount: diskimage + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath + ${SUDO} mount /dev/vnd0c /mnt/regress-realpath + +unconfig: + @echo '\n======== $@ ========' + -${SUDO} umount -f /dev/vnd0c 2>/dev/null || true + -${SUDO} rmdir /mnt/regress-realpath 2>/dev/null || true + -${SUDO} vnconfig -u vnd0 2>/dev/null || true + -${SUDO} rm -f stamp-setup + +REGRESS_SETUP = ${PROGS} mount +REGRESS_CLEANUP = unconfig +REGRESS_TARGETS = + +REGRESS_TARGETS += run-chroot +run-chroot: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath + ${SUDO} ./realpath-chroot /mnt/regress-realpath / + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chroot-dir +run-chroot-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo + ${SUDO} ./realpath-chroot /mnt/regress-realpath/foo / + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chroot-dir +run-chroot-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo + ${SUDO} ./realpath-chroot /mnt/regress-realpath /foo + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chroot-dir-dir +run-chroot-dir-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo/bar + ${SUDO} ./realpath-chroot /mnt/regress-realpath/foo /bar + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chdir +run-chdir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath + ${SUDO} ./realpath-chdir /mnt/regress-realpath . + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chdir-dir +run-chdir-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo + ${SUDO} ./realpath-chdir /mnt/regress-realpath/foo . + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chdir-dir +run-chdir-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo + ${SUDO} ./realpath-chdir /mnt/regress-realpath foo + ${SUDO} umount /mnt/regress-realpath + +REGRESS_TARGETS += run-chdir-dir-dir +run-chdir-dir-dir: + @echo '\n======== $@ ========' + ${SUDO} mkdir -p /mnt/regress-realpath/foo/bar + ${SUDO} ./realpath-chdir /mnt/regress-realpath/foo bar + ${SUDO} umount /mnt/regress-realpath + +REGRESS_ROOT_TARGETS = ${REGRESS_TARGETS} + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/realpath-unmount/realpath-chdir.c b/regress/sys/kern/realpath-unmount/realpath-chdir.c new file mode 100644 index 00000000000..03703ec297a --- /dev/null +++ b/regress/sys/kern/realpath-unmount/realpath-chdir.c @@ -0,0 +1,44 @@ +/* $OpenBSD: realpath-chdir.c,v 1.1.1.1 2019/08/05 15:16:39 bluhm Exp $ */ +/* + * Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org> + * Copyright (c) 2019 Moritz Buhl <mbuhl@moritzbuhl.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <err.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + char *cwd, *dir, *path = NULL; + char res[PATH_MAX]; + + if (argc != 3) + errx(2, "usage: realpath-chdir cwd dir"); + + cwd = argv[1]; + dir = argv[2]; + + if (chdir(cwd) == -1) + err(1, "chdir %s", cwd); + + if (realpath(dir, res) == NULL) + err(1, "realpath %s", dir); + + return 0; +} diff --git a/regress/sys/kern/realpath-unmount/realpath-chroot.c b/regress/sys/kern/realpath-unmount/realpath-chroot.c new file mode 100644 index 00000000000..72012aaf317 --- /dev/null +++ b/regress/sys/kern/realpath-unmount/realpath-chroot.c @@ -0,0 +1,44 @@ +/* $OpenBSD: realpath-chroot.c,v 1.1.1.1 2019/08/05 15:16:39 bluhm Exp $ */ +/* + * Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org> + * Copyright (c) 2019 Moritz Buhl <mbuhl@moritzbuhl.de> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <err.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + char *root, *dir, *path = NULL; + char res[PATH_MAX]; + + if (argc != 3) + errx(2, "usage: realpath-chroot root dir"); + + root = argv[1]; + dir = argv[2]; + + if (chroot(root) == -1) + err(1, "chroot %s", root); + + if (realpath(dir, res) == NULL) + err(1, "realpath %s", dir); + + return 0; +} |