Version in base suite: 3.17.1-2 Base version: criu_3.17.1-2 Target version: criu_3.17.1-2+deb12u1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/c/criu/criu_3.17.1-2.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/c/criu/criu_3.17.1-2+deb12u1.dsc changelog | 7 patches/cr-restore-rseq-dynamically-handle-libc-with-rseq.patch | 151 ++++++++++ patches/cr-restore-rseq-use-glibc-specific-way-to-unregister.patch | 61 ++++ patches/series | 2 4 files changed, 221 insertions(+) diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/compel/include/uapi/asm: No such file or directory diff: /srv/release.debian.org/tmp/CB2ws58gKz/criu-3.17.1/compel/include/uapi/asm: No such file or directory diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/compel/include/uapi/compel: recursive directory loop diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/images/google/protobuf/descriptor.proto: No such file or directory diff: /srv/release.debian.org/tmp/CB2ws58gKz/criu-3.17.1/images/google/protobuf/descriptor.proto: No such file or directory diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/test/others/unix-callback/lib/syslog-lib.so: No such file or directory diff: /srv/release.debian.org/tmp/CB2ws58gKz/criu-3.17.1/test/others/unix-callback/lib/syslog-lib.so: No such file or directory diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/test/others/unix-callback/lib/unix-lib.so: No such file or directory diff: /srv/release.debian.org/tmp/CB2ws58gKz/criu-3.17.1/test/others/unix-callback/lib/unix-lib.so: No such file or directory diff: /srv/release.debian.org/tmp/KmdS_oUvPU/criu-3.17.1/test/zdtm/static/lib/criu-rtc.so: No such file or directory diff: /srv/release.debian.org/tmp/CB2ws58gKz/criu-3.17.1/test/zdtm/static/lib/criu-rtc.so: No such file or directory diff -Nru criu-3.17.1/debian/changelog criu-3.17.1/debian/changelog --- criu-3.17.1/debian/changelog 2022-12-20 21:00:51.000000000 +0000 +++ criu-3.17.1/debian/changelog 2024-11-20 12:16:31.000000000 +0000 @@ -1,3 +1,10 @@ +criu (3.17.1-2+deb12u1) bookworm; urgency=medium + + * cr-restore: rseq: dynamically handle *libc with rseq (Closes: #1081683) + * cr-restore: rseq: use glibc-specific way to unregister only as fallback + + -- Salvatore Bonaccorso Wed, 20 Nov 2024 13:16:31 +0100 + criu (3.17.1-2) unstable; urgency=medium * criu: fix conflicting headers (Closes: #1026534) diff -Nru criu-3.17.1/debian/patches/cr-restore-rseq-dynamically-handle-libc-with-rseq.patch criu-3.17.1/debian/patches/cr-restore-rseq-dynamically-handle-libc-with-rseq.patch --- criu-3.17.1/debian/patches/cr-restore-rseq-dynamically-handle-libc-with-rseq.patch 1970-01-01 00:00:00.000000000 +0000 +++ criu-3.17.1/debian/patches/cr-restore-rseq-dynamically-handle-libc-with-rseq.patch 2024-11-20 12:16:31.000000000 +0000 @@ -0,0 +1,151 @@ +From cacddf19dad339f963b0b01f7174091b90c49e5d Mon Sep 17 00:00:00 2001 +From: Alexander Mikhalitsyn +Date: Wed, 20 Jul 2022 14:36:28 +0300 +Subject: [PATCH] cr-restore: rseq: dynamically handle *libc with rseq + +Before this patch we assumed that CRIU is compiled against +the same GLibc as it runs with. But as we see from real +world examples like #1935 it's not always true. + +The idea of this patch is to detect rseq configuration +for the main CRIU process and use it to unregister +rseq for all further child processes. It's correct, +because we restore pstree using clone*() syscalls, +don't use exec*() (!) syscalls, so rseq gets inherited +in the kernel and rseq configuration remains the same +for all children processes. + +This will prevent issues like this: +https://github.com/checkpoint-restore/criu/issues/1935 + +Suggested-by: Florian Weimer +Signed-off-by: Alexander Mikhalitsyn +--- + criu/cr-restore.c | 16 ++++++++-------- + criu/include/kerndat.h | 2 ++ + criu/kerndat.c | 25 +++++++++++++++++++++++-- + 3 files changed, 33 insertions(+), 10 deletions(-) + +diff --git a/criu/cr-restore.c b/criu/cr-restore.c +index d11d28173a63..5b5b41dfc8bd 100644 +--- a/criu/cr-restore.c ++++ b/criu/cr-restore.c +@@ -3103,14 +3103,14 @@ static void prep_libc_rseq_info(struct rst_rseq_param *rseq) + #else + static void prep_libc_rseq_info(struct rst_rseq_param *rseq) + { +- /* +- * TODO: handle built-in rseq on other libc'ies like musl +- * We can do that using get_rseq_conf kernel feature. +- * +- * For now we just assume that other libc libraries are +- * not registering rseq by default. +- */ +- rseq->rseq_abi_pointer = 0; ++ if (!kdat.has_rseq || !kdat.has_ptrace_get_rseq_conf) { ++ rseq->rseq_abi_pointer = 0; ++ return; ++ } ++ ++ rseq->rseq_abi_pointer = kdat.libc_rseq_conf.rseq_abi_pointer; ++ rseq->rseq_abi_size = kdat.libc_rseq_conf.rseq_abi_size; ++ rseq->signature = kdat.libc_rseq_conf.signature; + } + #endif + +diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h +index 83d867e75bab..a3959c99260d 100644 +--- a/criu/include/kerndat.h ++++ b/criu/include/kerndat.h +@@ -7,6 +7,7 @@ + #include "asm/kerndat.h" + #include "util-vdso.h" + #include "hugetlb.h" ++#include + + struct stat; + +@@ -82,6 +83,7 @@ struct kerndat_s { + bool has_openat2; + bool has_rseq; + bool has_ptrace_get_rseq_conf; ++ struct __ptrace_rseq_configuration libc_rseq_conf; + }; + + extern struct kerndat_s kdat; +diff --git a/criu/kerndat.c b/criu/kerndat.c +index bc5dccab1804..0f7d5fc8fb1d 100644 +--- a/criu/kerndat.c ++++ b/criu/kerndat.c +@@ -923,6 +923,7 @@ static int kerndat_has_ptrace_get_rseq_conf(void) + pid_t pid; + int len; + struct __ptrace_rseq_configuration rseq; ++ int ret = 0; + + pid = fork_and_ptrace_attach(NULL); + if (pid < 0) +@@ -930,6 +931,9 @@ static int kerndat_has_ptrace_get_rseq_conf(void) + + len = ptrace(PTRACE_GET_RSEQ_CONFIGURATION, pid, sizeof(rseq), &rseq); + if (len != sizeof(rseq)) { ++ if (kdat.has_ptrace_get_rseq_conf) ++ ret = 1; /* we should update kdat */ ++ + kdat.has_ptrace_get_rseq_conf = false; + pr_info("ptrace(PTRACE_GET_RSEQ_CONFIGURATION) is not supported\n"); + goto out; +@@ -940,16 +944,27 @@ static int kerndat_has_ptrace_get_rseq_conf(void) + * we need to pay attention to that and, possibly, make changes on the CRIU side. + */ + if (rseq.flags != 0) { ++ if (kdat.has_ptrace_get_rseq_conf) ++ ret = 1; /* we should update kdat */ ++ + kdat.has_ptrace_get_rseq_conf = false; + pr_err("ptrace(PTRACE_GET_RSEQ_CONFIGURATION): rseq.flags != 0\n"); + } else { ++ if (!kdat.has_ptrace_get_rseq_conf) ++ ret = 1; /* we should update kdat */ ++ + kdat.has_ptrace_get_rseq_conf = true; ++ ++ if (memcmp(&kdat.libc_rseq_conf, &rseq, sizeof(rseq))) ++ ret = 1; /* we should update kdat */ ++ ++ kdat.libc_rseq_conf = rseq; + } + + out: + kill(pid, SIGKILL); + waitpid(pid, NULL, 0); +- return 0; ++ return ret; + } + + int kerndat_sockopt_buf_lock(void) +@@ -1472,6 +1487,12 @@ int kerndat_try_load_new(void) + if (ret < 0) + return ret; + ++ ret = kerndat_has_ptrace_get_rseq_conf(); ++ if (ret < 0) { ++ pr_err("kerndat_has_ptrace_get_rseq_conf failed when initializing kerndat.\n"); ++ return ret; ++ } ++ + /* New information is found, we need to save to the cache */ + if (ret) + kerndat_save_cache(); +@@ -1657,7 +1678,7 @@ int kerndat_init(void) + pr_err("kerndat_has_rseq failed when initializing kerndat.\n"); + ret = -1; + } +- if (!ret && kerndat_has_ptrace_get_rseq_conf()) { ++ if (!ret && (kerndat_has_ptrace_get_rseq_conf() < 0)) { + pr_err("kerndat_has_ptrace_get_rseq_conf failed when initializing kerndat.\n"); + ret = -1; + } +-- +2.45.2 + diff -Nru criu-3.17.1/debian/patches/cr-restore-rseq-use-glibc-specific-way-to-unregister.patch criu-3.17.1/debian/patches/cr-restore-rseq-use-glibc-specific-way-to-unregister.patch --- criu-3.17.1/debian/patches/cr-restore-rseq-use-glibc-specific-way-to-unregister.patch 1970-01-01 00:00:00.000000000 +0000 +++ criu-3.17.1/debian/patches/cr-restore-rseq-use-glibc-specific-way-to-unregister.patch 2024-11-20 12:16:31.000000000 +0000 @@ -0,0 +1,61 @@ +From f7972a3f0468e32231af6914e2e9c9e07ac53ae6 Mon Sep 17 00:00:00 2001 +From: Alexander Mikhalitsyn +Date: Wed, 20 Jul 2022 15:17:35 +0300 +Subject: [PATCH] cr-restore: rseq: use glibc-specific way to unregister only + as fallback + +Let's use dynamic approach to detect built-in *libc rseq in all cases, +and "old" static approach as a fallback path if the user kernel +lacks support of ptrace_get_rseq_conf feature. + +Suggested-by: Florian Weimer +Signed-off-by: Alexander Mikhalitsyn +--- + criu/cr-restore.c | 15 ++++++--------- + 1 file changed, 6 insertions(+), 9 deletions(-) + +diff --git a/criu/cr-restore.c b/criu/cr-restore.c +index 5b5b41dfc8bd..919d10ab57b4 100644 +--- a/criu/cr-restore.c ++++ b/criu/cr-restore.c +@@ -3088,7 +3088,6 @@ static int prep_rseq(struct rst_rseq_param *rseq, ThreadCoreEntry *tc) + return 0; + } + +-#if defined(__GLIBC__) && defined(RSEQ_SIG) + static void prep_libc_rseq_info(struct rst_rseq_param *rseq) + { + if (!kdat.has_rseq) { +@@ -3096,15 +3095,14 @@ static void prep_libc_rseq_info(struct rst_rseq_param *rseq) + return; + } + +- rseq->rseq_abi_pointer = encode_pointer(__criu_thread_pointer() + __rseq_offset); +- rseq->rseq_abi_size = __rseq_size; +- rseq->signature = RSEQ_SIG; +-} ++ if (!kdat.has_ptrace_get_rseq_conf) { ++#if defined(__GLIBC__) && defined(RSEQ_SIG) ++ rseq->rseq_abi_pointer = encode_pointer(__criu_thread_pointer() + __rseq_offset); ++ rseq->rseq_abi_size = __rseq_size; ++ rseq->signature = RSEQ_SIG; + #else +-static void prep_libc_rseq_info(struct rst_rseq_param *rseq) +-{ +- if (!kdat.has_rseq || !kdat.has_ptrace_get_rseq_conf) { + rseq->rseq_abi_pointer = 0; ++#endif + return; + } + +@@ -3112,7 +3110,6 @@ static void prep_libc_rseq_info(struct rst_rseq_param *rseq) + rseq->rseq_abi_size = kdat.libc_rseq_conf.rseq_abi_size; + rseq->signature = kdat.libc_rseq_conf.signature; + } +-#endif + + static rlim_t decode_rlim(rlim_t ival) + { +-- +2.45.2 + diff -Nru criu-3.17.1/debian/patches/series criu-3.17.1/debian/patches/series --- criu-3.17.1/debian/patches/series 2022-12-20 21:00:51.000000000 +0000 +++ criu-3.17.1/debian/patches/series 2024-11-20 12:16:31.000000000 +0000 @@ -1,2 +1,4 @@ criu-fix-conflicting-headers.patch mount-add-definition-for-FSOPEN_CLOEXEC.patch +cr-restore-rseq-dynamically-handle-libc-with-rseq.patch +cr-restore-rseq-use-glibc-specific-way-to-unregister.patch