Commit 2b0e17e4 by Serge Hallyn Committed by Stéphane Graber

don't leak the rootfs.pin fd into the container

Only the container parent needs to keep that fd open. Close it as soon as the container's first task is spawned. Else it can show up in /proc/$$/fd in the container. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 20087962
...@@ -575,6 +575,9 @@ static int do_start(void *data) ...@@ -575,6 +575,9 @@ static int do_start(void *data)
lxc_sync_fini_parent(handler); lxc_sync_fini_parent(handler);
/* don't leak the pinfd to the container */
close(handler->pinfd);
/* Tell the parent task it can begin to configure the /* Tell the parent task it can begin to configure the
* container and wait for it to finish * container and wait for it to finish
*/ */
...@@ -691,7 +694,6 @@ int lxc_spawn(struct lxc_handler *handler) ...@@ -691,7 +694,6 @@ int lxc_spawn(struct lxc_handler *handler)
{ {
int failed_before_rename = 0; int failed_before_rename = 0;
const char *name = handler->name; const char *name = handler->name;
int pinfd;
if (lxc_sync_init(handler)) if (lxc_sync_init(handler))
return -1; return -1;
...@@ -735,8 +737,8 @@ int lxc_spawn(struct lxc_handler *handler) ...@@ -735,8 +737,8 @@ int lxc_spawn(struct lxc_handler *handler)
* marking it readonly. * marking it readonly.
*/ */
pinfd = pin_rootfs(handler->conf->rootfs.path); handler->pinfd = pin_rootfs(handler->conf->rootfs.path);
if (pinfd == -1) { if (handler->pinfd == -1) {
ERROR("failed to pin the container's rootfs"); ERROR("failed to pin the container's rootfs");
goto out_abort; goto out_abort;
} }
...@@ -818,8 +820,8 @@ int lxc_spawn(struct lxc_handler *handler) ...@@ -818,8 +820,8 @@ int lxc_spawn(struct lxc_handler *handler)
lxc_sync_fini(handler); lxc_sync_fini(handler);
if (pinfd >= 0) if (handler->pinfd >= 0)
close(pinfd); close(handler->pinfd);
return 0; return 0;
......
...@@ -49,6 +49,7 @@ struct lxc_handler { ...@@ -49,6 +49,7 @@ struct lxc_handler {
#if HAVE_APPARMOR #if HAVE_APPARMOR
int aa_enabled; int aa_enabled;
#endif #endif
int pinfd;
}; };
extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *); extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment