]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/cve-2019-5736.c
3 * Copyright © 2019 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2019 Canonical Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <lxc/lxccontainer.h>
30 #include <sys/types.h>
37 #define MYNAME "shortlived"
39 static int destroy_container(void)
49 execlp("lxc-destroy", "lxc-destroy", "-f", "-n", MYNAME
, NULL
);
53 ret
= waitpid(pid
, &status
, 0);
62 if (!WIFEXITED(status
)) { // did not exit normally
63 fprintf(stderr
, "%d: lxc-create exited abnormally\n", __LINE__
);
66 return WEXITSTATUS(status
);
69 static int create_container(void)
79 execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME
, NULL
);
83 ret
= waitpid(pid
, &status
, 0);
92 if (!WIFEXITED(status
)) { // did not exit normally
93 fprintf(stderr
, "%d: lxc-create exited abnormally\n", __LINE__
);
96 return WEXITSTATUS(status
);
99 int main(int argc
, char *argv
[])
104 struct lxc_container
*c
;
105 int ret
= EXIT_FAILURE
;
107 /* test a real container */
108 c
= lxc_container_new(MYNAME
, NULL
);
110 fprintf(stderr
, "%d: error creating lxc_container %s\n", __LINE__
, MYNAME
);
114 if (c
->is_defined(c
)) {
115 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
119 if (create_container() < 0) {
120 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
124 b
= c
->is_defined(c
);
126 fprintf(stderr
, "%d: %s thought it was not defined\n", __LINE__
, MYNAME
);
131 if (!s
|| strcmp(s
, "STOPPED")) {
132 fprintf(stderr
, "%d: %s is in state %s, not in STOPPED.\n", __LINE__
, c
->name
, s
? s
: "undefined");
136 b
= c
->load_config(c
, NULL
);
138 fprintf(stderr
, "%d: %s failed to read its config\n", __LINE__
, c
->name
);
142 if (!c
->set_config_item(c
, "lxc.init.cmd", "echo hello")) {
143 fprintf(stderr
, "%d: failed setting lxc.init.cmd\n", __LINE__
);
147 c
->want_daemonize(c
, true);
149 if (setenv("LXC_MEMFD_REXEC", "1", 1)) {
150 fprintf(stderr
, "%d: failed to set LXC_MEMFD_REXEC evironment variable\n", __LINE__
);
154 /* Test whether we can start a really short-lived daemonized container. */
155 for (i
= 0; i
< 10; i
++) {
156 if (!c
->startl(c
, 0, NULL
)) {
157 fprintf(stderr
, "%d: %s failed to start on %dth iteration\n", __LINE__
, c
->name
, i
);
161 if (!c
->wait(c
, "STOPPED", 30)) {
162 fprintf(stderr
, "%d: %s failed to wait on %dth iteration\n", __LINE__
, c
->name
, i
);
167 /* Test whether we can start a really short-lived daemonized container with lxc-init. */
168 for (i
= 0; i
< 10; i
++) {
169 if (!c
->startl(c
, 1, NULL
)) {
170 fprintf(stderr
, "%d: %s failed to start on %dth iteration\n", __LINE__
, c
->name
, i
);
174 if (!c
->wait(c
, "STOPPED", 30)) {
175 fprintf(stderr
, "%d: %s failed to wait on %dth iteration\n", __LINE__
, c
->name
, i
);
182 fprintf(stderr
, "all lxc_container tests passed for %s\n", c
->name
);
190 lxc_container_put(c
);