Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
117deb70
Unverified
Commit
117deb70
authored
May 15, 2018
by
Liza Tretyakova
Committed by
Christian Brauner
Jul 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: add filesystem and char device tests
Signed-off-by:
Liza Tretyakova
<
elizabet.tretyakova@gmail.com
>
parent
c6885c3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
7 deletions
+47
-7
mount_injection.c
src/tests/mount_injection.c
+47
-7
No files found.
src/tests/mount_injection.c
View file @
117deb70
...
...
@@ -146,16 +146,18 @@ static int perform_container_test(const char *name, const char *config_items[])
char
*
sret
;
char
template_log
[
sizeof
(
TEMPLATE
)],
template_dir
[
sizeof
(
TEMPLATE
)],
device_message
[
sizeof
(
"Check urandom device injected into "" - "
)
-
1
+
strlen
(
name
)
+
1
],
dir_message
[
sizeof
(
"Check dir "" injected into "" - "
)
-
1
+
sizeof
(
TEMPLATE
)
-
1
+
strlen
(
name
)
+
1
];
dir_message
[
sizeof
(
"Check dir "" injected into "" - "
)
-
1
+
sizeof
(
TEMPLATE
)
-
1
+
strlen
(
name
)
+
1
],
fs_message
[
sizeof
(
"Check devtmpfs injected into "" - "
)
-
1
+
strlen
(
name
)
+
1
];
struct
lxc_container
*
c
;
struct
lxc_mount
mnt
;
struct
lxc_log
log
;
int
ret
=
-
1
,
dev_msg_size
=
sizeof
(
"Check urandom device injected into "" - "
)
-
1
+
strlen
(
name
)
+
1
,
dir_msg_size
=
sizeof
(
"Check dir "" injected into "" - "
)
-
1
+
sizeof
(
TEMPLATE
)
-
1
+
strlen
(
name
)
+
1
;
dir_msg_size
=
sizeof
(
"Check dir "" injected into "" - "
)
-
1
+
sizeof
(
TEMPLATE
)
-
1
+
strlen
(
name
)
+
1
,
fs_msg_size
=
sizeof
(
"Check devtmpfs injected into "" - "
)
-
1
+
strlen
(
name
)
+
1
;
struct
mountinfo_data
device
=
{
.
mount_root
=
"/"
,
.
mount_root
=
"/
urandom
"
,
.
mount_point
=
"/mnt/mount_injection_test_urandom"
,
.
fstype
=
"devtmpfs"
,
.
fstype
=
NULL
,
.
mount_source
=
"/dev/urandom"
,
.
message
=
""
,
.
should_be_present
=
true
...
...
@@ -166,6 +168,13 @@ static int perform_container_test(const char *name, const char *config_items[])
.
mount_source
=
NULL
,
.
message
=
""
,
.
should_be_present
=
true
},
fs
=
{
.
mount_root
=
"/"
,
.
mount_point
=
"/mnt/mount_injection_test_devtmpfs"
,
.
fstype
=
"devtmpfs"
,
.
mount_source
=
NULL
,
.
message
=
""
,
.
should_be_present
=
true
};
/* Temp paths and messages setup */
...
...
@@ -190,6 +199,13 @@ static int perform_container_test(const char *name, const char *config_items[])
}
dir
.
message
=
&
dir_message
[
0
];
ret
=
snprintf
(
fs_message
,
fs_msg_size
,
"Check devtmpfs injected into %s - "
,
name
);
if
(
ret
<
0
||
ret
>=
fs_msg_size
)
{
fprintf
(
stderr
,
"Failed to create message for fs
\n
"
);
exit
(
EXIT_FAILURE
);
}
fs
.
message
=
&
fs_message
[
0
];
/* Setup logging*/
strcpy
(
template_log
,
TEMPLATE
);
i
=
lxc_make_tmpfile
(
template_log
,
false
);
...
...
@@ -244,7 +260,7 @@ static int perform_container_test(const char *name, const char *config_items[])
mnt
.
version
=
LXC_MOUNT_API_V1
;
/* Check device mounted */
ret
=
c
->
mount
(
c
,
"/dev/urandom"
,
"/mnt/mount_injection_test_urandom"
,
"devtmpfs"
,
0
,
NULL
,
&
mnt
);
ret
=
c
->
mount
(
c
,
"/dev/urandom"
,
"/mnt/mount_injection_test_urandom"
,
NULL
,
MS_BIND
,
NULL
,
&
mnt
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Failed to mount
\"
/dev/urandom
\"\n
"
);
goto
out
;
...
...
@@ -293,6 +309,31 @@ static int perform_container_test(const char *name, const char *config_items[])
if
(
ret
<
0
)
goto
out
;
/* Check fs mounted */
ret
=
c
->
mount
(
c
,
NULL
,
"/mnt/mount_injection_test_devtmpfs"
,
"devtmpfs"
,
0
,
NULL
,
&
mnt
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Failed to mount devtmpfs
\n
"
);
goto
out
;
}
ret
=
check_containers_mountinfo
(
c
,
&
fs
);
if
(
ret
<
0
)
goto
out
;
/* Check fs unmounted */
/* TODO: what about other umount flags? */
ret
=
c
->
umount
(
c
,
"/mnt/mount_injection_test_devtmpfs"
,
MNT_DETACH
,
&
mnt
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Failed to umount2 devtmpfs
\n
"
);
goto
out
;
}
fs
.
message
=
"Unmounted
\"
/mnt/mount_injection_test_devtmpfs
\"
-- should be missing now: "
;
fs
.
should_be_present
=
false
;
ret
=
check_containers_mountinfo
(
c
,
&
fs
);
if
(
ret
<
0
)
goto
out
;
/* Finalize the container */
if
(
!
c
->
stop
(
c
))
{
fprintf
(
stderr
,
"Stopping the container (%s) failed...
\n
"
,
name
);
...
...
@@ -340,8 +381,6 @@ static int do_unpriv_container_test()
{
const
char
*
config_items
[]
=
{
"lxc.mount.auto"
,
"shmounts:/tmp/mount_injection_test"
,
"lxc.init.uid"
,
"100000"
,
"lxc.init.gid"
,
"100000"
,
NULL
};
return
perform_container_test
(
NAME
"unprivileged"
,
config_items
);
...
...
@@ -353,6 +392,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"Privileged mount injection test failed
\n
"
);
return
-
1
;
}
if
(
do_unpriv_container_test
())
{
fprintf
(
stderr
,
"Unprivileged mount injection test failed
\n
"
);
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment