]>
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.
24 #include <lxc/lxccontainer.h>
29 #include <sys/types.h>
36 #define MYNAME "shortlived"
38 static int destroy_container(void)
48 execlp("lxc-destroy", "lxc-destroy", "-f", "-n", MYNAME
, NULL
);
52 ret
= waitpid(pid
, &status
, 0);
61 if (!WIFEXITED(status
)) { // did not exit normally
62 fprintf(stderr
, "%d: lxc-create exited abnormally\n", __LINE__
);
65 return WEXITSTATUS(status
);
68 static int create_container(void)
78 execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME
, NULL
);
82 ret
= waitpid(pid
, &status
, 0);
91 if (!WIFEXITED(status
)) { // did not exit normally
92 fprintf(stderr
, "%d: lxc-create exited abnormally\n", __LINE__
);
95 return WEXITSTATUS(status
);
98 int main(int argc
, char *argv
[])
103 struct lxc_container
*c
;
104 int ret
= EXIT_FAILURE
;
106 /* test a real container */
107 c
= lxc_container_new(MYNAME
, NULL
);
109 fprintf(stderr
, "%d: error creating lxc_container %s\n", __LINE__
, MYNAME
);
113 if (c
->is_defined(c
)) {
114 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
118 if (create_container() < 0) {
119 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
123 b
= c
->is_defined(c
);
125 fprintf(stderr
, "%d: %s thought it was not defined\n", __LINE__
, MYNAME
);
130 if (!s
|| strcmp(s
, "STOPPED")) {
131 fprintf(stderr
, "%d: %s is in state %s, not in STOPPED.\n", __LINE__
, c
->name
, s
? s
: "undefined");
135 b
= c
->load_config(c
, NULL
);
137 fprintf(stderr
, "%d: %s failed to read its config\n", __LINE__
, c
->name
);
141 if (!c
->set_config_item(c
, "lxc.init.cmd", "echo hello")) {
142 fprintf(stderr
, "%d: failed setting lxc.init.cmd\n", __LINE__
);
146 c
->want_daemonize(c
, true);
148 if (setenv("LXC_MEMFD_REXEC", "1", 1)) {
149 fprintf(stderr
, "%d: failed to set LXC_MEMFD_REXEC evironment variable\n", __LINE__
);
153 /* Test whether we can start a really short-lived daemonized container. */
154 for (i
= 0; i
< 10; i
++) {
155 if (!c
->startl(c
, 0, NULL
)) {
156 fprintf(stderr
, "%d: %s failed to start on %dth iteration\n", __LINE__
, c
->name
, i
);
160 if (!c
->wait(c
, "STOPPED", 30)) {
161 fprintf(stderr
, "%d: %s failed to wait on %dth iteration\n", __LINE__
, c
->name
, i
);
166 /* Test whether we can start a really short-lived daemonized container with lxc-init. */
167 for (i
= 0; i
< 10; i
++) {
168 if (!c
->startl(c
, 1, NULL
)) {
169 fprintf(stderr
, "%d: %s failed to start on %dth iteration\n", __LINE__
, c
->name
, i
);
173 if (!c
->wait(c
, "STOPPED", 30)) {
174 fprintf(stderr
, "%d: %s failed to wait on %dth iteration\n", __LINE__
, c
->name
, i
);
181 fprintf(stderr
, "all lxc_container tests passed for %s\n", c
->name
);
189 lxc_container_put(c
);