1
Index: lxc-0.8.0~rc1/configure.ac
2
===================================================================
3
--- lxc-0.8.0~rc1.orig/configure.ac 2012-07-27 04:47:14.000000000 +0000
4
+++ lxc-0.8.0~rc1/configure.ac 2012-07-27 04:50:32.321657349 +0000
7
AM_CONDITIONAL([ENABLE_RPATH], [test "x$enable_rpath" = "xyes"])
9
+AC_ARG_ENABLE([seccomp],
10
+ [AC_HELP_STRING([--enable-seccomp], [enable seccomp])],
11
+ [], [enable_seccomp=yes])
12
+AM_CONDITIONAL([ENABLE_SECCOMP], [test "x$enable_seccomp" = "xyes"])
15
[AC_HELP_STRING([--enable-doc], [make mans (require docbook2man installed) [default=auto]])],
16
[], [enable_doc=auto])
18
AC_MSG_ERROR([docbook2man required by man request, but not found])
21
+AM_COND_IF([ENABLE_SECCOMP],
22
+ [AC_CHECK_HEADER([seccomp.h],[],[AC_MSG_ERROR([You must install the seccomp development package in order to compile lxc])])
23
+ AC_CHECK_LIB([seccomp], [seccomp_init],[],[AC_MSG_ERROR([You must install the seccomp development package in order to compile lxc])])
24
+ AC_SUBST([SECCOMP_LIBS], [-lseccomp])])
26
AM_CONDITIONAL([ENABLE_DOCBOOK], [test "x$have_docbook" = "xyes"])
28
AC_ARG_ENABLE([examples],
29
Index: lxc-0.8.0~rc1/src/lxc/Makefile.am
30
===================================================================
31
--- lxc-0.8.0~rc1.orig/src/lxc/Makefile.am 2012-07-27 04:47:14.000000000 +0000
32
+++ lxc-0.8.0~rc1/src/lxc/Makefile.am 2012-07-27 04:55:40.789650086 +0000
37
+ seccomp.c seccomp.h \
38
mainloop.c mainloop.h \
42
-DLXCPATH=\"$(LXCPATH)\" \
43
-DLXCINITDIR=\"$(LXCINITDIR)\"
46
+AM_CFLAGS += -DHAVE_SECCOMP
49
liblxc_so_CFLAGS = -fPIC -DPIC $(AM_CFLAGS)
53
-Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
55
-liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
56
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor -lseccomp
62
AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir)
64
-LDADD=liblxc.so @CAP_LIBS@ -lapparmor
65
+LDADD=liblxc.so @CAP_LIBS@ -lapparmor -lseccomp
67
lxc_attach_SOURCES = lxc_attach.c
68
lxc_cgroup_SOURCES = lxc_cgroup.c
69
Index: lxc-0.8.0~rc1/src/lxc/conf.h
70
===================================================================
71
--- lxc-0.8.0~rc1.orig/src/lxc/conf.h 2012-07-27 04:47:14.000000000 +0000
72
+++ lxc-0.8.0~rc1/src/lxc/conf.h 2012-07-27 04:50:54.185650337 +0000
76
struct lxc_list hooks[NUM_LXC_HOOKS];
77
+ char *seccomp; // filename with the seccomp rules
80
int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf);
81
Index: lxc-0.8.0~rc1/src/lxc/confile.c
82
===================================================================
83
--- lxc-0.8.0~rc1.orig/src/lxc/confile.c 2012-07-27 04:47:14.000000000 +0000
84
+++ lxc-0.8.0~rc1/src/lxc/confile.c 2012-07-27 04:50:32.325656692 +0000
86
static int config_network_ipv6_gateway(const char *, char *, struct lxc_conf *);
87
static int config_cap_drop(const char *, char *, struct lxc_conf *);
88
static int config_console(const char *, char *, struct lxc_conf *);
89
+static int config_seccomp(const char *, char *, struct lxc_conf *);
91
typedef int (*config_cb)(const char *, char *, struct lxc_conf *);
94
{ "lxc.network.ipv6", config_network_ipv6 },
95
{ "lxc.cap.drop", config_cap_drop },
96
{ "lxc.console", config_console },
97
+ { "lxc.seccomp", config_seccomp },
100
static const size_t config_size = sizeof(config)/sizeof(struct config);
105
+static int config_seccomp(const char *key, char *value,
106
+ struct lxc_conf *lxc_conf)
110
+ if (lxc_conf->seccomp) {
111
+ ERROR("seccomp already defined");
114
+ path = strdup(value);
116
+ SYSERROR("failed to strdup '%s': %m", value);
120
+ lxc_conf->seccomp = path;
125
static int config_hook(const char *key, char *value,
126
struct lxc_conf *lxc_conf)
128
Index: lxc-0.8.0~rc1/src/lxc/lxc-clone.in
129
===================================================================
130
--- lxc-0.8.0~rc1.orig/src/lxc/lxc-clone.in 2012-07-27 04:47:14.000000000 +0000
131
+++ lxc-0.8.0~rc1/src/lxc/lxc-clone.in 2012-07-27 04:50:32.329656065 +0000
133
sed -i '/lxc.utsname/d' $lxc_path/$lxc_new/config
134
echo "lxc.utsname = $hostname" >> $lxc_path/$lxc_new/config
136
-grep "lxc.mount[ \t]" $lxc_path/$lxc_new/config >/dev/null 2>&1 && { sed -i '/lxc.mount[ \t]/d' $lxc_path/$lxc_new/config; echo "lxc.mount = $lxc_path/$lxc_new/fstab" >> $lxc_path/$lxc_new/config; }
137
+grep "lxc.mount =" $lxc_path/$lxc_new/config >/dev/null 2>&1 && { sed -i '/lxc.mount =/d' $lxc_path/$lxc_new/config; echo "lxc.mount = $lxc_path/$lxc_new/fstab" >> $lxc_path/$lxc_new/config; }
139
if [ -e $lxc_path/$lxc_orig/fstab ];then
140
cp $lxc_path/$lxc_orig/fstab $lxc_path/$lxc_new/fstab
141
Index: lxc-0.8.0~rc1/src/lxc/seccomp.c
142
===================================================================
143
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
144
+++ lxc-0.8.0~rc1/src/lxc/seccomp.c 2012-07-27 20:37:50.856592211 +0000
147
+ * lxc: linux Container library
149
+ * (C) Copyright Canonical, Inc. 2012
152
+ * Serge Hallyn <serge.hallyn@canonical.com>
154
+ * This library is free software; you can redistribute it and/or
155
+ * modify it under the terms of the GNU Lesser General Public
156
+ * License as published by the Free Software Foundation; either
157
+ * version 2.1 of the License, or (at your option) any later version.
159
+ * This library is distributed in the hope that it will be useful,
160
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
161
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
162
+ * Lesser General Public License for more details.
164
+ * You should have received a copy of the GNU Lesser General Public
165
+ * License along with this library; if not, write to the Free Software
166
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
172
+#include <seccomp.h>
174
+#include <seccomp.h>
175
+#include "lxcseccomp.h"
179
+lxc_log_define(lxc_seccomp, lxc);
182
+ * The first line of the config file has a policy language version
183
+ * the second line has some directives
184
+ * then comes policy subject to the directives
185
+ * right now version must be '1'
186
+ * the directives must include 'whitelist' (only type of policy currently
187
+ * supported) and can include 'debug' (though debug is not yet supported).
189
+static int parse_config(FILE *f, struct lxc_conf *conf)
194
+ ret = fscanf(f, "%d\n", &version);
195
+ if (ret != 1 || version != 1) {
196
+ ERROR("invalid version");
199
+ if (!fgets(line, 1024, f)) {
200
+ ERROR("invalid config file");
203
+ if (!strstr(line, "whitelist")) {
204
+ ERROR("only whitelist policy is supported");
207
+ if (strstr(line, "debug")) {
208
+ ERROR("debug not yet implemented");
211
+ /* now read in the whitelist entries one per line */
212
+ while (fgets(line, 1024, f)) {
214
+ ret = sscanf(line, "%d", &nr);
217
+ ret = seccomp_rule_add(SCMP_ACT_ALLOW, nr, 0);
219
+ ERROR("failed loading allow rule for %d\n", nr);
226
+int lxc_read_seccomp_config(struct lxc_conf *conf)
231
+ if (seccomp_init(SCMP_ACT_ERRNO(31)) < 0) { /* for debug, pass in SCMP_ACT_TRAP */
232
+ ERROR("failed initializing seccomp");
235
+ if (!conf->seccomp)
238
+ /* turn of no-new-privs. We don't want it in lxc, and it breaks
240
+ if (seccomp_attr_set(SCMP_FLTATR_CTL_NNP, 0)) {
241
+ ERROR("failed to turn off n-new-privs\n");
245
+ f = fopen(conf->seccomp, "r");
247
+ SYSERROR("failed to open seccomp policy file %s\n", conf->seccomp);
250
+ ret = parse_config(f, conf);
255
+int lxc_seccomp_load(struct lxc_conf *conf)
258
+ if (!conf->seccomp)
260
+ ret = seccomp_load();
262
+ ERROR("Error loading the seccomp policy");
267
Index: lxc-0.8.0~rc1/src/lxc/start.c
268
===================================================================
269
--- lxc-0.8.0~rc1.orig/src/lxc/start.c 2012-07-27 04:47:14.000000000 +0000
270
+++ lxc-0.8.0~rc1/src/lxc/start.c 2012-07-27 04:50:32.329656065 +0000
275
+ if (lxc_read_seccomp_config(conf) != 0) {
276
+ ERROR("failed loading seccomp policy");
277
+ goto out_free_name;
280
/* Begin the set the state to STARTING*/
281
if (lxc_set_state(name, handler, STARTING)) {
282
ERROR("failed to set state '%s'", lxc_state2str(STARTING));
284
if (apparmor_load(handler) < 0)
285
goto out_warn_father;
287
+ if (lxc_seccomp_load(handler->conf) != 0)
288
+ goto out_warn_father;
290
close(handler->sigfd);
292
HOOK(handler->name, "start", handler->conf);
293
Index: lxc-0.8.0~rc1/src/lxc/lxcseccomp.h
294
===================================================================
295
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
296
+++ lxc-0.8.0~rc1/src/lxc/lxcseccomp.h 2012-07-27 04:57:34.661646994 +0000
299
+ * lxc: linux Container library
301
+ * (C) Copyright Canonical, Inc. 2012
304
+ * Serge Hallyn <serge.hallyn@canonical.com>
306
+ * This library is free software; you can redistribute it and/or
307
+ * modify it under the terms of the GNU Lesser General Public
308
+ * License as published by the Free Software Foundation; either
309
+ * version 2.1 of the License, or (at your option) any later version.
311
+ * This library is distributed in the hope that it will be useful,
312
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
313
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
314
+ * Lesser General Public License for more details.
316
+ * You should have received a copy of the GNU Lesser General Public
317
+ * License along with this library; if not, write to the Free Software
318
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
321
+#ifndef _lxc_seccomp_h
326
+int lxc_seccomp_load(struct lxc_conf *conf);
327
+int lxc_read_seccomp_config(struct lxc_conf *conf);
329
+static inline int lxc_seccomp_load(struct lxc_conf *conf) {
333
+static inline int lxc_read_seccomp_config(struct lxc_conf *conf) {
339
Index: lxc-0.8.0~rc1/README
340
===================================================================
341
--- lxc-0.8.0~rc1.orig/README 2011-10-25 12:02:11.000000000 +0000
342
+++ lxc-0.8.0~rc1/README 2012-07-27 20:49:05.850603933 +0000
346
Daniel Lezcano <daniel.lezcano@free.fr>
351
+To restrict a container with seccomp, you must specify a profile which is
352
+basically a whitelist of system calls it may execute. In the container
353
+config file, add a line like
355
+lxc.seccomp = /var/lib/lxc/q1/seccomp.full
357
+I created a usable (but basically worthless) seccomp.full file using
359
+cat > seccomp.full << EOF
363
+for i in `seq 0 300`; do
364
+ echo $i >> secomp.full
366
+for i in `seq 1024 1079`; do
367
+ echo $i >> seccomp.full
370
+ -- Serge Hallyn <serge.hallyn@ubuntu.com> Fri, 27 Jul 2012 15:47:02 +0600