提交 3739265f 编写于 作者: Z Zheng Zucheng 提交者: Zheng Zengkai

fork: Allocate a new task_struct_resvd object for fork task

hulk inclusion
category: feature
bugzilla: 187196, https://gitee.com/openeuler/kernel/issues/I612CS
CVE: NA

-------------------------------

Allocate a new task_struct_resvd object for the recently cloned task
Signed-off-by: NZheng Zucheng <zhengzucheng@huawei.com>
Reviewed-by: NZhang Qiao <zhangqiao22@huawei.com>
Reviewed-by: NNanyong Sun <sunnanyong@huawei.com>
Reviewed-by: Nchenhui <judy.chenhui@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 2b42032b
...@@ -673,6 +673,8 @@ struct wake_q_node { ...@@ -673,6 +673,8 @@ struct wake_q_node {
* struct task_struct_resvd - KABI extension struct * struct task_struct_resvd - KABI extension struct
*/ */
struct task_struct_resvd { struct task_struct_resvd {
/* pointer back to the main task_struct */
struct task_struct *task;
}; };
struct task_struct { struct task_struct {
......
...@@ -57,6 +57,10 @@ unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)] ...@@ -57,6 +57,10 @@ unsigned long init_shadow_call_stack[SCS_SIZE / sizeof(long)]
}; };
#endif #endif
static struct task_struct_resvd init_task_struct_resvd = {
.task = &init_task,
};
/* /*
* Set up the first task table, touch at your own risk!. Base=0, * Set up the first task table, touch at your own risk!. Base=0,
* limit=0x1fffff (=2MB) * limit=0x1fffff (=2MB)
...@@ -213,6 +217,7 @@ struct task_struct init_task ...@@ -213,6 +217,7 @@ struct task_struct init_task
#ifdef CONFIG_SECCOMP_FILTER #ifdef CONFIG_SECCOMP_FILTER
.seccomp = { .filter_count = ATOMIC_INIT(0) }, .seccomp = { .filter_count = ATOMIC_INIT(0) },
#endif #endif
._resvd = &init_task_struct_resvd,
}; };
EXPORT_SYMBOL(init_task); EXPORT_SYMBOL(init_task);
......
...@@ -174,6 +174,7 @@ static inline struct task_struct *alloc_task_struct_node(int node) ...@@ -174,6 +174,7 @@ static inline struct task_struct *alloc_task_struct_node(int node)
static inline void free_task_struct(struct task_struct *tsk) static inline void free_task_struct(struct task_struct *tsk)
{ {
kfree(tsk->_resvd);
kmem_cache_free(task_struct_cachep, tsk); kmem_cache_free(task_struct_cachep, tsk);
} }
#endif #endif
...@@ -851,6 +852,18 @@ void set_task_stack_end_magic(struct task_struct *tsk) ...@@ -851,6 +852,18 @@ void set_task_stack_end_magic(struct task_struct *tsk)
*stackend = STACK_END_MAGIC; /* for overflow detection */ *stackend = STACK_END_MAGIC; /* for overflow detection */
} }
static bool dup_resvd_task_struct(struct task_struct *dst,
struct task_struct *orig, int node)
{
dst->_resvd = kmalloc_node(sizeof(struct task_struct_resvd),
GFP_KERNEL, node);
if (!dst->_resvd)
return false;
dst->_resvd->task = dst;
return true;
}
static struct task_struct *dup_task_struct(struct task_struct *orig, int node) static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
{ {
struct task_struct *tsk; struct task_struct *tsk;
...@@ -863,6 +876,12 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) ...@@ -863,6 +876,12 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
tsk = alloc_task_struct_node(node); tsk = alloc_task_struct_node(node);
if (!tsk) if (!tsk)
return NULL; return NULL;
/*
* before proceeding, we need to make tsk->_resvd = NULL,
* otherwise the error paths below, if taken, might end up causing
* a double-free for task_struct_resvd extension object.
*/
WRITE_ONCE(tsk->_resvd, NULL);
stack = alloc_thread_stack_node(tsk, node); stack = alloc_thread_stack_node(tsk, node);
if (!stack) if (!stack)
...@@ -888,7 +907,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) ...@@ -888,7 +907,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
refcount_set(&tsk->stack_refcount, 1); refcount_set(&tsk->stack_refcount, 1);
#endif #endif
if (err) if (err || !dup_resvd_task_struct(tsk, orig, node))
goto free_stack; goto free_stack;
err = scs_prepare(tsk, node); err = scs_prepare(tsk, node);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册