2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-28 12:57:57 +00:00

19 Commits

Author SHA1 Message Date
Andrew Vagin
a1457a7b73 sysctl: restore sysctls for correct namespaces
When we don't use userns, __userns_sysctl_op is called
in context of the current process. A mount namespaces is restored
the last one, so when we restore namespaces, we see /proc from the
host pid namespace. In this case we can't use virtual pid to access
/proc/pid.

Let's open /proc/self/ns and use this descriptor to switch namespaces.

Cc: Tycho Andersen <tycho.andersen@canonical.com>
Fixes: f79f4546cfc0 ("sysctl: move sysctl calls to usernsd")
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-09 18:25:35 +03:00
Andrew Vagin
c7bc365530 sysctl: add the "fallthrough" annotation
CID 152112 (#1 of 1): Missing break in switch (MISSING_BREAK)
unterminated_case: The case for value 4 is not terminated by a 'break' statement.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 15:16:03 +03:00
Kir Kolyshkin
bf607a6ea8 sysctl_op(): fix check for known ns mask
This must be boolean not logical NOT.

Reported by Coverity, CID 114612.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:57:09 +03:00
Kir Kolyshkin
7073009b5d __userns_sysctl_op(): fix a check
This is obviously a copy-paste typo.

Reported by Coverity, CID 114615.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-07 14:57:02 +03:00
Andrew Vagin
fd8e58841a restore: block SIGCHILD for sub-processes (v2)
Otherwise sigchld_handler() will call waitpid()
and worries about unknown process.

(00.333012)      1: kernel/hostname nr 15
(00.333120)      1: kernel/domainname nr 6
(00.335243)      1: Error (cr-restore.c:1225): BUG at cr-restore.c:1225

v2: don't use unitialized oldmask

Cc: Tycho Andersen <tycho.andersen@canonical.com>
Reported-by: Mr Jenkins
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-10-05 19:41:33 +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
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
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
Pavel Emelyanov
1bbc994ccf sysctl: Remove dead CTL_PRINT|_SHOW code
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-27 16:18:27 +03:00
Pavel Tikhomirov
ffe3d5cfda add int(CTL_32)
Signed-off-by: Pavel Tikhomirov <ptikhomirov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 19:23:24 +04:00
Andrey Vagin
edca5ab0af sysctl: don't write '\0' at the end of buffer in a sysctl file
It isn't required. The kernel has a bug in handling auto_msgmni and
if we send extra symbols, a new value isn't applied.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-14 12:21:48 +04:00
Andrey Vagin
6705051282 syscall: don't use pr_info to print a part of string
Before:
(00.009468)     87: sysctl: <kernel/sem> = <(00.009475)     87: 2108913153 (00.009481)     87: 1252387386 (00.009486)     87: 835139248 (00.009491)     87: 320896030 (00.009496)     87: >
After:
(00.009468)     87: sysctl: <kernel/sem> = <2108913153 1252387386 835139248 320896030 >

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-14 12:20:36 +04:00
Cyrill Gorcunov
f6303de7ca sysctl: Don't forget to close fds
In case if openat/open call returned fd = 0,
don't forget to close it on routine exit,
ie just use close_safe macro.

Not a big deal since the descriptors get closed
once program finish execution but still.

#CID 996183 Resource leak

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-04-05 08:23:17 +04:00
Alexander Kartashov
3c16edc0bd cr: generalized format strings
This patch replaces the format specifier %ld with PRIx64
in the following places:

* the format string argument of the functions scanf() and printf(),
* in the macros GEN_SYSCTL_*_FUNC.

We need explicit specification of the integer size there.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-16 19:20:08 +04:00
Andrey Vagin
f8a1207927 sysctl: zero is a valid number for a file descriptor
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-10 15:22:16 +04:00
Alexander Kartashov
6f61488f21 x86: moved x86-specific files into the directory arch/x86.
* The following files goes into the directory arch/x86/include/asm unmodified:
  - include/atomic.h,
  - include/linkage.h,
  - include/memcpy_64.h,
  - include/types.h,
  - include/bitops.h,
  - pie/parasite-head-x86-64.S,
  - include/processor-flags.h,
  - include/syscall-x86-64.def.

* Changed include directives in the source files that include the headers
  listed above.

* Modified build scripts to reflect the source moves.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-01-09 17:02:47 +04:00
Stanislav Kinsbursky
41195598cf parasite: remove excessive header deps from parasite.h and friends
The task is not complete - this is just a part of what have to be done. I.e.
looks like a lot of excessive deps can be fixed.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-30 12:50:18 +04:00
Cyrill Gorcunov
827cabb480 show: Use pr_msg for showing contents on console
Due to code sharing, especially in IPC area,
the unbinding is done via helper macros and
sysclt engine tuning (new CTL_SHOW action
added).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-03-02 11:12:59 +04:00
Cyrill Gorcunov
405985e964 Add sysctl handling engine
Since we need to operate with sysctls pretty heavy,
better to add some common engine for all handlers.

Based-on-patch-from: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
2012-02-02 21:22:20 +04:00