1
Index: lxc-0.8.0~rc1/configure.ac
2
===================================================================
3
--- lxc-0.8.0~rc1.orig/configure.ac 2012-08-08 17:54:34.000000000 -0500
4
+++ lxc-0.8.0~rc1/configure.ac 2012-08-08 17:54:34.000000000 -0500
1
commit 16049797728edeba06f3d6dce8c21daa7ffdbced
2
Author: Serge Hallyn <serge.hallyn@canonical.com>
3
Date: Fri Jul 27 21:13:53 2012 -0500
5
Introduce support for seccomp.
9
This patch is so far just a proof of concept. The libseccomp api will be
10
changing soon so it probably wouldn't be worth pulling this until it is
11
updated for the new API.
13
This patch introduces support for seccomp to lxc. Seccomp lets a program
14
restrict its own (and its children's) future access to system calls. It
15
uses a simple whitelist system call policy file. It would probably be
16
better to switch to something more symbolic (i.e specifying 'open' rather
17
than the syscall #, especially given container arch flexibility).
19
I just wanted to get this out there as a first step. You can also get
20
source for an ubuntu package based on this patch at
21
https://code.launchpad.net/~serge-hallyn/ubuntu/quantal/lxc/lxc-seccomp
23
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
25
Index: lxc-fix-seccomp/README
26
===================================================================
27
--- lxc-fix-seccomp.orig/README 2012-08-16 15:38:00.877173000 -0500
28
+++ lxc-fix-seccomp/README 2012-08-16 15:38:00.877173000 -0500
32
Daniel Lezcano <daniel.lezcano@free.fr>
37
+To restrict a container with seccomp, you must specify a profile which is
38
+basically a whitelist of system calls it may execute. In the container
39
+config file, add a line like
41
+lxc.seccomp = /var/lib/lxc/q1/seccomp.full
43
+I created a usable (but basically worthless) seccomp.full file using
45
+cat > seccomp.full << EOF
49
+for i in `seq 0 300`; do
50
+ echo $i >> secomp.full
52
+for i in `seq 1024 1079`; do
53
+ echo $i >> seccomp.full
56
+ -- Serge Hallyn <serge.hallyn@ubuntu.com> Fri, 27 Jul 2012 15:47:02 +0600
57
Index: lxc-fix-seccomp/configure.ac
58
===================================================================
59
--- lxc-fix-seccomp.orig/configure.ac 2012-08-16 15:38:00.877173000 -0500
60
+++ lxc-fix-seccomp/configure.ac 2012-08-16 17:48:05.955917878 -0500
7
63
AM_CONDITIONAL([ENABLE_RPATH], [test "x$enable_rpath" = "xyes"])
9
65
+AC_ARG_ENABLE([seccomp],
10
66
+ [AC_HELP_STRING([--enable-seccomp], [enable seccomp])],
11
+ [], [enable_seccomp=yes])
12
+AM_CONDITIONAL([ENABLE_SECCOMP], [test "x$enable_seccomp" = "xyes"])
67
+ [], [enable_seccomp=check])
14
69
AC_ARG_ENABLE([doc],
15
70
[AC_HELP_STRING([--enable-doc], [make mans (require docbook2man installed) [default=auto]])],
16
71
[], [enable_doc=auto])
18
73
AC_MSG_ERROR([docbook2man required by man request, but not found])
76
+if test "$enable_seccomp" = "check" ; then
77
+ AC_CHECK_LIB([seccomp],[seccomp_init],[enable_seccomp=yes], [enable_seccomp=no])
80
+AM_CONDITIONAL([ENABLE_SECCOMP], [test "x$enable_seccomp" = "xyes"])
21
82
+AM_COND_IF([ENABLE_SECCOMP],
22
83
+ [AC_CHECK_HEADER([seccomp.h],[],[AC_MSG_ERROR([You must install the seccomp development package in order to compile lxc])])
23
84
+ AC_CHECK_LIB([seccomp], [seccomp_init],[],[AC_MSG_ERROR([You must install the seccomp development package in order to compile lxc])])
85
+ AC_DEFINE_UNQUOTED([ENABLE_SECCOMP], 1, [Seccomp is available])
24
86
+ AC_SUBST([SECCOMP_LIBS], [-lseccomp])])
26
88
AM_CONDITIONAL([ENABLE_DOCBOOK], [test "x$have_docbook" = "xyes"])
28
90
AC_ARG_ENABLE([examples],
29
Index: lxc-0.8.0~rc1/src/lxc/Makefile.am
91
Index: lxc-fix-seccomp/src/lxc/Makefile.am
30
92
===================================================================
31
--- lxc-0.8.0~rc1.orig/src/lxc/Makefile.am 2012-08-08 17:54:34.000000000 -0500
32
+++ lxc-0.8.0~rc1/src/lxc/Makefile.am 2012-08-08 17:54:34.000000000 -0500
93
--- lxc-fix-seccomp.orig/src/lxc/Makefile.am 2012-08-16 15:38:00.877173000 -0500
94
+++ lxc-fix-seccomp/src/lxc/Makefile.am 2012-08-16 17:36:30.547929653 -0500
37
+ seccomp.c seccomp.h \
38
100
mainloop.c mainloop.h \
39
101
af_unix.c af_unix.h \
42
104
-DLXCPATH=\"$(LXCPATH)\" \
43
105
-DLXCINITDIR=\"$(LXCINITDIR)\"
45
107
+if ENABLE_SECCOMP
46
108
+AM_CFLAGS += -DHAVE_SECCOMP
109
+liblxc_so_SOURCES += seccomp.c
49
112
liblxc_so_CFLAGS = -fPIC -DPIC $(AM_CFLAGS)
139
202
if [ -e $lxc_path/$lxc_orig/fstab ];then
140
203
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-08-08 17:54:34.000000000 -0500
204
Index: lxc-fix-seccomp/src/lxc/lxcseccomp.h
205
===================================================================
206
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
207
+++ lxc-fix-seccomp/src/lxc/lxcseccomp.h 2012-08-16 15:38:00.877173000 -0500
210
+ * lxc: linux Container library
212
+ * (C) Copyright Canonical, Inc. 2012
215
+ * Serge Hallyn <serge.hallyn@canonical.com>
217
+ * This library is free software; you can redistribute it and/or
218
+ * modify it under the terms of the GNU Lesser General Public
219
+ * License as published by the Free Software Foundation; either
220
+ * version 2.1 of the License, or (at your option) any later version.
222
+ * This library is distributed in the hope that it will be useful,
223
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
224
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
225
+ * Lesser General Public License for more details.
227
+ * You should have received a copy of the GNU Lesser General Public
228
+ * License along with this library; if not, write to the Free Software
229
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
232
+#ifndef _lxc_seccomp_h
237
+int lxc_seccomp_load(struct lxc_conf *conf);
238
+int lxc_read_seccomp_config(struct lxc_conf *conf);
240
+static inline int lxc_seccomp_load(struct lxc_conf *conf) {
244
+static inline int lxc_read_seccomp_config(struct lxc_conf *conf) {
250
Index: lxc-fix-seccomp/src/lxc/seccomp.c
251
===================================================================
252
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
253
+++ lxc-fix-seccomp/src/lxc/seccomp.c 2012-08-16 15:38:00.877173000 -0500
145
254
@@ -0,0 +1,121 @@
147
256
+ * lxc: linux Container library
290
407
close(handler->sigfd);
292
409
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-08-08 17:54:34.000000000 -0500
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 07:02:11.000000000 -0500
342
+++ lxc-0.8.0~rc1/README 2012-08-08 17:54:34.000000000 -0500
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
371
Index: lxc-0.8.0~rc1/src/lxc/Makefile.in
372
===================================================================
373
--- lxc-0.8.0~rc1.orig/src/lxc/Makefile.in 2012-08-08 17:54:34.000000000 -0500
374
+++ lxc-0.8.0~rc1/src/lxc/Makefile.in 2012-08-08 17:55:55.125019315 -0500
379
+ seccomp.c seccomp.h \
380
mainloop.c mainloop.h \
381
af_unix.c af_unix.h \
385
-Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
387
-liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor
388
+liblxc_so_LDADD = -lutil $(CAP_LIBS) -lapparmor -lseccomp
395
AM_LDFLAGS = -Wl,-E $(am__append_1)
396
-LDADD = liblxc.so @CAP_LIBS@ -lapparmor
397
+LDADD = liblxc.so @CAP_LIBS@ -lapparmor -lseccomp
398
lxc_attach_SOURCES = lxc_attach.c
399
lxc_cgroup_SOURCES = lxc_cgroup.c
400
lxc_checkpoint_SOURCES = lxc_checkpoint.c
410
Index: lxc-fix-seccomp/configure
411
===================================================================
412
--- lxc-fix-seccomp.orig/configure 2012-08-16 15:38:00.877173000 -0500
413
+++ lxc-fix-seccomp/configure 2012-08-16 16:23:27.284003869 -0500
420
+ENABLE_SECCOMP_FALSE
426
enable_option_checking
427
enable_dependency_tracking
433
@@ -1358,6 +1362,7 @@
434
--disable-dependency-tracking speeds up one-time build
435
--enable-dependency-tracking do not reject slow dependency extractors
436
--disable-rpath do not set rpath in executables
437
+ --enable-seccomp enable seccomp
438
--enable-doc make mans (require docbook2man installed)
440
--disable-examples do not install configuration examples
441
@@ -4340,6 +4345,22 @@
445
+# Check whether --enable-seccomp was given.
446
+if test "${enable_seccomp+set}" = set; then :
447
+ enableval=$enable_seccomp;
452
+ if test "x$enable_seccomp" = "xyes"; then
453
+ ENABLE_SECCOMP_TRUE=
454
+ ENABLE_SECCOMP_FALSE='#'
456
+ ENABLE_SECCOMP_TRUE='#'
457
+ ENABLE_SECCOMP_FALSE=
461
# Check whether --enable-doc was given.
462
if test "${enable_doc+set}" = set; then :
463
enableval=$enable_doc;
464
@@ -4392,6 +4413,71 @@
465
as_fn_error $? "docbook2man required by man request, but not found" "$LINENO" 5
468
+if test -z "$ENABLE_SECCOMP_TRUE"; then :
469
+ ac_fn_c_check_header_mongrel "$LINENO" "seccomp.h" "ac_cv_header_seccomp_h" "$ac_includes_default"
470
+if test "x$ac_cv_header_seccomp_h" = xyes; then :
473
+ as_fn_error $? "You must install the seccomp development package in order to compile lxc" "$LINENO" 5
477
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for seccomp_init in -lseccomp" >&5
478
+$as_echo_n "checking for seccomp_init in -lseccomp... " >&6; }
479
+if ${ac_cv_lib_seccomp_seccomp_init+:} false; then :
480
+ $as_echo_n "(cached) " >&6
482
+ ac_check_lib_save_LIBS=$LIBS
483
+LIBS="-lseccomp $LIBS"
484
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
485
+/* end confdefs.h. */
487
+/* Override any GCC internal prototype to avoid an error.
488
+ Use char because int might match the return type of a GCC
489
+ builtin and then its argument prototype would still apply. */
493
+char seccomp_init ();
497
+return seccomp_init ();
502
+if ac_fn_c_try_link "$LINENO"; then :
503
+ ac_cv_lib_seccomp_seccomp_init=yes
505
+ ac_cv_lib_seccomp_seccomp_init=no
507
+rm -f core conftest.err conftest.$ac_objext \
508
+ conftest$ac_exeext conftest.$ac_ext
509
+LIBS=$ac_check_lib_save_LIBS
511
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_seccomp_seccomp_init" >&5
512
+$as_echo "$ac_cv_lib_seccomp_seccomp_init" >&6; }
513
+if test "x$ac_cv_lib_seccomp_seccomp_init" = xyes; then :
514
+ cat >>confdefs.h <<_ACEOF
515
+#define HAVE_LIBSECCOMP 1
518
+ LIBS="-lseccomp $LIBS"
521
+ as_fn_error $? "You must install the seccomp development package in order to compile lxc" "$LINENO" 5
525
+cat >>confdefs.h <<_ACEOF
526
+#define ENABLE_SECCOMP 1
529
+ SECCOMP_LIBS=-lseccomp
533
if test "x$have_docbook" = "xyes"; then
535
ENABLE_DOCBOOK_FALSE='#'
536
@@ -5103,6 +5189,10 @@
537
as_fn_error $? "conditional \"ENABLE_RPATH\" was never defined.
538
Usually this means the macro was only invoked conditionally." "$LINENO" 5
540
+if test -z "${ENABLE_SECCOMP_TRUE}" && test -z "${ENABLE_SECCOMP_FALSE}"; then
541
+ as_fn_error $? "conditional \"ENABLE_SECCOMP\" was never defined.
542
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
544
if test -z "${ENABLE_DOCBOOK_TRUE}" && test -z "${ENABLE_DOCBOOK_FALSE}"; then
545
as_fn_error $? "conditional \"ENABLE_DOCBOOK\" was never defined.
546
Usually this means the macro was only invoked conditionally." "$LINENO" 5