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

9635 Commits

Author SHA1 Message Date
Veronika Kabatova
dd348bd60a Add support for configuration files
Implementation changes for usage of simple configuration files. Before
parsing the command line options, either default configuration files
(/etc/criu/default.conf, $HOME/.criu/default.conf; in this order) are
parsed, or a specific config file passed by the user. Two new options are
introduced: "--config FILEPATH" option allows users to specify a single
configuration file they want to use; and "--no-default-config" option to
forbid the parsing of default configuration files. Both options are to be
passed only via the command line.

Usage of configuration files is not mandatory to keep backwards
compatibility. The implementation of this feature tries to be compatible
with command line usage -- the user should get the same results whether
he passes the options (in the right order of parsing) on command line or
writes them in config files. This allows the user to:

1) Override boolean options if needed
2) Specify partial configuration for options that are possible to pass
   several times (e.g. "--external"), and pass the rest of the options
   based on process runtime by command line

Configuration file syntax allows comments marked with '#' sign, the rest
of the line after '#' is ignored. The user can use one option per line
(with argument supplied on the same line if needed, divided with whitespace
characters), the options are the same as long options (without the "--"
prefix used on command line).

Configuration file example (syntax purposes only, doesn't make sense):

$ cat ~/.criu/default.conf
tcp-established
work-dir /home/<USERNAME>/criu/work_directory
extra # inline comment
no-restore-sibling
tree	111111

Signed-off-by: Veronika Kabatova <vkabatov@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Michael Holzheu
7e01425766 s390: Fix clone() syscall parameters for s390
On s390 the first two paramters are swapped because we use
the CONFIG_CLONE_BACKWARDS2 kernel config option.

Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Kirill Tkhai
3c712e280b pstree: Do not populate zero levels of task's pid
If task's pid were hashed before the task itself
(this may happen, when another task has sid or pgid
equal to this pid), the pid mustn't contain zero
levels. So, if pgid or sid has zero levels, we should
not add them.

Otherwise, session04 --iter 3 fails with:

=[log]=> dump/zdtm/static/session04/30/2/restore.log
------------------------ grep Error ------------------------
(01.858187)      6: Restoring children in our session:
(01.858206)      6: Forking task with 303 pid (flags 0x600)
(01.869893)      1: PID: real 145 virt 15
(01.870247)      1: Forking task with 20 pid (flags 0x0)
(01.872948) Error (criu/cr-restore.c:381): 0: Write -1 to sys/kernel/ns_last_pid: Invalid argument
(01.873030) Error (criu/namespaces.c:2664): Can't set next pid
(01.873103)      1: Error (criu/ns-common.c:46): Error answer
(01.873123)      1: Error (criu/cr-restore.c:404): Can't request next pid
(01.873135)      1: Error (criu/cr-restore.c:1321): Can't set next pid
(01.873310)      1: Error (criu/cr-restore.c:1434): Can't fork for 20: No such file or directory

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Acked-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Mike Rapoport
0aa9cc3641 pstree: fix prepare_dummy_pstree after rework of PID namespace
Since commit 84eedc49a (pstree: Make lookup_create_pid() able to create
tasks with pid->level > 1) the read_pstree_image function presumes that
namespaces image is already parsed.
This patch ensures that this is the case for prepare_dummy_pstree users.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Kirill Tkhai
627ca7d13d zdtm: Add SIGCHLD flag to userns-leaked-sock test
wait() waits children created using SIGCHLD signal only.
Add it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Pavel Emelyanov
181ea542e3 net: Fix links collection retcode
There's a

   if (bad_thing) {
	   ret = -1;
	   break;
   }

code above this hunk, whose intention is to propagate -1 back to
caller. This propagation is obviously broken.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Dmitry Safonov
7d5ac8338d zdtm: Add infop to waitid() in pidns0{2,3}
As said in man page:
> The application shall ensure that the infop argument
> points to a siginfo_t structure.

While x86_64 ignores NULL, ia32 syscall returns error:
Test output: ================================
20:52:47.176:     4: FAIL: pidns02.c:158: Can't wait (errno = 14 (Bad address))
20:52:47.177:     4: FAIL: pidns02.c:183: Test failed (errno = 14 (Bad address))
20:52:47.177:     3: ERR: test.c:228: Test exited unexpectedly with code 255
 <<< ================================

Test output: ================================
20:53:27.835:     1: FAIL: pidns03.c:119: Can't wait (errno = 14 (Bad address))
20:53:28.207:     4: FAIL: pidns03.c:201: Can't wait or bad status: errno=0, status=32512 (errno = 0 (Success))
 <<< ================================

Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Kirill Tkhai
8df85f8c51 compel, x86_64: Fix sys_clone() definition
Commit 37e4c7bfc264 fixed arm, ppc, x86 (32bit),
while it made wrong definition of x86_64. Fix that.

Also, add commentary to raw fork() implementation.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Andrei Vagin
bbb9ed6096 restore: handle errors of restore_wait_other_tasks
In a error case, task_entries->nr_in_progress is set to -1
and we have to handle this case.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:44 +03:00
Adrian Reber
4864af0d91 zdtm: also dump and restore tests with --check-only
This adds the option '--check-only' to zdtm.py. If specified each test
cases is first dumped with the '--check-only' option enabled before the
real dump. Also during restore the test case is first restored with
--check-only before doing the real restore.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:29:42 +03:00
Adrian Reber
bab458b0d6 zdtm: call getpid() during gone if pid is zero
If calling gone() without ever calling getpid() before leads to
backtrace. Just call getpid() to avoid that.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:57 +03:00
Adrian Reber
59d18c8028 zdtm: add reset_pid() function
In preparation for the zdtm option '--check-only' a new helper function
reset_pid() is added which writes to ns_last_pid to avoid PID collisions
during check-only restore and the real restore.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:57 +03:00
Adrian Reber
bad73c629a restorer: skip aio restore in check-only mode
Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:57 +03:00
Adrian Reber
1e03c8a25b check-only: fix network unlock in check-only mode
Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:57 +03:00
Kirill Tkhai
cd16b9c687 zdtm: Add userns-leaked-sock test
1)Create a socket, bind it, then create a child in lower user, pid and net ns.
2)Close socket in parent
3)After signal, check that child can create the socket with the same name.
  (It must, as it's in another net namespace).

v2: Add uid/gid mapping.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
693e643358 user_ns: Prepare creds of newly created task
Sockets are sent via SCM_CREDENTIALS, and this kernel interface
needs to have uid and gid mapped (see __scm_send() in kernel).
So, set them before send_fds() use.

Also, move prep_usernsd_transport() below to be after this
for uniformity.

v2: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
373f9327f9 files: Add new master to file_desc if owners of existing fles have no permissions
Iterate over fake_master_head and add a fake fake fle of root_item,
which becomes new master and have permissions to restore file_desc.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
f03848309c files: Choose file master with enough permissions
On Thu, Jun 15, 2017 at 12:16, Cyrill Gorcunov wrote:
> On Thu, Jun 15, 2017 at 12:10:43PM +0300, Kirill Tkhai wrote:
> > On Wed, Jun 14, 2017 at 23:32, Andrei Vagin wrote:
> > > On Wed, Jun 07, 2017 at 02:28:53PM +0300, Kirill Tkhai wrote:
> > > > 1)Find such fle, and link it at the beginning of list.
> > > > 2)Order by pid, where possible, if it does not contradict (1)
> > >
> > > Why do we need to order by pid?
> >
> > This was initially, and I left the logic. As I know,
> > it's need for epoll, to place master in parent task.
> >
> > CC: gorcunov@virtuozzo.com
> > Cyrill, could you please say, why we need this, if you remember?
>
> I think it's the same as in bug we met.
> ---
> commit 2df9c9dc6e0b926aaba00138e3e66295ebea76ce
> Author: Cyrill Gorcunov <gorcunov@virtuozzo.com>
> Date:   Mon Apr 3 18:38:55 2017 +0300
>
>     vz7: files -- Select proper master fd when collecting fd
>
>     When choosing the master file which gonna be sending file
>     descriptor to the children we must not only look into
>     their PIDs but consider process tree relations, in particular
>     the child of a process might be choosen as a master and
>     epoll restore will fail because target files are simply
>     not present in child tree.
>
>     |  31964  31964  31964       epoll
>     |    585  31964  31964           epoll
>     |    586  31964  31964           epoll
>     |...
>     | (04.797121)    585: Error (criu/eventpoll.c:180): epoll: Unexpected state for tfd (id 0 fd 8)
>
>     That's because the target files are blong to 31964 and not
>     present in child 585, but because PID wrapp happened it
>     has been chosen as a leader which is of course wrong.
>
>     https://jira.sw.ru/browse/PSBM-63355
>
>     Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>

[PATCH v3 18/30]files: Choose file master with enough permissions

1)Find such fle, and link it at the beginning of list.
2)Order by pid, where possible, if it does not contradict (1)
3)If there is no a master, leave fdesc in fake_master_head.

v3: Describe pid order reasons

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
80c0c63b41 files: Populate file_desc::setns_userns
Do it here once to use cached value later.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
eecdaebaee net: Add file_desc_ops::get_user_ns for sockets
Return user_ns of saved net ns_id.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
ecd57e0a3c files: Add file_desc_ops::get_user_ns
Returns user_ns of file (currently it's not exported to userspace)
and minimal user_ns need for restore file (for example, socket
net_ns->user_ns, regulating setns() permittions).

This will be need to choose correct process as owner of file master.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
4eb718553a ns: Refactor top_user_ns assignment
The aim is to have top_user_ns set even if !(root_ns_mask & CLONE_NEWUSER).
This allows to avoid additional comparison top_user_ns with NULL elsewhere.

Thus, move fixup for old images to generic code, to support the case above.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
eb31ccc167 ns: Rename root_user_ns to top_user_ns
I'm going to use this in !(root_ns_mask & CLONE_NEWUSER) case,
so choose a better name to fit everything.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
b8ca87fca9 net: Fixup net ns_id of sockets on old dumps
Set them equal to top_net_ns.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
625e7f9c2a ns: Add top_net_ns global variable
It will be need for fast obtaining root_item's net_ns,
and to fixup old dumps.

v2: Add a comment to top_xxx_ns. Extend MARK_ROOT_NS().

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
91b85145c0 utils: Use daemon in open_fd_of_vpid() only its really need
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
a5483337b3 utils: Cleanup open_fd_of_vpid()
Move +1 up to snprintf().

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
1349c6439c utils: Change open_fd_of_real_pid() to be open_fd_of_vpid()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
320dba091a shmem: Move pr_info to open_fd_of_real_pid()
Just to not allocate path buffer twice.

v2: Change debug message.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
02fcb99c39 zdtm: Add SIGCHLD to clone flags in pidns01
Plain wait() waits only children created with SIGCHLD flag.
Add it.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Andrei Vagin
d8d3d8d81f zdtm: pidns03: Wait till child dead
Wait child before daemonization to do not allow
zdtm.py to see child fds and maps before it
becomes zombie.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
662ca6ba95 zdtm: pidns02: Wait till child dead
Wait child before daemonization to do not allow
zdtm.py to see child fds and maps before it
becomes zombie.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
5bd29333cf ns: Add can_access_userns() helper
Returns true if argument is the same user_ns as current has,
or it's our descendant.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
8f37c6291f pid_ns: Make add_child_task() working with last_level_pid()
The original idea was to sort children and to keep child
reapers at the beginning of the list. But there a mistake
happened: we must look for last_level_pid() as it is
an indicator of a child_reaper.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Kirill Tkhai
83134eecc4 pre_dump: Assign parasite pid only if it hasn't collected yet
Parasite returns last level pid (pid in task's pid namespace),
so we mustn't rewrite already collected from /proc/[pid]/status
vpid.

We handle that correctly on dump, do the same on pre-dump.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
0020399593 zdtm: test for new init reparent handling with tricky setns
Session 15's(20) leader is in first pidns, one it's process is in
second pidns and one is
in the third. So we create two helpers here for each aditional
pidns.

(It is critical that

Full test now looks like (mind pids here are different(real) from
their id's in source code e.g. 15 is 20 here):
      (pid,ppid,sid)
session04(1, 0, 1)───session04(4, 1, 4)───session04(5, 4, 4)───session04(6, 5, 6,pid1)─┬─session04(8, 6, 8)───session04(9, 8, 7)
                                                                                       ├─session04(10, 6, 6)───session04(11, 10, 11)
                                                                                       ├─session04(13, 6, 13)───session04(14, 13, 11)
                                                                                       ├─session04(15, 6, 15)
                                                                                       ├─session04(17, 6, 17)─┬─session04(18, 17, 15)
                                                                                       │                      └─session04(19, 17, 17,pid2)───session04(22, 19, 20)
                                                                                       ├─session04(20, 6, 20)
                                                                                       └─session04(23, 6, 6,pid3)───session04(25, 23, 20)

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
55cd96cfd6 zdtm: test for new init reparent handling with nested pidns
Demand ns_pid, ns_get_userns and ns_get_parent features, else will
have "Can't do ns ioctl" error in criu:set_ns_opt().

v2:remove unused variable i in cleanup
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
1d2955c039 zdtm: add test for new init reparent handling
Before "pstree: rework init reparent handling for pid namespaces" patch
we would get:

$ ./test/zdtm.py run -t zdtm/static/session01

=== Run 1/1 ================ zdtm/static/session01

======================= Run zdtm/static/session01 in ns ========================
Start test
./session01 --pidfile=session01.pid --outfile=session01.out
Run criu dump
Run criu restore
=[log]=> dump/zdtm/static/session01/31/1/restore.log
------------------------ grep Error ------------------------
(00.001103) 8 was born with sid 4
(00.001105) 7 was born with sid 4
(00.001106) 21 was born with sid 17
(00.001108) 1 was born with sid 17
(00.001109) Error (criu/pstree.c:1005): Can't find a session leader for 17
------------------------ ERROR OVER ------------------------

Corresponding tree before dump:
(combined 'pstree -pS 1' and 'ps axf -o pid,ppid,sid')

session01(1, 0, 1)─┬─session01(3, 1, 1)───session01(4, 3, 4)─┬─session01(5, 4, 5)─┬─session01(23, 5, 5)
                   │                                         │                    ├─session01(24, 5, 5)
                   │                                         │                    └─session01(26, 5, 5)
                   │                                         ├─session01(6, 4, 4)
                   │                                         ├─session01(7, 4, 7)───session01(16, 7, 4)
                   │                                         └─session01(8, 4, 8)───session01(15, 8, 15)───session01(20, 15, 4)
                   ├─session01(12, 1, 12)───session01(17, 12, 17)───session01(18, 17, 18)───session01(27, 18, 4)
                   ├─session01(13, 1, 10)
                   ├─session01(14, 1, 4)
                   └─session01(21, 1, 21)───session01(22, 21, 17)

22 can not restore as it needs session 17, but 17-th's leader is not in
ancestors(21 had been reparented from 17; 12, 13 an 14 from 4).

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
d00e81e3b5 pstree: enable sid handling back
These checks skip adding helpers and setting ids in case
of nested pid namespaces.

FIXME disable pgid, as it does not work yet

v2: add a comment near the added check for pgid
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
b1212a1f93 pstree: rework init reparent handling for pid namespaces
- Put code into new handle_init_reparent, make it pidns relative
and call it for each pidns.

- Consider the case when process tree branch(subtree) reparented to init
(parent of root of these branch died) riping some session in two
pieces and representative of these session in reparented branch can
not inherit its session if we simply try to fork the tree as is.
Patch adds helper can_inherit_sid to find such "adopted" brunches and
re-reparent them to helpers.

Previousely we had only direct children of init handled.

- We need many helpers for one session as:

1) The leader of session, if it is already dead, can not be recreated as
a helper in arbitrary pidns. But only in pidns ancestor of pidns of
any alive process of these session (sessions processes can't leave
pidns in which the session had been created).

More over session can be created only on proper level: sid array of the
alive process can end with several zerroes, meaning that after creation
of session, processes had entered several more pidnses, so we need to
cut these extra levels before creating the leader.

2) We can not re-reparent branch directly to session leader as the latter
can be in other pidns, thus create additional helper in our init's pidns,
and it's children will reparent to init.

If parents of session processes are in multiple pidnses we will need
helper per each such pidns, to be able to re-reparent them. See test
with setns for an example

- Collect all helper processes in separate list, so that it would
be easier to find them with get_helper_by_sid for other possibly
existing pieces of these sid. Branches re-reparented to such helpers
are temporary out of the tree and also skipped from walk over items
in for_each_pssubtree_item.

- Collect zombies and helpers which will reparent to init of pidns in
collect_child_pids to init of pidns instead of root task.

- The process tree which had only reparents to pidns init process
(no child subreapers reparents) will be restored fine). One tricky case
than we need re-reparent and the session leader is in same pidns with us
and our parent is in lower pid ns will fail - it happens than somebody
enters the pidns does setsid and then does clone(CLONE_PARENT).

v2: handle get_free_pids returns 0 as error
v3: rebase due to patchwork fail - use add_child_task and move_child_task
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
f10251e66c pstree: make equal_pid handle sid comparison between nested pidnses
If process belonging to some session is in different pidns than leader
of these session, it will have zeroes on all aditional levels in sid,
so though levels for these process and leader does not match - sids do.

v2: change to static inline function as there is no more pr_err
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
6e979f6867 pstree: add is_session_leader helper and use it where possible
equal_pid(item->pid, item->sid) -> is_session_leader(item)

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
59ad51932c pstree: add helper for_each_pssubtree_item to walk item's subtree
Need it to lookup adoptive children of pidns init. Also add
skip_descendants flag to be able to skip unneeded subtrees.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:56 +03:00
Pavel Tikhomirov
f39d203588 pstree/pid: add helper to get free pids in pidns and all it's ancestors
v2: handle get_free_pids returns 0 as error, remove unneeded iter var in
get_free_pids

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
02deb233ae zdtm: Add pidns03 test
Create a child in new pid_ns; then the child creats thread and zombie.
Zombie is in the second created new pid_ns. Then the great parent
setns() to its active pid_ns. So, lets draw the table:

                    pid_ns vs pid_for_children_ns
great parent:       equal
child:              not equal
child thread:       equal
grand child zombie: zombies don't have pid_for_children_ns

After signal chech that everything remains the same.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
ecb7e5801a ns: Restore pid_for_children ns in threads
Threads may have different pid_for_children ns.
Allow them to set it after they are created:
just get a pid_ns fd from fdstore, and setns()
to it, after thread creation.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
f39a52923d ns: First stage of restore pid_for_children ns
Restore it in dependence of thread numbers:
1)single-threaded -- before user_ns assignment
2)multi-threaded -- after thread creation (in next patch).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
915c5477ac fork: Delete pid argument of set_pid_for_children_ns()
In next patches set_pid_for_children_ns() will be used
without pid, so move pid check out of function.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
54e982d553 fork: Move ns-specific code to setup_child_task_namespaces()
No functional changes -- just to improve readability.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00
Kirill Tkhai
9bd07e8668 ns: Fixup pid_for_children_ns of threads
Populate pid ns (always) and pid_for_children ns
(if it's empty, i.e., in old dumps).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-30 01:28:55 +03:00