diff --git a/glibc.spec b/glibc.spec index 3259e487ce4c5dea7e63b9bc31a2668cfced6414..1fdabe2fb8fa974eeba4081fbc6d213a3ed0fece 100644 --- a/glibc.spec +++ b/glibc.spec @@ -67,7 +67,7 @@ ############################################################################## Name: glibc Version: 2.38 -Release: 44 +Release: 45 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -248,6 +248,8 @@ Patch158: backport-elf-Move-__rtld_malloc_init_stubs-call-into-_dl_star.patch Patch159: backport-elf-Handle-static-PIE-with-non-zero-load-address-BZ-.patch Patch160: backport-elf-Introduce-_dl_relocate_object_no_relro.patch Patch161: backport-elf-Switch-to-main-malloc-after-final-ld.so-self-rel.patch +Patch162: nptl-initialize-rseq-area-prior-to-registration.patch +Patch163: nptl-initialize-cpu_id_start-prior-to-rseq-registrat.patch #openEuler patch list Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch @@ -1469,6 +1471,10 @@ fi %endif %changelog +* Sat Dec 7 2024 Qingqing Li - 2.38-45 +- nptl: initialize cpu_id_start prior to rseq registration +- nptl: initialize rseq area prior to registration + * Fri Dec 06 2024 shixuantong - 2.38-44 - elf: Handle static PIE with non-zero load address - elf: Introduce _dl_relocate_object_no_relro diff --git a/nptl-initialize-cpu_id_start-prior-to-rseq-registrat.patch b/nptl-initialize-cpu_id_start-prior-to-rseq-registrat.patch new file mode 100644 index 0000000000000000000000000000000000000000..814d0ec854d5b32af4d4735772f0f90660026648 --- /dev/null +++ b/nptl-initialize-cpu_id_start-prior-to-rseq-registrat.patch @@ -0,0 +1,34 @@ +From 37ded328c4240f5a84c69b8cb803f0652fa68d20 Mon Sep 17 00:00:00 2001 +From: Michael Jeanson +Date: Wed, 20 Nov 2024 14:15:42 -0500 +Subject: [PATCH] nptl: initialize cpu_id_start prior to rseq registration + +When adding explicit initialization of rseq fields prior to +registration, I glossed over the fact that 'cpu_id_start' is also +documented as initialized by user-space. + +While current kernels don't validate the content of this field on +registration, future ones could. + +Signed-off-by: Michael Jeanson +Reviewed-by: Mathieu Desnoyers +(cherry picked from commit d9f40387d3305d97e30a8cf8724218c42a63680a) +--- + sysdeps/unix/sysv/linux/rseq-internal.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h +index 8fd26f335e..0ad79174bd 100644 +--- a/sysdeps/unix/sysv/linux/rseq-internal.h ++++ b/sysdeps/unix/sysv/linux/rseq-internal.h +@@ -56,6 +56,7 @@ rseq_register_current_thread (struct pthread *self, bool do_rseq) + registration, there is no guarantee that struct pthread is + cleared on all architectures. */ + THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_UNINITIALIZED); ++ THREAD_SETMEM (self, rseq_area.cpu_id_start, 0); + THREAD_SETMEM (self, rseq_area.rseq_cs, 0); + THREAD_SETMEM (self, rseq_area.flags, 0); + +-- +2.27.0 + diff --git a/nptl-initialize-rseq-area-prior-to-registration.patch b/nptl-initialize-rseq-area-prior-to-registration.patch new file mode 100644 index 0000000000000000000000000000000000000000..7502c52d24bd4307e46824c77df56a67e0f0b22d --- /dev/null +++ b/nptl-initialize-rseq-area-prior-to-registration.patch @@ -0,0 +1,61 @@ +From 9423cc5387d93de63be09740bfd86abd01dca7d1 Mon Sep 17 00:00:00 2001 +From: Michael Jeanson +Date: Thu, 7 Nov 2024 22:23:49 +0100 +Subject: [PATCH] nptl: initialize rseq area prior to registration + +Per the rseq syscall documentation, 3 fields are required to be +initialized by userspace prior to registration, they are 'cpu_id', +'rseq_cs' and 'flags'. Since we have no guarantee that 'struct pthread' +is cleared on all architectures, explicitly set those 3 fields prior to +registration. + +Signed-off-by: Michael Jeanson +Reviewed-by: Florian Weimer +(cherry picked from commit 97f60abd25628425971f07e9b0e7f8eec0741235) +--- + nptl/descr.h | 2 ++ + sysdeps/unix/sysv/linux/rseq-internal.h | 10 ++++++++++ + 2 files changed, 12 insertions(+) + +diff --git a/nptl/descr.h b/nptl/descr.h +index 0171576c23..4ec2df7a26 100644 +--- a/nptl/descr.h ++++ b/nptl/descr.h +@@ -414,6 +414,8 @@ struct pthread + { + uint32_t cpu_id_start; + uint32_t cpu_id; ++ uint64_t rseq_cs; ++ uint32_t flags; + }; + char pad[32]; /* Original rseq area size. */ + } rseq_area __attribute__ ((aligned (32))); +diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h +index 226ba59a24..8fd26f335e 100644 +--- a/sysdeps/unix/sysv/linux/rseq-internal.h ++++ b/sysdeps/unix/sysv/linux/rseq-internal.h +@@ -51,11 +51,21 @@ rseq_register_current_thread (struct pthread *self, bool do_rseq) + /* The initial implementation used only 20 bytes out of 32, + but still expected size 32. */ + size = RSEQ_AREA_SIZE_INITIAL; ++ ++ /* Initialize the rseq fields that are read by the kernel on ++ registration, there is no guarantee that struct pthread is ++ cleared on all architectures. */ ++ THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_UNINITIALIZED); ++ THREAD_SETMEM (self, rseq_area.rseq_cs, 0); ++ THREAD_SETMEM (self, rseq_area.flags, 0); ++ + int ret = INTERNAL_SYSCALL_CALL (rseq, &self->rseq_area, + size, 0, RSEQ_SIG); + if (!INTERNAL_SYSCALL_ERROR_P (ret)) + return true; + } ++ /* When rseq is disabled by tunables or the registration fails, inform ++ userspace by setting 'cpu_id' to RSEQ_CPU_ID_REGISTRATION_FAILED. */ + THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED); + return false; + } +-- +2.27.0 +