diff --git a/usr.sbin/chroot/chroot.c b/usr.sbin/chroot/chroot.c --- a/usr.sbin/chroot/chroot.c +++ b/usr.sbin/chroot/chroot.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -158,8 +159,13 @@ err(1, "procctl"); } - if (chdir(argv[0]) == -1 || chroot(".") == -1) + if (chdir(argv[0]) == -1) err(1, "%s", argv[0]); + if (chroot(".") == -1) { + if (errno == EPERM && !nonprivileged && geteuid() != 0) + errx(1, "unprivileged use requires -n"); + err(1, "%s", argv[0]); + } if (gids && setgroups(gids, gidlist) == -1) err(1, "setgroups");