Commit Graph

6355 Commits

Author SHA1 Message Date
Yifeng Tan
61d7a733c7 confile: add lxc.proc.* to set proc filesystem
Signed-off-by: Yifeng Tan <tanyifeng1@huawei.com>
2017-12-13 20:08:56 +08:00
Christian Brauner
5af9369bf3
start: fix cgroup namespace preservation
Prior to this patch we raced with a very short-lived init process. Essentially,
the init process could exit before we had time to record the cgroup namespace
causing the container to abort and report ABORTING to the caller when it
actually started just fine. Let's not do this.

(This uses syscall(SYS_getpid) in the the child to retrieve the pid just in case
we're on an older glibc version and we end up in the namespace sharing branch
of the actual lxc_clone() call.)

Additionally this fixes the shortlived tests. They were faulty so far and
should have actually failed because of the cgroup namespace recording race but
the ret variable used to return from the function was not correctly
initialized. This fixes it.
Furthermore, the shortlived tests used the c->error_num variable to determine
success or failure but this is actually not correct when the container is
started daemonized.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-13 00:28:30 +01:00
Christian Brauner
6c84b5994a
tools: exit success when lxc-execute is daemonized
The error_num value doesn't tell us anything since the container hasn't exited.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 21:05:39 +01:00
Christian Brauner
5d113f650c
start: do not unconditionally dup std{in,out,err}
Starting with commit

    commit c5b93afba1
    Author: Li Feng <lifeng68@huawei.com>
    Date:   Mon Jul 10 17:19:52 2017 +0800

        start: dup std{in,out,err} to pty slave

        In the case the container has a console with a valid slave pty file descriptor
        we duplicate std{in,out,err} to the slave file descriptor so console logging
        works correctly. When the container does not have a valid slave pty file
        descriptor for its console and is started daemonized we should dup to
        /dev/null.

        Closes #1646.

        Signed-off-by: Li Feng <lifeng68@huawei.com>
        Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

we made std{err,in,out} a duplicate of the slave file descriptor of the console
if it existed. This meant we also duplicated all of them when we executed
application containers in the foreground even if some std{err,in,out} file
descriptor did not refer to a {p,t}ty. This blocked use cases such as:

    echo foo | lxc-execute -n -- cat

which are very valid and common with application containers but less common
with system containers where we don't have to care about this. So my suggestion
is to unconditionally duplicate std{err,in,out} to the console file descriptor
if we are either running daemonized - this ensures that daemonized application
containers with a single bash shell keep on working - or when we are not
running an application container. In other cases we only duplicate those file
descriptors that actually refer to a {p,t}ty. This logic is similar to what we
do for lxc-attach already.

Refers to #1690.
Closes #2028.

Reported-by: Felix Abecassis <fabecassis@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 20:50:51 +01:00
Christian Brauner
9e1329562b
conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:56 +01:00
Christian Brauner
a61b4e8584
coverity: #1426028
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:56 +01:00
Christian Brauner
a55f31bda2
coverity: #1425857
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
0e4adc1a33
coverity: #1425858
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
e8eb39565a
coverity: #1425859
check return value of snprintf()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
d5590c8c70
coverity: #1425860
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
f54f8d0b58
coverity: #1425861
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
41784e4ee4
coverity: #1425862
initialize handler

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:55 +01:00
Christian Brauner
6a0019fa97
coverity: #1425863
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
62de1db6ef
coverity: #1425866
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
d6d979bc2b
coverity: #1425867
do not pass NULL pointer to chdir()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
3ca108148b
coverity: #1425869
do not unmap prematurely

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
de429548c4
coverity: #1425870
check snprintf() return value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:55:54 +01:00
Christian Brauner
c7d76c0947
lxccontainer: cleanup {attach,detach}_interface()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:54:21 +01:00
Christian Brauner
acbfeda88b
lxccontainer: only attach netns on netdev detach
Detaching network namespaces as an unprivileged user is currently not possible
and attaching to the user namespace will mean we are not allowed to move the
network device into an ancestor network namespace.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:54:12 +01:00
Christian Brauner
b69dfc9fcb
coverity: #1425874 + cleanup
- check for memory allocation failure
- free allocated memory
- cleanup function

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 11:53:58 +01:00
Christian Brauner
bad943c4dc
Merge pull request #2021 from 3XX0/overlay-oob-copy
overlay: fix out-of-bounds copy
2017-12-12 11:40:21 +01:00
Jonathan Calmels
6d1a5f93db conf: avoid spawning unnecessary subshells
Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-12-11 16:52:55 -08:00
Christian Brauner
19bfbf6e94
tools: block using lxc-execute without config file
Moving away from internal symbols we can't do hacks like we currently do in
lxc-start and call internal functions like lxc_conf_init(). This is unsafe
anyway. Instead, we should simply error out if the user didn't give us a
configuration file to use. lxc-start refuses to start in that case already.

Relates to discussion in https://github.com/lxc/go-lxc/pull/96#discussion_r155075560 .
Closes #2023.

Reported-by: Felix Abecassis <fabecassis@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-12 01:45:54 +01:00
Jonathan Calmels
fe3485479f overlay: fix out-of-bounds copy
Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
2017-12-11 14:49:57 -08:00
Serge Hallyn
f449521ce6
Merge pull request #2020 from brauner/2017-12-11/clone
start: intelligently use clone() on ns sharing
2017-12-11 13:52:05 -06:00
Christian Brauner
7acb5ce30d
tests: add namespace sharing tests
This also ensures that the new more efficient clone() way of sharing namespaces
is tested.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 19:16:26 +01:00
Christian Brauner
8deca6c986
start: intelligently use clone() on ns sharing
When I first solved this problem I went for a fork() + setns() + clone() model.
This works fine but has unnecessary overhead for a couple of reasons:

- doing a full fork() including copying file descriptor table and virtual
  memory
- using pipes to retrieve the pid of the second child (the actual container
  process)

This can all be avoided by being a little smart in how we employ the clone()
syscall:

- using CLONE_VM will let us get rid of using pipes since we can simply write
  to the handler because we share the memory with our parent
- using CLONE_VFORK will also let us get rid of using pipes since the execution
  of the parent is suspended until the child returns
- using CLONE_VM will not cause virtual memory to be copied
- using CLONE_FILES will not cause the file descriptor table to be copied

Note that the intermediate clone() is used with CLONE_VM. Some glibc versions
used to reset the pid/tid to -1 when CLONE_VM was used without CLONE_THREAD.
But since the memory between parent and child is shared on CLONE_VM this would
invalidate the getpid() cache that glibc used to maintain and so getpid() in
the child would return the parent's pid. This is all fixed in newer glibc
versions where the getpid() cache is removed and the pid/tid is not reset
anymore. However, if for whatever reason you - dear commiter - somehow need to
get the pid of the dummy intermediate process for do_share_ns() you need to
call syscall(__NR_getpid) directly. The next lxc_clone() call does not employ
CLONE_VM and will be fine.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 19:15:25 +01:00
Christian Brauner
bc9724f76c
coverity: #1425879
do not double close file descriptor

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:37 +01:00
Christian Brauner
3151d4e2d8
coverity: #1425883
ensure \0-termination

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:37 +01:00
Christian Brauner
8810408c6b
coverity: #1425884
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
7fd3d41810
coverity: #1428855
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
edeb1836ba
coverity: #1425886
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
29f133bc33
coverity: #1425893
used calculated string length when copying into buffer

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
b44c0a6787
coverity: #1426029
fix use after free

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:34 +01:00
Christian Brauner
e409b21402
conf: lxc.sysctl coding style fixes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 11:27:24 +01:00
Christian Brauner
ed20740bca
Merge pull request #2009 from lifeng68/add_sysctl
confile: add lxc.sysctl config
2017-12-11 11:21:07 +01:00
LiFeng
7edd05402c confile: Add lxc.sysctl config
Signed-off-by: LiFeng <lifeng68@huawei.com>
2017-12-11 09:24:11 -05:00
Stéphane Graber
9f3b360c2b
Merge pull request #2019 from brauner/2017-12-11/fix_legacy_network_parser
legacy confile: fix legacy network parser
2017-12-11 00:40:27 -05:00
Christian Brauner
b668653c52
conf: fix lxc.prlimit clearing
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 06:22:56 +01:00
Christian Brauner
4bc717d6e3
legacy confile: fix legacy network parser
This fixes a bug introduced by:

commit 94f0035bf6
Author: Christian Brauner <christian.brauner@ubuntu.com>
Date:   Thu Dec 7 15:07:26 2017 +0100

    coverity: #1425924

    remove logically dead condition

    Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

Coverity's bug analysis is correct but my fix wasn't.

This commit fixes a bunch of other bugs I just spotted as well.

This unblocks #2009.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 06:03:45 +01:00
Stéphane Graber
b826fe7df3
travis: Fix build failure
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2017-12-09 01:51:14 -05:00
Serge Hallyn
8a82c80b7d
Merge pull request #2016 from flx42/lxc-oci-misc-improvements
lxc-oci misc improvements
2017-12-08 22:56:14 -06:00
Felix Abecassis
a787c33229 lxc-oci: add support for WorkingDir
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 20:38:43 -08:00
Serge Hallyn
6d75f4cb0b
Merge pull request #2012 from marcosps/pthread_mtx_msg
lxc: Distinguish pthread_mutex_unlock error messages
2017-12-08 22:10:50 -06:00
Serge Hallyn
be459e9997
Merge pull request #1950 from brauner/2017-11-27/criu_fixes
bugfixes
2017-12-08 21:59:09 -06:00
Felix Abecassis
8f54d926c5 lxc-oci: add IPv6 support to /etc/hosts
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 19:36:49 -08:00
Felix Abecassis
e86dcc912f lxc-oci: add basic handling of numerical uid/gid
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 19:36:40 -08:00
Tycho Andersen
4be4832738 add --share-$NS= support to lxc-execute
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2017-12-08 21:37:12 +00:00
Marcos Paulo de Souza
81a14ca944 lxc: Distinguish pthread_mutex_unlock error messages
The same message exists in lxclock.c and cgmanager.c, so print the
filename along with the message.

Before this patch:
lxc-destroy -n u1
pthread_mutex_unlock returned:1 Operation not permitted

After this patch:
xc-destroy -n u1
lxclock.c: pthread_mutex_unlock returned:1 Operation not permitted

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
2017-12-08 00:02:18 -02:00
Serge Hallyn
f6812e7f2e
Merge pull request #2011 from brauner/generic/coverity
coverity: bugfixes
2017-12-07 14:46:09 -06:00