Commit Graph

4488 Commits

Author SHA1 Message Date
Wolfgang Bumiller
16d08ae7e3 hooks: put binary hooks into $libexecdir/lxc/hooks
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Serge Hallyn
fd51a89b60 support arguments in lxc.init_cmd
Otherwise something like
	lxc.init_cmd = /sbin/init debug verbose
fails trying to execute a file called "/sbin/init debug verbose"

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Sungbae Yoo
4ff8fb6cae Unify the polite word style in Korean manpages
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Sungbae Yoo
756f0ae856 doc: Add the description of lxc.hook.stop to Korean lxc.container.conf(5)
Update for commit 0a2b5ab

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Serge Hallyn
5d1df05bd5 only re-open fds if stdin is a tty
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 13:28:22 -05:00
Stéphane Graber
120146b993 Init error_num to 1
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 13:28:22 -05:00
Stéphane Graber
4a31104560 lxc-ubuntu-cloud: Never exit 0 when no container is created
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 13:28:22 -05:00
Stéphane Graber
208a29f10c Merge pull request #683 from Kubuxu/patch-1
arch template: Fix systemd-sysctl service
2015-10-30 10:01:32 -04:00
Jakub Sztandera
427d42930d arch template: Fix systemd-sysctl service
The systemd-sysctl service includes condition that /proc/sys/ has to be read-write.
In lxc only /proc/sys/net/ is read-write which causes the condition to fail and service not to run.
This patch changes the check to /proc/sys/net/ and makes the service apply only rules that are in net tree.

Signed-off-by: Jakub Sztandera <kubuxu@gmail.com>
2015-10-30 12:09:42 +01:00
Serge Hallyn
407fef433c don't close std* fd if opentty fails
We didn't do it before, and it makes testcases fail.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-10-29 23:51:14 -05:00
Christian Brauner
9e5a2a015a Simplify function
Instead of duplicating the cleanup-code, once for success and once for failure,
simply keep a variable fret which is -1 in the beginning and gets set to 0 on
success or stays -1 on failure.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:58:55 -04:00
Christian Brauner
1e3ce0da49 Parse rootfs->path
The mount_entry_overlay_dirs() and mount_entry_aufs_dirs() functions create
workdirs and upperdirs for overlay and aufs lxc.mount.entry entries. They try
to make sure that the workdirs and upperdirs can only be created under the
containerdir (e.g. /path/to/the/container/CONTAINERNAME). In order to do this
the right hand side of

                if ((strncmp(upperdir, lxcpath, dirlen) == 0) && (strncmp(upperdir, rootfs->path, rootfslen) != 0))

was thought to check if the rootfs->path is not present in the workdir and
upperdir mount options. But the current check is bogus since it will be
trivially true whenever the container is a block-dev or overlay or aufs backed
since the rootfs->path will then have a form like e.g.

        overlayfs:/some/path:/some/other/path

This patch adds the function ovl_get_rootfs_dir() which parses rootfs->path by
searching backwards for the first occurrence of the delimiter pair ":/". We do
not simply search for ":" since it might be used in path names. If ":/" is not
found we assume the container is directory backed and simply return
strdup(rootfs->path).

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-29 17:57:17 -04:00
Serge Hallyn
4ed565e51a lxc-net: switch After target to network-online.target
Otherwise it may start too early and end up taking 10.0.3.1 even
though eth0 was eventually going to end up on 10.0.3.x.

https://bugs.launchpad.net/juju-core/+bug/1510619

Reported-by: Ryan Harper <ryan.harper@ubuntu.com>
Cc: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:56:33 -04:00
Serge Hallyn
b5f4bc783f lxc-usernsexec: reopen fds 0,1,2 separately
lxc-usernsexec was using fd 0 and reopening it as 0,1,2 for
the new task.  If doing "lxc-usernsexec .. < script" this
will corrupt the file 'script'.

Reported-by: Fiedler Roman <Roman.Fiedler@ait.ac.at>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:56:31 -04:00
Serge Hallyn
f348e47c93 Ignore trailing /init.scope in init cgroups
The lxc monitor does not store the container's cgroups, rather it
recalculates them whenever needed.

Systemd moves itself into a /init.scope cgroup for the systemd
controller.

It might be worth changing that (by storing all cgroup info in the
lxc_handler), but for now go the hacky route and chop off any
trailing /init.scope.

I definately thinkg we want to switch to storing as that will be
more bullet-proof, but for now we need a quick backportable fix
for systemd 226 guests.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:56:27 -04:00
Stéphane Graber
27c278a769 ubuntu-cloud: Replace .tar.gz by .tar.xz and don't auto-generate missing tarballs
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-29 17:47:47 -04:00
Christian Brauner
0a2dddd479 Make mount_entry_create_*_dirs() more robust
The mount_entry_create_*_dirs() functions currently assume that the rootfs of
the container is actually named "rootfs". This has the consequence that

	del = strstr(lxcpath, "/rootfs");
	if (!del) {
		free(lxcpath);
		lxc_free_array((void **)opts, free);
		return -1;
	}
	*del = '\0';

will return NULL when the rootfs of a container is not actually named "rootfs".
This means the we return -1 and do not create the necessary upperdir/workdir
directories required for the overlay/aufs mount to work. Hence, let's not make
that assumption. We now pass lxc_path and lxc_name to
mount_entry_create_*_dirs() and create the path directly. To prevent failure we
also have mount_entry_create_*_dirs() check that lxc_name and lxc_path are not
empty when they are passed in.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-29 17:47:44 -04:00
KATOH Yasufumi
d0b2a43477 doc: Add the description of lxc.hook.stop to Japanese lxc.container.conf(5)
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:45:49 -04:00
Sungbae Yoo
06ce392132 doc: Add lxc.ephemeral in Korean lxc.container.conf(5)
Update for commit 4e6eb26

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-29 17:45:47 -04:00
Serge Hallyn
e963273a77 coverity: free mounts on error path
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-10-17 21:16:22 -05:00
Stéphane Graber
2d9ec00d61
Tell gcc about lxcmntent for the unmount hook
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 15:44:38 -07:00
Stéphane Graber
36dd8426cb
Don't include mntent when lxcmntent is used
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 14:36:51 -07:00
Stéphane Graber
83d9344146
Don't re-include config.h in lxcmntent.h
It causes trouble when importing from different paths and will always be
included ahead of time anyway.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 13:29:36 -07:00
Stéphane Graber
4a459ee7ba
Update gitignore
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 13:08:44 -04:00
Stéphane Graber
97272aec0f
Attempt to fix bionic builds of unmount-namespace
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-11 13:07:52 -04:00
Sungbae Yoo
73740a136b doc: Add the note related mount in Korean lxc.container.conf(5)
Update for commit 592fd47

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-07 16:39:46 +01:00
Sungbae Yoo
5901bc7919 doc: Add the common and '-s' option in Korean lxc-destroy(1)
Update for commit 3635c5e

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-07 16:39:44 +01:00
KATOH Yasufumi
7346eb3aab doc: Add lxc.ephemeral in Japanese lxc.container.conf(5)
Update for commit 4e6eb26

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-07 16:39:42 +01:00
Wolfgang Bumiller
b73f115f41 added the unmount-namespace hook
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:24 +01:00
Wolfgang Bumiller
0a2b5ab1e7 document the stop hook
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:12 +01:00
Wolfgang Bumiller
b3286b628b pass namespace handles to the stop hook
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:11 +01:00
Wolfgang Bumiller
8438bfbda7 run stop hook between STOPPING and STOPPED states
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:11 +01:00
Wolfgang Bumiller
52492063b7 added stop-hook entries
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:10 +01:00
Wolfgang Bumiller
b6b2b194a8 preserve container namespace
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:10 +01:00
Wolfgang Bumiller
035a38fc93 start.c:preserve_ns: added pid parameter
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:10 +01:00
Christian Brauner
6e46cc0dca Make overlayfs mounts work directly
When users wanted to mount overlay directories with lxc.mount.entry they had to
create upperdirs and workdirs beforehand in order to mount them. To create it
for them we add the functions mount_entry_create_overlay_dirs() and
mount_entry_create_aufs_dirs() which do this for them. User can now simply
specify e.g.:

        lxc.mount.entry = /lower merged overlay lowerdir=/lower,upper=/upper,workdir=/workdir,create=dir

and /upper and /workdir will be created for them. /upper and /workdir need to
be absolute paths to directories which are created under the containerdir (e.g.
under $lxcpath/CONTAINERNAME/). Relative mountpoints, mountpoints outside the
containerdir, and mountpoints within the container's rootfs are ignored. (The
latter *might* change in the future should it be considered safe/useful.)

Specifying

        lxc.mount.entry = /lower merged overlay lowerdir=/lower:/lower2,create=dir

will lead to a read-only overlay mount in accordance with the
kernel-documentation.

Specifying

        lxc.mount.entry = /lower merged overlay lowerdir=/lower,create=dir

will fail when no upperdir and workdir options are given.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-07 16:38:07 +01:00
Stéphane Graber
80e80c4011 Fix the type of i in lxc_mount_auto_mounts
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-05 12:12:17 +01:00
Serge Hallyn
cc4fd5064b lxc_mount_auto_mounts: fix weirdness
The default_mounts[i].destination is never NULL except in the last
'stop here' entry.  Coverity doesn't know about that and so is spewing
a warning.  In any case, let's add a more stringent check in case someone
accidentally adds a NULL there later.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-05 11:51:59 +01:00
KATOH Yasufumi
2c79e91b4b doc: Add the note related mount in Japanese lxc.container.conf(5)
Update for commit 592fd47

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-05 11:49:25 +01:00
Serge Hallyn
13cea07dcd lxc-test-symlink: add a test using absolute symlink
This would have caught the regression last night.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-05 11:49:05 +01:00
Christian Brauner
7111ed68cb Make lxc-start-ephemeral use lxc.ephemeral
While lxc-copy is under review let users benefit (reboot survival etc.) from the
new lxc.ephemeral option already in lxc-start-ephemeral. This way we can remove
the lxc.hook.post-stop script-

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-10-05 11:49:03 +01:00
Christian Brauner
4f64d0db3f Cleanup parts of lxc-destroy
A bit of pedantry usually doesn't hurt. The code should be easier to follow now
and avoids some repetitions.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-05 11:47:19 +01:00
Christian Brauner
4e6eb26bf0 Add lxc.ephemeral to lxc.container.conf manpage
Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-05 11:47:16 +01:00
Bogdan Purcareata
9d291dd226 seccomp: add aarch64 support
Enable aarch64 seccomp support for LXC containers running on ARM64
architectures. Tested with libseccomp 2.2.0 and the default seccomp
policy example files delivered with the LXC package.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-10-05 11:47:12 +01:00
Stéphane Graber
570bea4eed Merge pull request #666 from Ponce/slackware-template
Add a slackware template.
2015-09-30 13:58:01 -04:00
Stéphane Graber
e209cddb66 Merge pull request #667 from cjwatson/ephemeral-parse-passwd
lxc-start-ephemeral: Parse passwd directly
2015-09-30 13:56:50 -04:00
Colin Watson
c6be89f857 lxc-start-ephemeral: Parse passwd directly
On Ubuntu 15.04, lxc-start-ephemeral's call to pwd.getpwnam always
fails.  While I haven't been able to prove it or track down an exact
cause, I strongly suspect that glibc does not guarantee that you can
call NSS functions after a context switch without re-execing.  (Running
"id root" in a subprocess from the same point works fine.)

It's safer to use getent to extract the relevant line from the passwd
file and parse it directly.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
2015-09-30 13:52:32 +01:00
Stéphane Graber
4928c7186c
Define O_PATH and O_NOFOLLOW for Android
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-09-29 14:59:28 -04:00
Matteo Bernardini
3a05a669c1 Add a slackware template.
Requires pkgtools and slackpkg (from the slackware-current tree).

Signed-off-by: Matteo Bernardini <ponce@slackbuilds.org>
2015-09-29 17:35:25 +02:00
Serge Hallyn
592fd47a62 CVE-2015-1335: Protect container mounts against symlinks
When a container starts up, lxc sets up the container's inital fstree
by doing a bunch of mounting, guided by the container configuration
file.  The container config is owned by the admin or user on the host,
so we do not try to guard against bad entries.  However, since the
mount target is in the container, it's possible that the container admin
could divert the mount with symbolic links.  This could bypass proper
container startup (i.e. confinement of a root-owned container by the
restrictive apparmor policy, by diverting the required write to
/proc/self/attr/current), or bypass the (path-based) apparmor policy
by diverting, say, /proc to /mnt in the container.

To prevent this,

1. do not allow mounts to paths containing symbolic links

2. do not allow bind mounts from relative paths containing symbolic
links.

Details:

Define safe_mount which ensures that the container has not inserted any
symbolic links into any mount targets for mounts to be done during
container setup.

The host's mount path may contain symbolic links.  As it is under the
control of the administrator, that's ok.  So safe_mount begins the check
for symbolic links after the rootfs->mount, by opening that directory.

It opens each directory along the path using openat() relative to the
parent directory using O_NOFOLLOW.  When the target is reached, it
mounts onto /proc/self/fd/<targetfd>.

Use safe_mount() in mount_entry(), when mounting container proc,
and when needed.  In particular, safe_mount() need not be used in
any case where:

1. the mount is done in the container's namespace
2. the mount is for the container's rootfs
3. the mount is relative to a tmpfs or proc/sysfs which we have
   just safe_mount()ed ourselves

Since we were using proc/net as a temporary placeholder for /proc/sys/net
during container startup, and proc/net is a symbolic link, use proc/tty
instead.

Update the lxc.container.conf manpage with details about the new
restrictions.

Finally, add a testcase to test some symbolic link possibilities.

Reported-by: Roman Fiedler
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-09-29 09:52:55 -04:00