2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 21:38:16 +00:00

criu: Initialize util before service worker starts

When restoring dumps in new mount + pid namespaces where multiple dumps
share the same network namespace, CRIU may fail due to conflicting
unix socket names. This happens because the service worker creates
sockets using a pattern that includes criu_run_id, but util_init()
is called after cr_service_work() starts.

The socket naming pattern "crtools-fd-%d-%d" uses the restore PID
and criu_run_id, however criu_run_id is always 0 when not initialized,
leading to conflicts when multiple restores run simultaneously either
in the same CRIU process or because of multiple CRIU processes
doing the same operation in different PID namespaces.

Fix this by:

- Moving util_init() before cr_service_work() starts
- Adding a second util_init() call in the service worker fork
to ensure unique IDs across multiple worker runs
- Making sure that dump and restore operations have util_init() called
early to generate unique socket names

With this fix, socket names always include the namespace ID, preventing
conflicts when multiple processes with the same pid share a network
namespace.

Fixes #2499

[ avagin: minore code changes ]

Signed-off-by: Lorenzo Fontana <fontanalorenz@gmail.com>
Signed-off-by: Andrei Vagin <avagin@google.com>
This commit is contained in:
Lorenzo Fontana 2024-10-18 18:51:18 +02:00 committed by Andrei Vagin
parent 9052ef93c7
commit 622b43392f
2 changed files with 15 additions and 3 deletions

View File

@ -1310,6 +1310,14 @@ int cr_service_work(int sk)
int ret = -1;
CriuReq *msg = 0;
/*
* util_init initializes criu_run_id and compel_run_id so that sockets
* are generated with an unique name identifying the specific process
* even in cases where multiple processes with the same pid in
* different pid namespaces are sharing the same network namespace.
*/
util_init();
more:
opts.mode = CR_SWRK;

View File

@ -169,7 +169,13 @@ int main(int argc, char *argv[], char *envp[])
pr_err("unknown command: %s\n", argv[optind]);
goto usage;
}
/*
* util_init initializes criu_run_id and compel_run_id so that sockets
* are generated with an unique name identifying the specific process
* even in cases where multiple processes with the same pid in
* different pid namespaces are sharing the same network namespace.
*/
util_init();
if (opts.mode == CR_SWRK) {
if (argc != optind + 2) {
fprintf(stderr, "Usage: criu swrk <fd>\n");
@ -254,8 +260,6 @@ int main(int argc, char *argv[], char *envp[])
return 1;
}
util_init();
if (log_init(opts.output))
return 1;