@@ -17,11 +17,11 @@ mod test_mount {
17
17
18
18
use libc:: { EACCES , EROFS } ;
19
19
20
+ use nix:: errno:: Errno ;
20
21
use nix:: mount:: { mount, umount, MsFlags , MS_BIND , MS_RDONLY , MS_NOEXEC } ;
21
22
use nix:: sched:: { unshare, CLONE_NEWNS , CLONE_NEWUSER } ;
22
23
use nix:: sys:: stat:: { self , S_IRWXU , S_IRWXG , S_IRWXO , S_IXUSR , S_IXGRP , S_IXOTH } ;
23
24
use nix:: unistd:: getuid;
24
- use nix:: sys:: utsname;
25
25
26
26
use tempdir:: TempDir ;
27
27
@@ -31,20 +31,6 @@ exit 23";
31
31
const EXPECTED_STATUS : i32 = 23 ;
32
32
33
33
const NONE : Option < & ' static [ u8 ] > = None ;
34
-
35
- // Skip tests on kernel 4.4.0, which has a bug regarding tmpfs in namespaces
36
- // https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1659087
37
- pub fn check_kernel ( ) {
38
- let u = utsname:: uname ( ) ;
39
- if u. release ( ) . starts_with ( "4.4.0" ) {
40
- let stderr = io:: stderr ( ) ;
41
- let mut handle = stderr. lock ( ) ;
42
- writeln ! ( handle, "Linux kernel 4.4.0 has known bugs with tmpfs in namespaces. Skipping test." )
43
- . unwrap ( ) ;
44
- process:: exit ( 0 ) ;
45
- }
46
- }
47
-
48
34
pub fn test_mount_tmpfs_without_flags_allows_rwx ( ) {
49
35
let tempdir = TempDir :: new ( "nix-test_mount" )
50
36
. unwrap_or_else ( |e| panic ! ( "tempdir failed: {}" , e) ) ;
@@ -64,6 +50,23 @@ exit 23";
64
50
. write ( true )
65
51
. mode ( ( S_IRWXU | S_IRWXG | S_IRWXO ) . bits ( ) )
66
52
. open ( & test_path)
53
+ . or_else ( |e|
54
+ if Errno :: from_i32 ( e. raw_os_error ( ) . unwrap ( ) ) == Errno :: EOVERFLOW {
55
+ // Skip tests on certain Linux kernels which have a bug
56
+ // regarding tmpfs in namespaces.
57
+ // Ubuntu 14.04 and 16.04 are known to be affected; 16.10 is
58
+ // not. There is no legitimate reason for open(2) to return
59
+ // EOVERFLOW here.
60
+ // https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1659087
61
+ let stderr = io:: stderr ( ) ;
62
+ let mut handle = stderr. lock ( ) ;
63
+ writeln ! ( handle, "Buggy Linux kernel detected. Skipping test." )
64
+ . unwrap ( ) ;
65
+ process:: exit ( 0 ) ;
66
+ } else {
67
+ panic ! ( "open failed: {}" , e) ;
68
+ }
69
+ )
67
70
. and_then ( |mut f| f. write ( SCRIPT_CONTENTS ) )
68
71
. unwrap_or_else ( |e| panic ! ( "write failed: {}" , e) ) ;
69
72
@@ -200,7 +203,6 @@ exit 23";
200
203
. write ( true )
201
204
. open ( "/proc/self/uid_map" )
202
205
. and_then ( |mut f| f. write ( format ! ( "1000 {} 1\n " , uid) . as_bytes ( ) ) )
203
- //.and_then(|mut f| f.write(format!("1000 {} 1\n", uid).as_bytes()))
204
206
. unwrap_or_else ( |e| panic ! ( "could not write uid map: {}" , e) ) ;
205
207
}
206
208
}
@@ -225,12 +227,9 @@ macro_rules! run_tests {
225
227
226
228
#[ cfg( target_os = "linux" ) ]
227
229
fn main ( ) {
228
- use test_mount:: { setup_namespaces, check_kernel,
229
- test_mount_tmpfs_without_flags_allows_rwx,
230
- test_mount_rdonly_disallows_write,
231
- test_mount_noexec_disallows_exec,
230
+ use test_mount:: { setup_namespaces, test_mount_tmpfs_without_flags_allows_rwx,
231
+ test_mount_rdonly_disallows_write, test_mount_noexec_disallows_exec,
232
232
test_mount_bind} ;
233
- check_kernel ( ) ;
234
233
setup_namespaces ( ) ;
235
234
236
235
run_tests ! ( test_mount_tmpfs_without_flags_allows_rwx,
0 commit comments