Commit Graph

8686 Commits

Author SHA1 Message Date
Thomas Parrott
3f0ed090d6 network: Adds mode param (bridge, router) to veth network setting
Defaulting to bridge mode.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2019-07-11 12:37:23 +01:00
Thomas Parrott
3e7d1bd171 lxc/log: Adds error_log_errno macro
Suggested usage:

	return error_log_errno(err, "Failed: %s", "some error");

It sets errno to the value of err, then calls SYSERROR with the format and remaining args.

It always returns -1.

Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
2019-07-11 11:29:38 +01:00
Christian Brauner
bc554fdff9
Merge pull request #3090 from Rachid-Koucha/patch-3
Suppress hardcoded table sizes
2019-07-11 12:10:28 +02:00
Rachid Koucha
6da7363420
Suppress hardcoded table sizes
. Use sizeof() instead of hardcoded values
. snprintf(..., size, ""...) is in error if the return code is >= size (not sufficient to set only ">")

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-07-11 10:01:36 +02:00
Christian Brauner
9b01795886
Merge pull request #3089 from Rachid-Koucha/patch-2
Typo fix
2019-07-11 09:57:34 +02:00
Rachid Koucha
8332a09c96
Typo fix
Fixed a typo in error message

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-07-11 09:42:05 +02:00
Christian Brauner
6587d52bf6
Merge pull request #3088 from tenforward/japanese
doc: Add lxc.comp.notify.cookie to Japanese lxc.container.conf(5)
2019-07-11 08:28:11 +02:00
KATOH Yasufumi
5bc821d349 doc: Add lxc.comp.notify.cookie to Japanese lxc.container.conf(5)
update for commit 214008e

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2019-07-11 15:22:08 +09:00
Stéphane Graber
fd34369e10
Merge pull request #3087 from brauner/master
cgroup: check for non-empty conf
2019-07-10 10:53:45 -04:00
Christian Brauner
d926acfde0
cgroup: check for non-empty conf
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-10 16:34:29 +02:00
Stéphane Graber
d094c18024
Merge pull request #3086 from brauner/2019-07-09/seccomp_fixes
seccomp: coding style
2019-07-09 15:15:41 -04:00
Christian Brauner
cbbdd1dd35
seccomp: coding style
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-09 21:08:20 +02:00
Christian Brauner
26077e91db
Merge pull request #3080 from Blub/seccomp-notify-api
Seccomp notify api update
2019-07-09 17:50:44 +02:00
Christian Brauner
b9dab9ef8f
af_unix: remove unused variable
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-09 17:19:29 +02:00
Wolfgang Bumiller
637996a4c3 seccomp: send caller pidfd along with proxied requests
On the one hand this should close the race between the
process exiting until the proxy reads the request.
On the other hand it'll help the proxy quickly access info
from /proc (such as ./cwd, ./ns/mnt, ...)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
87e547d9c7 seccomp: recvmsg with MSG_TRUNC
We only read the message without the cookie. For now assert
that the sender also didn't try to send more by letting
`recvmsg()` return the original size of the packet if it was
longer.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
214008eeb2 doc: document lxc.seccomp.notify.cookie
and fix a minor typo

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
651e63a719 seccomp: defer reconnecting to the proxy
With the previous commit we now attempt to reconnect to the
proxy in the beginning of the notify handler if we had no
connection.
If the connection fails later on, we now don't really need
to immediately try to reconnect if we send a default
response anyway (particularly if the recv() fails). (This
also gives the proxy more time, for instance if it was just
restarted.)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
ed3a98c4c2 seccomp: keep retrying to reconnect to proxy
If a syscall happens after we already failed to communicate
with the proxy, proxy_fd was -1.
Before the previous commit we'd then be stuck in the state
where there was no proxy registered. With the previous
commit we'd send a default reply and only then try to
reconnect.
Improve this even further by trying to reconnect right at
the start.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
1370a882bc seccomp: send default response when there's no proxy
Particularly, when there's no proxy registered (iow. none
configured but the seccomp profile still had a 'notify'
rule), we don't want to leave them hanging.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
3745ee0ec7 seccomp: retry connecting to the proxy once
If the first sendmsg() fails, try to reconnect once before
failing. Otherwise if a proxy restarts while no syscall
happens, the next syscall always fails with ENOSYS.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
5357b872f7 seccomp: don't ignore syscalls when there's no proxy
The container process would just hang.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
8a99ab014a seccomp: remove reconnect-loop
When we fail to send a message, we send a default seccomp
response and try to reconnect to the proxy. It doesn't
really make much sense to retry to send the request over the
new connection as the syscall has already been answered. The
same goes for receiving the response - after reconnecting to
the proxy, we're a new client to a potentially new proxy
process, so awaiting a response without having sent a
request doesn't make all too much sense either.

In the future we should probably have a timeout or retry
count for the entire proxy _transaction_ before sending a
response to seccomp at all (and probably handle requests
asynchronously).

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
045ee7210d seccomp: use SOCK_SEQPACKET for the notify proxy
The seccomp notify API has a few variables: The struct sizes
are queried at runtime, and we now also have a user
configured cookie.
This means that with a SOCK_STREAM connection the proxy
needs to carefully read() the right amount of data based on
the contents of our proxy message struct to avoid ending up
in the middle of a packet.
While for now this may not be too tragic, since we currently
only ever send a single packet and then wait for the
response, we may at some point want to be able to handle
multiple processes simultaneously, hence it makes sense to
switch to a packet based connection.

So switch to using SOCK_SEQPACKET which is packet based,
(and also guarantees ordering). The `MSG_PEEK` flag can be
used with `recvmsg()` to figure out a packet's size on the
other end, and usually the size *should* not change after
that for an existing connection from a running container.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
f910c9e526 seccomp: assert that __reserved is 0 in notify responses
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
4a094eec4a seccomp: update notify api
The previous API doesn't reflect the fact that
`seccomp_notif` and `seccomp_notif_resp` are allocatd
dynamically with sizes figured out at runtime.

We now query the sizes via the seccomp(2) syscall and change
`struct seccomp_notify_proxy_msg` to contain the sizes
instead of the data, with the data following afterwards.

Additionally it did not provide a convenient way to identify
the container the message originated from, for which we now
include a cookie configured via `lxc.seccomp.notify.cookie`.

Since we currently always send exactly one request and await
the response immediately, verify the `id` in the client's
response.

Finally, the proxy message's "version" field is removed, and
we reserve 64 bits in its place.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
84cf6d259b conf: add lxc.seccomp.notify.cookie
This is an arbitrary string to to be included in proxied
seccomp notification messages.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
99d03dec11 file_utils: add lxc_recvmsg_nointr_iov
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
970ef13dd2 af_unix: add lxc_unix_connect_type
we want to use SOCK_SEQPACKET and in the future perhaps
SOCK_DATAGRAM as well

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 12:25:10 +02:00
Christian Brauner
dc85e31eca af_unix: add lxc_abstract_unix_recv_fds_iov()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-09 12:25:10 +02:00
Wolfgang Bumiller
e1726045d4 af_unix: add lxc_abstract_unix_send_fds_iov
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-09 11:13:27 +02:00
Christian Brauner
cfc3b34209
Merge pull request #3085 from Blub/pidfd_send_signal-fixup
pidf_send_signal: fix return value
2019-07-08 23:33:58 +02:00
Wolfgang Bumiller
cf38fe06ac pidf_send_signal: fix return value
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-08 18:12:29 +02:00
Stéphane Graber
aab6e3eb73
Merge pull request #3083 from brauner/2019-07-07/mount_api
lxccontainer: properly cleanup on mount injection failure
2019-07-07 12:39:49 -04:00
Christian Brauner
1f77c35ecb
lxccontainer: properly cleanup on mount injection failure
Closes: #3082
Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-07 18:24:55 +02:00
Christian Brauner
9c238bc6bf
Merge pull request #3081 from brauner/2019-07-05/network_unification_fixes
start: call lxc_find_gateway_addresses early
2019-07-05 11:44:45 +02:00
Thomas Parrott
03ca4af8fa
start: call lxc_find_gateway_addresses early
This restores the lxc.net.x.ipv4.gateway = auto and
lxc.net.x.ipv6.gateway = auto functionality.

When the child is created the parent and child have different views of
struct lxc_handler since - obviously - virtual memory is duplicated. So any
changes to done by the parent that the child should see need to be IPCed to it.
For any non-actual device creation stuff this does not make much sense. This
includes finding gateway addresses. Move it back prior to clone().

Fixes #3078

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
[christian.brauner@ubuntu.com: non-functional changes and update commit message]
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-05 11:05:38 +02:00
Stéphane Graber
306ca14a29
Merge pull request #3077 from brauner/2019-07-03/network_fixes
network: simplify lxc_network_move_created_netdev_priv()
2019-07-03 18:13:20 -04:00
Christian Brauner
24190194c1
network: simplify lxc_network_move_created_netdev_priv()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 23:55:57 +02:00
Stéphane Graber
a70d78cdc8
Merge pull request #3076 from brauner/2019-07-03/network_fixes
network: fixes after unifying network creation
2019-07-03 17:43:54 -04:00
Christian Brauner
3c09b97cd5
network: send names for all non-trivial network types
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 23:28:58 +02:00
Christian Brauner
61302ef7dc
network: record created_name for instantiate_phys()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:48:20 +02:00
Christian Brauner
75b074eea0
network: simplify instantiate_phys()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:46:37 +02:00
Christian Brauner
83530dba89
network: record created_name for instantiate_vlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:44:52 +02:00
Christian Brauner
d4d684109c
network: simplify instantiate_vlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:44:19 +02:00
Christian Brauner
e7fdd504e9
network: record created_name for instantiate_ipvlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:43:19 +02:00
Christian Brauner
dd1192068d
network: simplify instantiate_ipvlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:42:59 +02:00
Christian Brauner
a9704f0521
network: stash created_name in instantiate_macvlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:39:54 +02:00
Christian Brauner
8021de2564
network: simplify instantiate_macvlan()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:39:24 +02:00
Christian Brauner
3ebffb9896
network: s/loDev/loop_device/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-07-03 21:37:37 +02:00