[libvirt] [PATCH]lxc: don't mount dir if ownership couldn't be known

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Tue Nov 12 11:38:02 UTC 2013


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

We bind mount some dir from host to guest.
With userns enabled, if we couldn't know
the dir's ownership, don't mount it.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 src/lxc/lxc_container.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 255c711..92d0a39 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -96,6 +96,8 @@
 typedef char lxc_message_t;
 #define LXC_CONTINUE_MSG 'c'
 
+#define OVERFLOWUID 65534
+
 typedef struct __lxc_child_argv lxc_child_argv_t;
 struct __lxc_child_argv {
     virDomainDefPtr config;
@@ -1073,6 +1075,18 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
     if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0)
         goto cleanup;
 
+    if (stat(src, &st) < 0) {
+        virReportSystemError(errno, _("Unable to stat bind source %s"),
+                             src);
+        goto cleanup;
+    } else {
+        if (OVERFLOWUID == st.st_uid || OVERFLOWUID == st.st_gid)
+            errno = EPERM;
+            virReportSystemError(errno, _("Unknown st_uid/st_gid for %s"),
+                                 fs->src);
+        goto cleanup;
+    }
+
     if (stat(fs->dst, &st) < 0) {
         if (errno != ENOENT) {
             virReportSystemError(errno, _("Unable to stat bind target %s"),
-- 
1.8.2.1




More information about the libvir-list mailing list