Ondřej Vašík f7c868
From 0cf7b1d928acaaddd4eaa28c6a22f7bd6457b379 Mon Sep 17 00:00:00 2001
Ondřej Vašík f7c868
From: Bernhard Voelker <mail@bernhard-voelker.de>
Ondřej Vašík f7c868
Date: Fri, 01 Aug 2014 00:07:33 +0000
Ondřej Vašík f7c868
Subject: chroot: perform chdir("/") again unless new --skip-chdir is specified
Ondřej Vašík f7c868
Ondřej Vašík f7c868
Since commit v8.22-94-g99960ee, chroot(1) skips the chroot(2) syscall
Ondřej Vašík f7c868
for "/" arguments (and synonyms).  The problem is that it also skips
Ondřej Vašík f7c868
the following chdir("/") call in that case.  The latter breaks existing
Ondřej Vašík f7c868
scripts which expect "/" to be the working directory inside the chroot.
Ondřej Vašík f7c868
While the first part of the change - i.e., skipping chroot("/") - is
Ondřej Vašík f7c868
okay for consistency with systems where it might succeed for a non-root
Ondřej Vašík f7c868
user, the second part might be malicious, e.g.
Ondřej Vašík f7c868
Ondřej Vašík f7c868
  cd /home/user && chroot '/' bin/foo
Ondřej Vašík f7c868
Ondřej Vašík f7c868
In the "best" case, chroot(1) could not execute 'bin/foo' with ENOENT,
Ondřej Vašík f7c868
but in the worst case, chroot(1) would execute '/home/user/bin/foo' in
Ondřej Vašík f7c868
the case that exists - instead of '/bin/foo'.
Ondřej Vašík f7c868
Ondřej Vašík f7c868
Revert that second part of the patch, i.e., perform the chdir("/)
Ondřej Vašík f7c868
in the common case again - unless the new --skip-chdir option is
Ondřej Vašík f7c868
specified.  Restrict this new option to the case of "/" arguments.
Ondřej Vašík f7c868
Ondřej Vašík f7c868
* src/chroot.c (SKIP_CHDIR): Add enum.
Ondřej Vašík f7c868
(long_opts): Add entry for the new --skip-chdir option.
Ondřej Vašík f7c868
(usage): Add --skip-chdir option, and while at it, move the other
Ondřej Vašík f7c868
to options into alphabetical order.
Ondřej Vašík f7c868
(main): Accept the above new option, allowing it only in the case
Ondřej Vašík f7c868
when NEWROOT is the old "/".
Ondřej Vašík f7c868
Move down the chdir() call after the if-clause to ensure it is
Ondřej Vašík f7c868
run in any case - unless --skip-chdir is specified.
Ondřej Vašík f7c868
Add a 'newroot' variable for the new root directory as it is used
Ondřej Vašík f7c868
in a couple of places now.
Ondřej Vašík f7c868
* tests/misc/chroot-fail.sh: Invert the last tests which check the
Ondřej Vašík f7c868
working directory of the execvp()ed program when a "/"-like
Ondřej Vašík f7c868
argument was passed: now expect it to be "/" - unless --skip-chdir
Ondřej Vašík f7c868
is given.
Ondřej Vašík f7c868
* doc/coreutils.texi (chroot invocation): Document the new option.
Ondřej Vašík f7c868
Document that chroot(1) usually calls chdir("/") unless the new
Ondřej Vašík f7c868
--skip-chdir option is specified.  Sort options.
Ondřej Vašík f7c868
* init.cfg (nonroot_has_perm_): Add chroot's new --skip-chdir option.
Ondřej Vašík f7c868
* tests/cp/preserve-gid.sh (t1): Likewise.
Ondřej Vašík f7c868
* tests/cp/special-bits.sh: Likewise.
Ondřej Vašík f7c868
* tests/id/setgid.sh: Likewise.
Ondřej Vašík f7c868
* tests/misc/truncate-owned-by-other.sh: Likewise.
Ondřej Vašík f7c868
* tests/mv/sticky-to-xpart.sh: Likewise.
Ondřej Vašík f7c868
* tests/rm/fail-2eperm.sh: Likewise.
Ondřej Vašík f7c868
* tests/rm/no-give-up.sh: Likewise.
Ondřej Vašík f7c868
* tests/touch/now-owned-by-other.sh: Likewise.
Ondřej Vašík f7c868
Ondřej Vašík f7c868
Reported by Andreas Schwab in http://bugs.gnu.org/18062
Ondřej Vašík f7c868
---
Ondřej Vašík f7c868
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
Ondřej Vašík f7c868
index 96f0781..7c86719 100644
Ondřej Vašík f7c868
--- a/doc/coreutils.texi
Ondřej Vašík f7c868
+++ b/doc/coreutils.texi
Ondřej Vašík f7c868
@@ -16113,7 +16113,10 @@ On many systems, only the super-user can do this.@footnote{However,
Ondřej Vašík f7c868
 some systems (e.g., FreeBSD) can be configured to allow certain regular
Ondřej Vašík f7c868
 users to use the @code{chroot} system call, and hence to run this program.
Ondřej Vašík f7c868
 Also, on Cygwin, anyone can run the @command{chroot} command, because the
Ondřej Vašík f7c868
-underlying function is non-privileged due to lack of support in MS-Windows.}
Ondřej Vašík f7c868
+underlying function is non-privileged due to lack of support in MS-Windows.
Ondřej Vašík f7c868
+Furthermore, the @command{chroot} command avoids the @code{chroot} system call
Ondřej Vašík f7c868
+when @var{newroot} is identical to the old @file{/} directory for consistency
Ondřej Vašík f7c868
+with systems where this is allowed for non-privileged users.}.
Ondřej Vašík f7c868
 Synopses:
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 @example
Ondřej Vašík f7c868
@@ -16123,10 +16126,11 @@ chroot @var{option}
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 Ordinarily, file names are looked up starting at the root of the
Ondřej Vašík f7c868
 directory structure, i.e., @file{/}.  @command{chroot} changes the root to
Ondřej Vašík f7c868
-the directory @var{newroot} (which must exist) and then runs
Ondřej Vašík f7c868
-@var{command} with optional @var{args}.  If @var{command} is not
Ondřej Vašík f7c868
-specified, the default is the value of the @env{SHELL} environment
Ondřej Vašík f7c868
-variable or @command{/bin/sh} if not set, invoked with the @option{-i} option.
Ondřej Vašík f7c868
+the directory @var{newroot} (which must exist), then changes the working
Ondřej Vašík f7c868
+directory to @file{/}, and finally runs @var{command} with optional @var{args}.
Ondřej Vašík f7c868
+If @var{command} is not specified, the default is the value of the @env{SHELL}
Ondřej Vašík f7c868
+environment variable or @command{/bin/sh} if not set, invoked with the
Ondřej Vašík f7c868
+@option{-i} option.
Ondřej Vašík f7c868
 @var{command} must not be a special built-in utility
Ondřej Vašík f7c868
 (@pxref{Special built-in utilities}).
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
@@ -16135,6 +16139,14 @@ Options must precede operands.
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 @table @samp
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
+@item --groups=@var{groups}
Ondřej Vašík f7c868
+@opindex --groups
Ondřej Vašík f7c868
+Use this option to override the supplementary @var{groups} to be
Ondřej Vašík f7c868
+used by the new process.
Ondřej Vašík f7c868
+The items in the list (names or numeric IDs) must be separated by commas.
Ondřej Vašík f7c868
+Use @samp{--groups=''} to disable the supplementary group look-up
Ondřej Vašík f7c868
+implicit in the @option{--userspec} option.
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
 @item --userspec=@var{user}[:@var{group}]
Ondřej Vašík f7c868
 @opindex --userspec
Ondřej Vašík f7c868
 By default, @var{command} is run with the same credentials
Ondřej Vašík f7c868
@@ -16145,13 +16157,13 @@ If a @var{user} is specified then the supplementary groups
Ondřej Vašík f7c868
 are set according to the system defined list for that user,
Ondřej Vašík f7c868
 unless overridden with the @option{--groups} option.
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-@item --groups=@var{groups}
Ondřej Vašík f7c868
-@opindex --groups
Ondřej Vašík f7c868
-Use this option to override the supplementary @var{groups} to be
Ondřej Vašík f7c868
-used by the new process.
Ondřej Vašík f7c868
-The items in the list (names or numeric IDs) must be separated by commas.
Ondřej Vašík f7c868
-Use @samp{--groups=''} to disable the supplementary group look-up
Ondřej Vašík f7c868
-implicit in the @option{--userspec} option.
Ondřej Vašík f7c868
+@item --skip-chdir
Ondřej Vašík f7c868
+@opindex --skip-chdir
Ondřej Vašík f7c868
+Use this option to not change the working directory to @file{/} after changing
Ondřej Vašík f7c868
+the root directory to @var{newroot}, i.e., inside the chroot.
Ondřej Vašík f7c868
+This option is only permitted when @var{newroot} is the old @file{/} directory,
Ondřej Vašík f7c868
+and therefore is mostly useful together with the @option{--groups} and
Ondřej Vašík f7c868
+@option{--userspec} options to retain the previous working directory.
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 @end table
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
diff --git a/init.cfg b/init.cfg
Ondřej Vašík f7c868
index 725ee12..032646b 100644
Ondřej Vašík f7c868
--- a/init.cfg
Ondřej Vašík f7c868
+++ b/init.cfg
Ondřej Vašík f7c868
@@ -400,7 +400,8 @@ nonroot_has_perm_()
Ondřej Vašík f7c868
   require_built_ chroot
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
   local rm_version=$(
Ondřej Vašík f7c868
-    chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" rm --version |
Ondřej Vašík f7c868
+    chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+      rm --version |
Ondřej Vašík f7c868
     sed -n '1s/.* //p'
Ondřej Vašík f7c868
   )
Ondřej Vašík f7c868
   case ":$rm_version:" in
Ondřej Vašík f7c868
diff --git a/src/chroot.c b/src/chroot.c
Ondřej Vašík f7c868
index 6c2d63f..418ea67 100644
Ondřej Vašík f7c868
--- a/src/chroot.c
Ondřej Vašík f7c868
+++ b/src/chroot.c
Ondřej Vašík f7c868
@@ -49,13 +49,15 @@ static inline bool gid_unset (gid_t gid) { return gid == (gid_t) -1; }
Ondřej Vašík f7c868
 enum
Ondřej Vašík f7c868
 {
Ondřej Vašík f7c868
   GROUPS = UCHAR_MAX + 1,
Ondřej Vašík f7c868
-  USERSPEC
Ondřej Vašík f7c868
+  USERSPEC,
Ondřej Vašík f7c868
+  SKIP_CHDIR
Ondřej Vašík f7c868
 };
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 static struct option const long_opts[] =
Ondřej Vašík f7c868
 {
Ondřej Vašík f7c868
   {"groups", required_argument, NULL, GROUPS},
Ondřej Vašík f7c868
   {"userspec", required_argument, NULL, USERSPEC},
Ondřej Vašík f7c868
+  {"skip-chdir", no_argument, NULL, SKIP_CHDIR},
Ondřej Vašík f7c868
   {GETOPT_HELP_OPTION_DECL},
Ondřej Vašík f7c868
   {GETOPT_VERSION_OPTION_DECL},
Ondřej Vašík f7c868
   {NULL, 0, NULL, 0}
Ondřej Vašík f7c868
@@ -194,9 +196,14 @@ Run COMMAND with root directory set to NEWROOT.\n\
Ondřej Vašík f7c868
 "), stdout);
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
       fputs (_("\
Ondřej Vašík f7c868
-  --userspec=USER:GROUP  specify user and group (ID or name) to use\n\
Ondřej Vašík f7c868
   --groups=G_LIST        specify supplementary groups as g1,g2,..,gN\n\
Ondřej Vašík f7c868
 "), stdout);
Ondřej Vašík f7c868
+      fputs (_("\
Ondřej Vašík f7c868
+  --userspec=USER:GROUP  specify user and group (ID or name) to use\n\
Ondřej Vašík f7c868
+"), stdout);
Ondřej Vašík f7c868
+      printf (_("\
Ondřej Vašík f7c868
+  --skip-chdir           do not change working directory to %s\n\
Ondřej Vašík f7c868
+"), quote ("/"));
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
       fputs (HELP_OPTION_DESCRIPTION, stdout);
Ondřej Vašík f7c868
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
Ondřej Vašík f7c868
@@ -218,6 +225,7 @@ main (int argc, char **argv)
Ondřej Vašík f7c868
   char *userspec = NULL;
Ondřej Vašík f7c868
   char const *username = NULL;
Ondřej Vašík f7c868
   char const *groups = NULL;
Ondřej Vašík f7c868
+  bool skip_chdir = false;
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
   /* Parsed user and group IDs.  */
Ondřej Vašík f7c868
   uid_t uid = -1;
Ondřej Vašík f7c868
@@ -254,6 +262,10 @@ main (int argc, char **argv)
Ondřej Vašík f7c868
           groups = optarg;
Ondřej Vašík f7c868
           break;
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
+        case SKIP_CHDIR:
Ondřej Vašík f7c868
+          skip_chdir = true;
Ondřej Vašík f7c868
+          break;
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
         case_GETOPT_HELP_CHAR;
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
Ondřej Vašík f7c868
@@ -269,9 +281,19 @@ main (int argc, char **argv)
Ondřej Vašík f7c868
       usage (EXIT_CANCELED);
Ondřej Vašík f7c868
     }
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
+  char const *newroot = argv[optind];
Ondřej Vašík f7c868
+  bool is_oldroot = is_root (newroot);
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
+  if (! is_oldroot && skip_chdir)
Ondřej Vašík f7c868
+    {
Ondřej Vašík f7c868
+      error (0, 0, _("option --skip-chdir only permitted if NEWROOT is old %s"),
Ondřej Vašík f7c868
+             quote ("/"));
Ondřej Vašík f7c868
+      usage (EXIT_CANCELED);
Ondřej Vašík f7c868
+    }
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
   /* Only do chroot specific actions if actually changing root.
Ondřej Vašík f7c868
      The main difference here is that we don't change working dir.  */
Ondřej Vašík f7c868
-  if (! is_root (argv[optind]))
Ondřej Vašík f7c868
+  if (! is_oldroot)
Ondřej Vašík f7c868
     {
Ondřej Vašík f7c868
       /* We have to look up users and groups twice.
Ondřej Vašík f7c868
         - First, outside the chroot to load potentially necessary passwd/group
Ondřej Vašík f7c868
@@ -307,14 +329,14 @@ main (int argc, char **argv)
Ondřej Vašík f7c868
         }
Ondřej Vašík f7c868
 #endif
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-      if (chroot (argv[optind]) != 0)
Ondřej Vašík f7c868
+      if (chroot (newroot) != 0)
Ondřej Vašík f7c868
         error (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
Ondřej Vašík f7c868
-               argv[optind]);
Ondřej Vašík f7c868
-
Ondřej Vašík f7c868
-      if (chdir ("/"))
Ondřej Vašík f7c868
-        error (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
Ondřej Vašík f7c868
+               newroot);
Ondřej Vašík f7c868
     }
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
+  if (! skip_chdir && chdir ("/"))
Ondřej Vašík f7c868
+    error (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
   if (argc == optind + 1)
Ondřej Vašík f7c868
     {
Ondřej Vašík f7c868
       /* No command.  Run an interactive shell.  */
Ondřej Vašík f7c868
diff --git a/tests/cp/preserve-gid.sh b/tests/cp/preserve-gid.sh
Ondřej Vašík f7c868
index f141ac1..5499c2e 100755
Ondřej Vašík f7c868
--- a/tests/cp/preserve-gid.sh
Ondřej Vašík f7c868
+++ b/tests/cp/preserve-gid.sh
Ondřej Vašík f7c868
@@ -117,7 +117,8 @@ t1() {
Ondřej Vašík f7c868
   u=$1; shift
Ondřej Vašík f7c868
   g=$1; shift
Ondřej Vašík f7c868
   t0 "$f" "$u" "$g" \
Ondřej Vašík f7c868
-      chroot --user=+$nameless_uid:+$nameless_gid1 \
Ondřej Vašík f7c868
+      chroot --skip-chdir \
Ondřej Vašík f7c868
+             --user=+$nameless_uid:+$nameless_gid1 \
Ondřej Vašík f7c868
              --groups="+$nameless_gid1,+$nameless_gid2" \
Ondřej Vašík f7c868
         / env PATH="$tmp_path" "$@"
Ondřej Vašík f7c868
 }
Ondřej Vašík f7c868
diff --git a/tests/cp/special-bits.sh b/tests/cp/special-bits.sh
Ondřej Vašík f7c868
index a55eea2..1402819 100755
Ondřej Vašík f7c868
--- a/tests/cp/special-bits.sh
Ondřej Vašík f7c868
+++ b/tests/cp/special-bits.sh
Ondřej Vašík f7c868
@@ -42,7 +42,8 @@ set _ $(ls -l b); shift; p1=$1
Ondřej Vašík f7c868
 set _ $(ls -l b2); shift; p2=$1
Ondřej Vašík f7c868
 test $p1 = $p2 || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" cp -p c c2 || fail=1
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" cp -p c c2 \
Ondřej Vašík f7c868
+  || fail=1
Ondřej Vašík f7c868
 set _ $(ls -l c); shift; p1=$1
Ondřej Vašík f7c868
 set _ $(ls -l c2); shift; p2=$1
Ondřej Vašík f7c868
 test $p1 = $p2 && fail=1
Ondřej Vašík f7c868
diff --git a/tests/id/setgid.sh b/tests/id/setgid.sh
Ondřej Vašík f7c868
index 6d9d74f..019418a 100755
Ondřej Vašík f7c868
--- a/tests/id/setgid.sh
Ondřej Vašík f7c868
+++ b/tests/id/setgid.sh
Ondřej Vašík f7c868
@@ -27,14 +27,14 @@ echo $gp1 > exp || framework_failure_
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # With coreutils-8.16 and earlier, id -G would print both:
Ondřej Vašík f7c868
 #  $gp1 $NON_ROOT_GID
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
Ondřej Vašík f7c868
-  id -G > out || fail=1
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / \
Ondřej Vašík f7c868
+  env PATH="$PATH" id -G > out || fail=1
Ondřej Vašík f7c868
 compare exp out || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # With coreutils-8.22 and earlier, id would erroneously print
Ondřej Vašík f7c868
 #  groups=$NON_ROOT_GID
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
Ondřej Vašík f7c868
-  id > out || fail=1
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / \
Ondřej Vašík f7c868
+  env PATH="$PATH" id > out || fail=1
Ondřej Vašík f7c868
 grep -F "groups=$gp1" out || { cat out; fail=1; }
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 Exit $fail
Ondřej Vašík f7c868
diff --git a/tests/misc/chroot-fail.sh b/tests/misc/chroot-fail.sh
Ondřej Vašík f7c868
index a84826f..82ae23c 100755
Ondřej Vašík f7c868
--- a/tests/misc/chroot-fail.sh
Ondřej Vašík f7c868
+++ b/tests/misc/chroot-fail.sh
Ondřej Vašík f7c868
@@ -30,7 +30,7 @@ chroot --- / true # unknown option
Ondřej Vašík f7c868
 test $? = 125 || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # Note chroot("/") succeeds for non-root users on some systems, but not all,
Ondřej Vašík f7c868
-# however we avoid the chroot() with "/" to have common behvavior.
Ondřej Vašík f7c868
+# however we avoid the chroot() with "/" to have common behavior.
Ondřej Vašík f7c868
 chroot / sh -c 'exit 2' # exit status propagation
Ondřej Vašík f7c868
 test $? = 2 || fail=1
Ondřej Vašík f7c868
 chroot / . # invalid command
Ondřej Vašík f7c868
@@ -38,10 +38,25 @@ test $? = 126 || fail=1
Ondřej Vašík f7c868
 chroot / no_such # no such command
Ondřej Vašík f7c868
 test $? = 127 || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-# Ensure we don't chdir("/") when not changing root
Ondřej Vašík f7c868
-# to allow only changing user ids for a command.
Ondřej Vašík f7c868
-for dir in '/' '/.' '/../'; do
Ondřej Vašík f7c868
+# Ensure that --skip-chdir fails with a non-"/" argument.
Ondřej Vašík f7c868
+cat <<\EOF > exp || framework_failure_
Ondřej Vašík f7c868
+chroot: option --skip-chdir only permitted if NEWROOT is old '/'
Ondřej Vašík f7c868
+Try 'chroot --help' for more information.
Ondřej Vašík f7c868
+EOF
Ondřej Vašík f7c868
+chroot --skip-chdir . env pwd >out 2>err && fail=1
Ondřej Vašík f7c868
+compare /dev/null out || fail=1
Ondřej Vašík f7c868
+compare exp err || fail=1
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
+# Ensure we don't chroot("/") when NEWROOT is old "/".
Ondřej Vašík f7c868
+ln -s / isroot || framework_failure_
Ondřej Vašík f7c868
+for dir in '/' '/.' '/../' isroot; do
Ondřej Vašík f7c868
+  # Verify that chroot(1) succeeds and performs chdir("/")
Ondřej Vašík f7c868
+  # (chroot(1) of coreutils-8.23 failed to run the latter).
Ondřej Vašík f7c868
   curdir=$(chroot "$dir" env pwd) || fail=1
Ondřej Vašík f7c868
+  test "$curdir" = '/' || fail=1
Ondřej Vašík f7c868
+
Ondřej Vašík f7c868
+  # Test the "--skip-chdir" option.
Ondřej Vašík f7c868
+  curdir=$(chroot --skip-chdir "$dir" env pwd) || fail=1
Ondřej Vašík f7c868
   test "$curdir" = '/' && fail=1
Ondřej Vašík f7c868
 done
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
diff --git a/tests/misc/truncate-owned-by-other.sh b/tests/misc/truncate-owned-by-other.sh
Ondřej Vašík f7c868
index e70badb..f65439e 100755
Ondřej Vašík f7c868
--- a/tests/misc/truncate-owned-by-other.sh
Ondřej Vašík f7c868
+++ b/tests/misc/truncate-owned-by-other.sh
Ondřej Vašík f7c868
@@ -29,7 +29,7 @@ chmod g+w root-owned
Ondřej Vašík f7c868
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
Ondřej Vašík f7c868
 chmod g+x .
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
   truncate -s0 root-owned || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 Exit $fail
Ondřej Vašík f7c868
diff --git a/tests/mv/sticky-to-xpart.sh b/tests/mv/sticky-to-xpart.sh
Ondřej Vašík f7c868
index e0c99e9..6c1f6e8 100755
Ondřej Vašík f7c868
--- a/tests/mv/sticky-to-xpart.sh
Ondřej Vašík f7c868
+++ b/tests/mv/sticky-to-xpart.sh
Ondřej Vašík f7c868
@@ -42,7 +42,8 @@ chmod go+x . || framework_failure_
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # Ensure that $NON_ROOT_USERNAME can access the required version of mv.
Ondřej Vašík f7c868
 version=$(
Ondřej Vašík f7c868
-  chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" mv --version |
Ondřej Vašík f7c868
+  chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+    mv --version |
Ondřej Vašík f7c868
   sed -n '1s/.* //p'
Ondřej Vašík f7c868
 )
Ondřej Vašík f7c868
 case $version in
Ondřej Vašík f7c868
@@ -50,7 +51,7 @@ case $version in
Ondřej Vašík f7c868
   *) skip_ "cannot access just-built mv as user $NON_ROOT_USERNAME";;
Ondřej Vašík f7c868
 esac
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
   mv t/root-owned "$other_partition_tmpdir" 2> out-t && fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # On some systems, we get 'Not owner'.  Convert it.
Ondřej Vašík f7c868
diff --git a/tests/rm/fail-2eperm.sh b/tests/rm/fail-2eperm.sh
Ondřej Vašík f7c868
index 6e8ce9b..c324037 100755
Ondřej Vašík f7c868
--- a/tests/rm/fail-2eperm.sh
Ondřej Vašík f7c868
+++ b/tests/rm/fail-2eperm.sh
Ondřej Vašík f7c868
@@ -32,14 +32,16 @@ touch a/b || framework_failure_
Ondřej Vašík f7c868
 # Try to ensure that $NON_ROOT_USERNAME can access
Ondřej Vašík f7c868
 # the required version of rm.
Ondřej Vašík f7c868
 rm_version=$(
Ondřej Vašík f7c868
-  chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" rm --version |
Ondřej Vašík f7c868
+  chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+    rm --version |
Ondřej Vašík f7c868
   sed -n '1s/.* //p'
Ondřej Vašík f7c868
 )
Ondřej Vašík f7c868
 case $rm_version in
Ondřej Vašík f7c868
   $PACKAGE_VERSION) ;;
Ondřej Vašík f7c868
   *) skip_ "cannot access just-built rm as user $NON_ROOT_USERNAME";;
Ondřej Vašík f7c868
 esac
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" rm -rf a 2> out-t && fail=1
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / \
Ondřej Vašík f7c868
+  env PATH="$PATH" rm -rf a 2> out-t && fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # On some systems, we get 'Not owner'.  Convert it.
Ondřej Vašík f7c868
 # On other systems (HPUX), we get 'Permission denied'.  Convert it, too.
Ondřej Vašík f7c868
diff --git a/tests/rm/no-give-up.sh b/tests/rm/no-give-up.sh
Ondřej Vašík f7c868
index 41070c9..958f9e8 100755
Ondřej Vašík f7c868
--- a/tests/rm/no-give-up.sh
Ondřej Vašík f7c868
+++ b/tests/rm/no-give-up.sh
Ondřej Vašík f7c868
@@ -30,7 +30,7 @@ chmod go=x . || framework_failure_
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # This must fail, since '.' is not writable by $NON_ROOT_USERNAME.
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
   rm -rf d 2>/dev/null && fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 # d must remain.
Ondřej Vašík f7c868
diff --git a/tests/touch/now-owned-by-other.sh b/tests/touch/now-owned-by-other.sh
Ondřej Vašík f7c868
index d01097e..018ef11 100755
Ondřej Vašík f7c868
--- a/tests/touch/now-owned-by-other.sh
Ondřej Vašík f7c868
+++ b/tests/touch/now-owned-by-other.sh
Ondřej Vašík f7c868
@@ -28,7 +28,7 @@ chmod g+w root-owned
Ondřej Vašík f7c868
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
Ondřej Vašík f7c868
 chmod g+x .
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
-chroot --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
+chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
Ondřej Vašík f7c868
   touch -d now root-owned || fail=1
Ondřej Vašík f7c868
 
Ondřej Vašík f7c868
 Exit $fail
Ondřej Vašík f7c868
--
Ondřej Vašík f7c868
cgit v0.9.0.2