From 3ce3777c0ab73888a241fd642e99328a9a6f7ca5 Mon Sep 17 00:00:00 2001 From: yinbin Date: Fri, 17 Jan 2025 19:54:59 +0800 Subject: [PATCH] sync SIGNAL: block SIGSEGV during exit process (cherry picked from commit 0997bc86367e1038eec8bbdc0ec0773b3a95c331) --- ...ix-the-memory-leak-when-using-strdup.patch | 25 +++++++ ...k_stop-while-stacks-exit-by-rpc-mess.patch | 74 +++++++++++++++++++ ...AL-block-SIGSEGV-during-exit-process.patch | 58 +++++++++++++++ gazelle.spec | 10 ++- 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 0314-fix-the-memory-leak-when-using-strdup.patch create mode 100644 0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch create mode 100644 0316-SIGNAL-block-SIGSEGV-during-exit-process.patch diff --git a/0314-fix-the-memory-leak-when-using-strdup.patch b/0314-fix-the-memory-leak-when-using-strdup.patch new file mode 100644 index 0000000..d314181 --- /dev/null +++ b/0314-fix-the-memory-leak-when-using-strdup.patch @@ -0,0 +1,25 @@ +From ff847f26a675fe7a1eca24cda2aad5904435ea74 Mon Sep 17 00:00:00 2001 +From: yangchen +Date: Mon, 13 Jan 2025 14:19:47 +0800 +Subject: [PATCH] fix the memory leak when using strdup + +--- + src/lstack/core/lstack_cfg.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c +index 9a935f1..3d49cc3 100644 +--- a/src/lstack/core/lstack_cfg.c ++++ b/src/lstack/core/lstack_cfg.c +@@ -398,7 +398,7 @@ static int32_t parse_devices(void) + sprintf(temp_dev + strlen(temp_dev), "%02x%s", + ((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr[i], i < (ETHER_ADDR_LEN - 1) ? ":" : ""); + } +- dev = strdup_assert_return(temp_dev); ++ dev = temp_dev; + break; + } + +-- +2.33.0 + diff --git a/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch b/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch new file mode 100644 index 0000000..9daafed --- /dev/null +++ b/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch @@ -0,0 +1,74 @@ +From 51e3c4f57dfcd6400df17bbebe18f544b90e134f Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Tue, 14 Jan 2025 10:19:27 +0800 +Subject: [PATCH] Stack: unset stack_stop, while stacks exit by rpc message. + +--- + src/lstack/api/lstack_unistd.c | 2 +- + src/lstack/core/lstack_protocol_stack.c | 3 ++- + src/lstack/core/lstack_thread_rpc.c | 1 - + src/lstack/include/lstack_protocol_stack.h | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c +index 0837a6b..d8b5d8e 100644 +--- a/src/lstack/api/lstack_unistd.c ++++ b/src/lstack/api/lstack_unistd.c +@@ -71,7 +71,7 @@ static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *con + + LSTACK_LOG(ERR, LSTACK, "lstack dumped, caught signal: %d\n", sig); + +- stack_stop(); ++ stack_wait(); + + if (sig_need_dump(sig)) { + /* dump stack info */ +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 1eebac4..fcc0ad7 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -795,7 +795,7 @@ void stack_exit(void) + } + } + +-void stack_stop(void) ++void stack_wait(void) + { + struct protocol_stack *stack = get_protocol_stack(); + if (stack != NULL) { +@@ -824,6 +824,7 @@ void stack_group_exit(void) + stack_exit(); + } + ++ /* Waiting all stacks' status transfer to WAIT, which means stacks are ready to exit. */ + for (i = 0; i < stack_group->stack_num; i++) { + if (stack_group->stacks[i] == NULL || stack == stack_group->stacks[i]) { + continue; +diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c +index 9f871af..26bd16a 100644 +--- a/src/lstack/core/lstack_thread_rpc.c ++++ b/src/lstack/core/lstack_thread_rpc.c +@@ -146,7 +146,6 @@ static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) + + static void stack_exit_by_rpc(struct rpc_msg *msg) + { +- stack_stop(); + stack_exit(); + } + +diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h +index c7c7efe..c9c50c9 100644 +--- a/src/lstack/include/lstack_protocol_stack.h ++++ b/src/lstack/include/lstack_protocol_stack.h +@@ -120,7 +120,7 @@ void thread_bind_stack(struct protocol_stack *stack); + int stack_group_init(void); + void stack_group_exit(void); + void stack_exit(void); +-void stack_stop(void); ++void stack_wait(void); + + int stack_setup_thread(void); + int stack_setup_app_thread(void); +-- +2.33.0 + diff --git a/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch b/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch new file mode 100644 index 0000000..a339ff5 --- /dev/null +++ b/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch @@ -0,0 +1,58 @@ +From 5d7e406a138567a9959c994af4fb574f7f075bed Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Wed, 15 Jan 2025 11:16:43 +0800 +Subject: [PATCH] SIGNAL: block SIGSEGV during exit process + +--- + src/lstack/api/lstack_unistd.c | 21 ++++++++++++--------- + 1 file changed, 12 insertions(+), 9 deletions(-) + +diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c +index d8b5d8e..e3b9b1f 100644 +--- a/src/lstack/api/lstack_unistd.c ++++ b/src/lstack/api/lstack_unistd.c +@@ -58,6 +58,15 @@ bool sig_need_dump(int sig) + return true; + } + ++static void pthread_block_sig(int sig) ++{ ++ sigset_t mask; ++ ++ sigemptyset(&mask); ++ sigaddset(&mask, sig); ++ pthread_sigmask(SIG_BLOCK, &mask, NULL); ++} ++ + static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *context) + { + static bool skip_process_exit = false; +@@ -81,6 +90,9 @@ static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *con + dump_lstack(); + } + ++ /* App sig_handler may access invalid memory address in gazelle threads, ++ * so we block this signal avoiding getting stuck during exit. */ ++ pthread_block_sig(SIGSEGV); + if (sig_is_registered(sig)) { + if (g_register_sigactions[sig].sa_flags & SA_SIGINFO) { + g_register_sigactions[sig].sa_sigaction(sig, info, context); +@@ -106,15 +118,6 @@ static void lstack_sig_default_handler(int sig) + lstack_sigaction_default_handler(sig, NULL, NULL); + } + +-static void pthread_block_sig(int sig) +-{ +- sigset_t mask; +- +- sigemptyset(&mask); +- sigaddset(&mask, sig); +- pthread_sigmask(SIG_BLOCK, &mask, NULL); +-} +- + static void pthread_unblock_sig(int sig) + { + sigset_t mask; +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index e114383..8eea003 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.2 -Release: 82 +Release: 83 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -330,6 +330,9 @@ Patch9310: 0310-DUMP-fix-build-error-of-oe2003-because-of-micro-is-n.patch Patch9311: 0311-SIGNAL-Adjust-sigaction-function-to-keep-lstack-sign.patch Patch9312: 0312-SIGNAL-Adjust-hijack-sigal-table-to-hijack-SIGABRT-S.patch Patch9313: 0313-DUMP-fix-abnomal-printing-in-the-dump-process.patch +Patch9314: 0314-fix-the-memory-leak-when-using-strdup.patch +Patch9315: 0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch +Patch9316: 0316-SIGNAL-block-SIGSEGV-during-exit-process.patch %description %{name} is a high performance user-mode stack. @@ -371,6 +374,11 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Fri Jan 17 2025 yinbin6 - 1.0.2-83 +- SIGNAL: block SIGSEGV during exit process +- Stack: unset stack_stop, while stacks exit by rpc message. +- fix the memory leak when using strdup + * Fri Jan 10 2025 yinbin6 - 1.0.2-82 - DUMP: fix abnomal printing in the dump process. - SIGNAL: Adjust hijack sigal table to hijack SIGABRT SIGQUIT and delet SIGKILL -- Gitee