~gary/ubuntu/precise/lxc/bug-951150

« back to all changes in this revision

Viewing changes to debian/patches/0032-start-check-caps.patch

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber, Serge Hallyn, Stéphane Graber
  • Date: 2012-02-02 19:06:19 UTC
  • Revision ID: package-import@ubuntu.com-20120202190619-h9w5i7o9e37jtqs7
Tags: 0.7.5-3ubuntu17
[ Serge Hallyn ]
* 0032-start-check-caps.patch: exit early and with a clear error message
  if lxc-start is run with insufficient permissions.  (LP: #925520)
* debian/lxc.init: if there is a failure during lxc network setup, clean
  up and exit. (LP: #925511)

[ Stéphane Graber ]
* 0033-ubuntu-template-multiarch.patch: Add support for building
  containers using qemu-user-static, using multi-arch to install some
  packages of the host architecture so the container boots and works.
* Add qemu-user-static as a Suggest of lxc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: lxc-start: exit early if insufficient privs
 
2
 This should be forwarded upstream.
 
3
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
 
4
Forwarded: no
 
5
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/925520
 
6
 
 
7
Index: lxc/src/lxc/caps.c
 
8
===================================================================
 
9
--- lxc.orig/src/lxc/caps.c     2012-01-31 15:05:12.426098000 -0600
 
10
+++ lxc/src/lxc/caps.c  2012-02-02 12:19:12.957178682 -0600
 
11
@@ -167,3 +167,42 @@
 
12
 
 
13
        return 0;
 
14
 }
 
15
+
 
16
+/*
 
17
+ * check if we have the caps needed to start a container.  returns 1 on
 
18
+ * success, 0 on error.  (I'd prefer this be a bool, but am afraid that
 
19
+ * might fail to build on some distros).
 
20
+ */
 
21
+int lxc_caps_check(void)
 
22
+{
 
23
+       uid_t uid = getuid();
 
24
+       cap_t caps;
 
25
+       cap_flag_value_t value;
 
26
+       int i, ret;
 
27
+
 
28
+       cap_value_t needed_caps[] = { CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SETUID, CAP_SETGID };
 
29
+
 
30
+#define NUMCAPS ((int) (sizeof(needed_caps) / sizeof(cap_t)))
 
31
+
 
32
+       if (!uid)
 
33
+               return 1;
 
34
+
 
35
+       caps = cap_get_proc();
 
36
+       if (!caps) {
 
37
+               ERROR("failed to cap_get_proc: %m");
 
38
+               return 0;
 
39
+       }
 
40
+
 
41
+       for (i=0; i<NUMCAPS; i++) {
 
42
+               ret = cap_get_flag(caps, needed_caps[i], CAP_EFFECTIVE, &value);
 
43
+               if (ret) {
 
44
+                       ERROR("Failed to cap_get_flag: %m");
 
45
+                       return 0;
 
46
+               }
 
47
+               if (!value) {
 
48
+                       return 0;
 
49
+               }
 
50
+       }
 
51
+
 
52
+       return 1;
 
53
+}
 
54
Index: lxc/src/lxc/caps.h
 
55
===================================================================
 
56
--- lxc.orig/src/lxc/caps.h     2012-01-31 15:05:12.426098000 -0600
 
57
+++ lxc/src/lxc/caps.h  2012-02-02 12:01:31.445196657 -0600
 
58
@@ -27,6 +27,7 @@
 
59
 extern int lxc_caps_down(void);
 
60
 extern int lxc_caps_up(void);
 
61
 extern int lxc_caps_init(void);
 
62
+extern int lxc_caps_check(void);
 
63
 
 
64
 #define lxc_priv(__lxc_function)                       \
 
65
        ({                                              \
 
66
Index: lxc/src/lxc/start.c
 
67
===================================================================
 
68
--- lxc.orig/src/lxc/start.c    2012-01-31 15:05:12.426098000 -0600
 
69
+++ lxc/src/lxc/start.c 2012-02-02 12:24:46.797173030 -0600
 
70
@@ -335,10 +335,17 @@
 
71
        return -1;
 
72
 }
 
73
 
 
74
+extern int lxc_caps_check(void);
 
75
+
 
76
 struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf)
 
77
 {
 
78
        struct lxc_handler *handler;
 
79
 
 
80
+       if (!lxc_caps_check()) {
 
81
+               ERROR("Not running with sufficient privilege");
 
82
+               return NULL;
 
83
+       }
 
84
+
 
85
        handler = malloc(sizeof(*handler));
 
86
        if (!handler)
 
87
                return NULL;