Commit graph

123 commits

Author SHA1 Message Date
Andrew Vagin
49448676ac util: don't leak cr-img objects (v2)
We need to call close_image() for "empty" images.

v2: don't touch generic functiuons
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-26 17:04:37 +03:00
Andrew Vagin
61b8fc264f net: block all traffic in internal network (v4)
Let's imagine that we have two local interconnected sockets.
Whe we are restoring tcp sockets, we need to disable the repair mode
to restore data in sending queues.

If traffic isn't blocked, a socket starts operating, but
in this time another end can be not restored yet.

$ test/zdtm.sh -r ns/static/socket-tcpbuf-local
...
(00.274632) 5: Error (sk-tcp.c:485): Can't restore 2 queue data (-1), want (1780919:1780919): Connection reset by peer

We create a separate chain to avoid conflicts with other rules.

https://bugs.openvz.org/browse/CRIU-96

v2: use iptables-restore to apply whole configuration for one call
v3: add a comment why we use iptables-restore instread of iptables.
v4: remove unused headers
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-19 17:17:07 +03:00
Cyrill Gorcunov
7de345d6b7 net: Move node's net fd reference into service fd
So we keep it and dont close inside close_old_fds()
helper but pass into veth creation so the kernel
can fetch the net namespace of the veth peer.

v2 (by avagin@):
 - don't forget to close opened descriptor

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-19 16:46:36 +03:00
Andrew Vagin
1e8a0594db net: dump iptables for ipv6 (v2)
v2: don't dump iptables if ipv6 isn't supported
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-19 15:19:01 +03:00
Andrew Vagin
1648db970c kerndat: check whether ipv6 is supported or not (v2)
v2: use a cached value to dump ipv6 interface addesses
    call get_ipv6() from kerndat_init_rst too

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-19 15:18:08 +03:00
Pavel Emelyanov
dc00fea333 net: Dont print error in rule save
This thing is new and can be absent in ip tool, which is OK
and is handled by net.c code itself.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 16:31:21 +03:00
Pavel Emelyanov
336b990995 net: Add flags to run_ip_tool
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 16:31:20 +03:00
Pavel Emelyanov
18d9170858 util: Add flags to cr_system
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 16:31:19 +03:00
Tycho Andersen
8a95be0679 net: allow c/r of empty bridges in the container
Implementing c/r of bridges with slaves shouldn't be too hard (viz. the
comment), but this is all I need to for right now.

v2: remove extra debug statement
v3: * remember to close fd in dump_bridge
    * use "known" buffer length and snprintf for spath in dump_bridge
    * change brace style

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-12 10:31:58 +03:00
Tycho Andersen
5f0b9ae1de net: ipv4: add ignore_routes_with_linkdown sysctl
Looks like this is new as of the 4.2 timeframe. It does bring up a
question: should we do a ls /proc/sys/net/conf/lo on the host to figure out
what sysctls to try and dump instead of use this hardcoded list? I guess we
need to check file modes too, because of mc_forwarding, but something like
that.

v2: add ignore_routes_with_linkdown to the end of the hardcoded devconfs
    list, so as not to break migration across criu versions.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-09 12:02:40 +03:00
Pavel Emelyanov
8cfe833696 net: Only warn on ip rule save missing, do not print error
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-28 00:13:28 +04:00
Pavel Emelyanov
e5df07654a net: Do not fail on absent rules image and fail on bad one
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-28 00:12:57 +04:00
Kirill Tkhai
c9afd17ad6 net: Add ip rule save/restore
Add support for save and restore of ip rules. It uses new
functionality of iproute which is already in iproute git:

http://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/commit/?id=2f4e171f7df22107b38fddcffa56c1ecb5e73359

v2: Use xstrdup() instead of strdup().
v3: Use open/close instead of helper.
v4: Return -1 on empty dump.

Signed-off-by: Kirill Tkhai <ktkhai@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-27 22:56:33 +03:00
Cyrill Gorcunov
12cb5bb87c net: Treat venet device as a separate complete device
When restoring venet device we need to restore its
index as well, which actually possible with new iproute2
package but the problem is that the index itself lays
inside image file. We could use crit tool to extract
it but this would slowdon procedure signifantly (need
to run python which would parse the image, or need
to pass the index into environmnet from inside of
the CRIU itself).

So lets do a trick and simply created venet device
inside container by criu itself (thanks we support
creating venet via netlink interface now).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-27 22:54:07 +03:00
Kir Kolyshkin
17b92fa542 Append newline when using pr_err()
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-09 18:28:00 +03:00
Kir Kolyshkin
e5654e586c Use strlcpy
It's better to

1. Use strlcpy() instead of strncpy() as otherwise we might end up
   with a not NULL-terminated string, which opens a portal to hell.
   There are a few places reported by Coverity for this, such as:
    - in criu_connect(), Coverity CID 51591;
    - in proc_pid_parse(), Coverity CID 51590;
    - in move_veth_to_bridge(), Coverity CID 51593;
    - etc.

2. Use strlcpy() instead of strcpy() to avoid buffer overruns.
   Some of these are also reported by Coverity, for example
   the one in dump_filemap(), Coverity CID 51630.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:57:28 +03:00
Kir Kolyshkin
250c89edde read_ns_sys_file(): check if buf is long enough
In case buf size is not adequate, report and return an error.
This is modelled after commit 1ead3d7.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:56:55 +03:00
Kir Kolyshkin
ec863205f4 read_ns_sys_file(): don't overrun buf
This is a classical off-by-one error. If sizeof(buf) is 512,
the last element is buf[511] but not buf[512].

Note that if read() returns 0, we return 0 but buf stays
uninitialized.

Reported by Coverity, CID 114623.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:56:42 +03:00
Tycho Andersen
f79f4546cf sysctl: move sysctl calls to usernsd
When in a userns, tasks can't write to certain sysctl files:

(00.009653)      1: Error (sysctl.c:142): Can't open sysctl kernel/hostname: Permission denied

See inline comments for details on affected namespaces.

Mostly for my own education in what is required to port something to be
userns restorable, I ported the sysctl stuff. A potential concern for this
patch is that copying structures with pointers around is kind of gory. I
did it ad-hoc here, but it may be worth inventing some mechanisms to make
it easier, although I'm not sure what exactly that would look like
(potentially re-using some of the protobuf bits; I'll investigate this more
if it looks helpful when doing the cgroup user namespaces port?).

Another issue is that there is not a great way to return non-fd stuff in
memory right now from userns_call; one of the little hacks in this code
would be "simplified" if we invented a way to do this.

v2: coalesce the individual struct sysctl_req requests into one big
    sysctl_userns_req that is in a contiguous region of memory so that we
    can pass it via userns_call. Hopefully nobody finds my little ascii
    diagram too offensive :)
v3: use the fork/setns trick to change the syctl values in the right ns for
    IPC/UTS nses; see inline comment for details
v4: only use sysctl_userns_req when actually doing a userns_call.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-05 13:16:14 +03:00
Andrew Vagin
a973e6fcb3 net: dump ipv6 routes
"ip route dump" dumps only ipv4 routes.

Reported-by: Ross Boucher <boucher@gmail.com>
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-05 13:11:31 +03:00
Pavel Emelyanov
e3f5ba3c37 ns: Prepare namespaces before tasks
There's already two things we do in criu namespaces before
forking the init task (start unsd and keep netnsfd for back
reference). Next patches will introduce the 3rd action for
mount namespaces, so have a special pre-call for all this
stuff.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-28 21:56:26 +03:00
Andrew Vagin
1a9f0b852b net: handle old or new images where a number of sysctls is differ
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-24 13:14:32 +03:00
Pavel Emelyanov
9353051ba7 ns: Check ns type with type field
Actually make use of the ns->type field and remove all getpid()'s
and other strange/inconsistent checks.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:15:28 +03:00
Andrey Vagin
4eb0952c0e net: don't call netns_entry__free_unpacked for uninitialized pointer (v2)
If the netns image is absent, the NetnsEntry entry will not be initialized.

Currently restore from old images crashes:

Core was generated by `criu swrk 3'.
Program terminated with signal SIGSEGV, Segmentation fault.
$0  0x0000000000427d80 in netns_entry.free_unpacked ()
(gdb) bt
$0  0x0000000000427d80 in netns_entry.free_unpacked ()
$1  0x0000000000436d07 in prepare_net_ns ()
$2  0x0000000000457c78 in prepare_namespace ()
$3  0x0000000000432917 in restore_task_with_children ()
$4  0x00007fc86acfccfd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

v2: remove debugging code

Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-06-11 19:50:03 +03:00
Cyrill Gorcunov
53bbea7358 Subject: net: Don't fail on missing icmp entries
icmp entries are missing on 3.10 kernel
(which is PCS7 default one) so we should
simply skip them on dump and restore.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-12 15:59:05 +03:00
Cyrill Gorcunov
121e0b906f sysctl: Make CTL_READ nonfatal
Some entries might be missing and that should not cause
CRIU to stop dumping when we know the entries are safe
to unuse.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-12 15:58:58 +03:00
Cyrill Gorcunov
9b0746572e net: Drop @ri test but use known ARRA_SIZE
We might miss entry in "ri ? ri - 1" expression when ri = 1.
Lets use known array size instead.

For some reason it didn't trigger on my tests earlier.

Reported-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 22:28:28 +03:00
Cyrill Gorcunov
0f857e0d5f net: Make @devconfs static
It is not used outside of net.c

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 14:14:30 +03:00
Cyrill Gorcunov
549998b118 sysctl: Pass number of requests in argument
This saves memory.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 14:14:24 +03:00
Cyrill Gorcunov
c8154faf2c net: Use snprintf instead of sprintf
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-05 14:14:01 +03:00
Oleg Nesterov
745f845fa8 revert 246367e4e4 "add walk_all flag to walk_namespaces"
We no longer need to populate ext_ns->mnt.mntinfo_list until
resolve_external_mounts(). We can rely on find_ext_ns_id() which
does collect_mntinfo() on demand.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Tested-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-14 22:34:40 +03:00
Pavel Tikhomirov
dfa96b5514 netdevconf: remove redundant and unsafe check
we don't need this check as just after it we have:
if (ret)
	break;
which safely unpackes nde, and closes nlsk and img in case of error

ps: sorry for inconveniences caused by my patchset
Signed-off-by: Pavel Tikhomirov <ptikhomirov@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-10 13:41:18 +03:00
Pavel Emelyanov
b87ae730fc netdev: Fix detection of device conf restore failure
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 23:14:18 +03:00
Pavel Tikhomirov
0c2e889005 optimization: do not restore configs for devices if value is default
because namespace default options are set before devices creation,
devices will gain default options(except lo, which is created with ns).

Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:22 +03:00
Pavel Tikhomirov
e4f62b85cc restore net device ipv4 confs
Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:21 +03:00
Pavel Tikhomirov
590073fc55 restore netns ipv4 conf all/default
restore order:
1. default
2. all
3. devices

Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:20 +03:00
Pavel Tikhomirov
0158e30001 dump netns ipv4 conf all/default
Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:20 +03:00
Pavel Tikhomirov
72b42d485f save net device confs bunched with criu sysctl API
Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:19 +03:00
Pavel Tikhomirov
e700fe93f6 add devconfs array to store config options names
Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 18:59:18 +03:00
Tycho Andersen
246367e4e4 add walk_all flag to walk_namespaces
In the rest of this series we need to walk all the namespaces to autodetect
which mounts are master/shared/private bind mounts, so we need the information
from criu's namespace in the case when the namespaces are not the same.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-09 12:53:19 +03:00
Andrey Vagin
4dbc3f093a sockets: define NETLINK_SOCK_DIAG in sockets.h
sockets.c: In function ‘preload_socket_modules’:
sockets.c:153:36: error: ‘NETLINK_SOCK_DIAG’ undeclared (first use in this function)
sockets.c:153:36: note: each undeclared identifier is reported only once for each function it appears in

Reported-by: Mr Travis
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-23 15:40:02 +03:00
Pavel Emelyanov
674df19a34 nlk: Add error callback to do_rtnl_req
In the next patch we will need to care about the exact error reported by
the kernel, so add the error callback for this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-22 18:54:37 +03:00
Saied Kazemi
296129295a Allow the veth-pair option to specify a bridge
When restoring a pair of veth devices that had one end inside a namespace
or container and the other end outside, CRIU creates a new veth pair,
puts one end in the namespace/container, and names the other end from
what's specified in the --veth-pair IN=OUT command line option.

This patch allows for appending a bridge name to the OUT string in the
form of OUT@<BRIDGE-NAME> in order for CRIU to move the outside veth to
the named bridge.  For example, --veth-pair eth0=veth1@br0 tells CRIU
to name the peer of eth0 veth1 and move it to bridge br0.

This is a simple and handy extension of the --veth-pair option that
obviates the need for an action script although one can still do the same
(and possibly more) if they prefer to use action scripts.

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-12 14:54:18 +03:00
Pavel Emelyanov
2d3fa5e7d0 net: Use ns walking helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-14 18:01:38 +04:00
Pavel Emelyanov
aeb3f547f7 net: Move NETLINK_INET_DIAG from socket.c to net.c
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-02 14:48:28 +04:00
Pavel Emelyanov
c57c2cfa64 predump: Collect mnt and net namespaces properly
On pre-dump we collect only two namespaces -- the mnt one
for criu and mnt one again for root task.

This is not correct. We need all mount namespaces to make
the irmap generation work properly and we need all net
namespaces to have parasite sockets created.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-02 14:30:31 +04:00
Pavel Emelyanov
45fd143409 parasite: Precreate daemon control sockets
Now we have netns on pstree-item and have the place
where to pre-create daemon socket in needed namespace.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:35:26 +04:00
Pavel Emelyanov
3c7d01f6a7 net: Pre-create nl diag sk
The setns() syscall (called by switch_ns()) can be extremely
slow. If we call it two or more times from the same task the
kernel will synchonously go on a very slow routine called
synchronize_rcu() trying to put a reference on old namespaces.

To avoid doing this more than once I propose to create all
per-ns sockets in one place with one setns call. In this
patch there's on nl diag socket used to collect other sockets
is created this way.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:34:29 +04:00
Pavel Emelyanov
4f9acb6a7c net: Do walk net namespaces to collect
Right now we don't support multiple net namespaces,
but some day we will. Other than this we have a logic
to distinguish cases with no namespaces vs one namespace,
so this walking already makes sence.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:34:05 +04:00
Pavel Emelyanov
7327ffe6a7 ns: Introduce collect_net_namespaces
And move sockets collection there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:33:56 +04:00