1 Star 0 Fork 32

fantaotao1/gazelle

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0249-fix-t_params-use-after-free-in-kernel-event-thread.patch 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
From 52a5607eb8f20ccbaf03c8046b29763c2081e24a Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 5 Sep 2022 14:46:46 +0800
Subject: [PATCH] fix t_params use after free in kernel event thread
---
src/lstack/core/lstack_protocol_stack.c | 30 +++++++++++++++----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
index 52a0c8f..a8c5e14 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -263,7 +263,9 @@ static void* gazelle_kernelevent_thread(void *arg)
struct thread_params *t_params = (struct thread_params*) arg;
uint16_t idx = t_params->idx;
struct protocol_stack *stack = get_protocol_stack_group()->stacks[idx];
+ struct protocol_stack_group *stack_group = get_protocol_stack_group();
+ sem_post(&stack_group->thread_phase1);
bind_to_stack_numa(stack);
LSTACK_LOG(INFO, LSTACK, "kernelevent_%02hu start\n", idx);
@@ -358,23 +360,22 @@ static struct protocol_stack *stack_thread_init(void *arg)
struct protocol_stack *stack = calloc(1, sizeof(*stack));
if (stack == NULL) {
LSTACK_LOG(ERR, LSTACK, "malloc stack failed\n");
- sem_post(&stack_group->thread_phase1);
- return NULL;
+ goto END2;
}
if (init_stack_value(stack, arg) != 0) {
- goto END;
+ goto END2;
}
if (init_stack_numa_cpuset(stack) < 0) {
- goto END;
+ goto END2;
}
if (create_affiliate_thread(arg) < 0) {
- goto END;
+ goto END2;
}
if (thread_affinity_init(stack->cpu_id) != 0) {
- goto END;
+ goto END1;
}
RTE_PER_LCORE(_lcore_id) = stack->cpu_id;
@@ -384,7 +385,7 @@ static struct protocol_stack *stack_thread_init(void *arg)
if (use_ltran()) {
if (client_reg_thrd_ring() != 0) {
- goto END;
+ goto END1;
}
}
@@ -397,14 +398,18 @@ static struct protocol_stack *stack_thread_init(void *arg)
usleep(SLEEP_US_BEFORE_LINK_UP);
if (ethdev_init(stack) != 0) {
- free(stack);
- return NULL;
+ goto END1;
}
return stack;
-END:
+/* kernel event thread dont create, stack thread post sem twice */
+END2:
+ sem_post(&stack_group->thread_phase1);
+END1:
sem_post(&stack_group->thread_phase1);
- free(stack);
+ if (stack != NULL) {
+ free(stack);
+ }
return NULL;
}
@@ -597,7 +602,8 @@ int32_t init_protocol_stack(void)
}
}
- wait_sem_value(&stack_group->thread_phase1, stack_group->stack_num);
+ /* stack_num * 2: stack thread and kernel event thread will post sem */
+ wait_sem_value(&stack_group->thread_phase1, stack_group->stack_num * 2);
for (int idx = 0; idx < queue_num; idx++){
free(t_params[idx]);
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fantaotao1/gazelle.git
git@gitee.com:fantaotao1/gazelle.git
fantaotao1
gazelle
gazelle
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385