summaryrefslogtreecommitdiff
path: root/tests/syscalls.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-02-11 12:13:14 +0100
committerLudovic Courtès <ludo@gnu.org>2020-02-11 12:33:35 +0100
commit1deca767be1b84b96633e317f3fcdd5165f95df3 (patch)
tree6ddc18cc2023ba35e419bb7f63f08a1e839cba2d /tests/syscalls.scm
parent3d2f29382de2d0ee852745cc002dfe2b5d22e1c2 (diff)
syscalls: Re-enable 'pivot-root' test.
Fixes <https://bugs.gnu.org/25476>. Reported by Paul Garlick <pgarlick@tourbillion-technology.com>. * tests/syscalls.scm ("pivot-root"): Skip only when PERFORM-CONTAINER-TESTS? is true. Rewrite to use a socket pair instead of a pipe. Synchronize parent and child so that the parent can initialize the child's UID and GID mappings before continuing.
Diffstat (limited to 'tests/syscalls.scm')
-rw-r--r--tests/syscalls.scm55
1 files changed, 31 insertions, 24 deletions
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index 1b3121e503e..7fe0cd15456 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2015 David Thompson <davet@gnu.org> 3;;; Copyright © 2015 David Thompson <davet@gnu.org>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
@@ -161,29 +161,22 @@
161 (waitpid fork-pid) 161 (waitpid fork-pid)
162 result)))))))) 162 result))))))))
163 163
164;; XXX: Skip this test when running Linux > 4.7.5 to work around 164(when (not perform-container-tests?)
165;; <https://bugzilla.kernel.org/show_bug.cgi?id=183461>.
166(when (or (not perform-container-tests?)
167 (version>? (utsname:release (uname)) "4.7.5")
168
169 ;; Skip on Ubuntu's 4.4 kernels, which contain a backport of the
170 ;; faulty code: <https://bugs.gnu.org/25476>.
171 (member (utsname:release (uname))
172 '("4.4.0-21-generic" "4.4.0-59-generic"
173 "4.4.0-116-generic")))
174 (test-skip 1)) 165 (test-skip 1))
175(test-equal "pivot-root" 166(test-equal "pivot-root"
176 #t 167 'success!
177 (match (pipe) 168 (match (socketpair AF_UNIX SOCK_STREAM 0)
178 ((in . out) 169 ((parent . child)
179 (match (clone (logior CLONE_NEWUSER CLONE_NEWNS SIGCHLD)) 170 (match (clone (logior CLONE_NEWUSER CLONE_NEWNS SIGCHLD))
180 (0 171 (0
181 (dynamic-wind 172 (dynamic-wind
182 (const #t) 173 (const #t)
183 (lambda () 174 (lambda ()
184 (close in) 175 (close parent)
185 (call-with-temporary-directory 176 (call-with-temporary-directory
186 (lambda (root) 177 (lambda (root)
178 (display "ready\n" child)
179 (read child) ;wait for "go!"
187 (let ((put-old (string-append root "/real-root"))) 180 (let ((put-old (string-append root "/real-root")))
188 (mount "none" root "tmpfs") 181 (mount "none" root "tmpfs")
189 (mkdir put-old) 182 (mkdir put-old)
@@ -192,18 +185,32 @@
192 (display "testing\n" port))) 185 (display "testing\n" port)))
193 (pivot-root root put-old) 186 (pivot-root root put-old)
194 ;; The test file should now be located inside the root directory. 187 ;; The test file should now be located inside the root directory.
195 (write (file-exists? "/test") out) 188 (write (and (file-exists? "/test") 'success!) child)
196 (close out))))) 189 (close child)))))
197 (lambda () 190 (lambda ()
198 (primitive-exit 0)))) 191 (primitive-exit 0))))
199 (pid 192 (pid
200 (close out) 193 (close child)
201 (let ((result (read in))) 194 (match (read parent)
202 (close in) 195 ('ready
203 (and (zero? (match (waitpid pid) 196 ;; Set up the UID/GID mapping so that we can mkdir on the tmpfs:
204 ((_ . status) 197 ;; <https://bugzilla.kernel.org/show_bug.cgi?id=183461>.
205 (status:exit-val status)))) 198 (call-with-output-file (format #f "/proc/~d/setgroups" pid)
206 (eq? #t result)))))))) 199 (lambda (port)
200 (display "deny" port)))
201 (call-with-output-file (format #f "/proc/~d/uid_map" pid)
202 (lambda (port)
203 (format port "0 ~d 1" (getuid))))
204 (call-with-output-file (format #f "/proc/~d/gid_map" pid)
205 (lambda (port)
206 (format port "0 ~d 1" (getgid))))
207 (display "go!\n" parent)
208 (let ((result (read parent)))
209 (close parent)
210 (and (zero? (match (waitpid pid)
211 ((_ . status)
212 (status:exit-val status))))
213 result)))))))))
207 214
208(test-equal "scandir*, ENOENT" 215(test-equal "scandir*, ENOENT"
209 ENOENT 216 ENOENT