From 622b43392fcb330343243a0f2842dd2919f977cc Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Fri, 18 Oct 2024 18:51:18 +0200 Subject: [PATCH] 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 Signed-off-by: Andrei Vagin --- criu/cr-service.c | 8 ++++++++ criu/crtools.c | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/criu/cr-service.c b/criu/cr-service.c index 61a04c5ff..b9d11ced2 100644 --- a/criu/cr-service.c +++ b/criu/cr-service.c @@ -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; diff --git a/criu/crtools.c b/criu/crtools.c index 94657f418..6f493850b 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -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 \n"); @@ -254,8 +260,6 @@ int main(int argc, char *argv[], char *envp[]) return 1; } - util_init(); - if (log_init(opts.output)) return 1;