Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1259733ybl; Mon, 2 Dec 2019 00:16:14 -0800 (PST) X-Google-Smtp-Source: APXvYqyf5+fmHIaZiJ9U2FsTqQmaeyRnN+A0MOt+o4oI1AGv4R7JI52IOquUUIFc7xxISLPwVgKK X-Received: by 2002:a05:6402:282:: with SMTP id l2mr63631901edv.187.1575274574720; Mon, 02 Dec 2019 00:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575274574; cv=none; d=google.com; s=arc-20160816; b=kUA8GIDYAPwuSshVG3lbGuzSCc4Gm4F449S3k83t5Kuf0MZFd2F5F8Mw3mzVUcG/FE UUPtiuvF45StMb08tUXZUlBJtrAdcGL2PJ2VR1rgg0NRnSuviJBkhoRDQHktMvJG4ih0 PNcUwHzJrTbXrk4iGU/vN9ERstdubJeuZ5vKuZUxTJ5xFB1gKXNzlg/6fxc3R6zv7TIG +4n8r89VmvFGpdEdF0R6aZeXd6g2auUJ6PLtUKdv6u6kr/jZr7erqQ80V0CgzgigQSFa JLo7dKrvWvSOAlQXxENq3mqKBLMaKFvBS+b7WXrpWNMOq56V0/0PebthrEo4JrDoARIh QU4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=jyrs/wJGNR+Jhe2Q5dkJey8tK1boO73yrbBmCKO+PS8=; b=yQqUiKl53DPFQvTKPJfjxj/xUrdZWw6ksBde1FEgPoji04SWNKBiabj6WXkwPVfFdt +GL4g30kI87mnEeB+/gWOz1iTO2A0bzR4UGSDvW4+hv2HUlIrGkisQwJ/C+obaMZct4E GZTY2g1O+aIrEXwjLyNMopbo0QTUSmXbuWG8MbYl7iS4zrtDJ37dTMb92O8fsz55QdLY ssUibxiV806iJXO2sgk4wGOtLIVDox0aKRWH5ixvR21uqK4I+f1Ukl2Hg2q8XyrPvhVs w3izTSS9mYZTscGVDYCJPp61Wl+1aImp0GzDUU8o8TyEh8JOfpP4GkWNp47vgK6MZqKL PhPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dm4si16319746edb.440.2019.12.02.00.15.51; Mon, 02 Dec 2019 00:16:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727423AbfLBIOj (ORCPT + 99 others); Mon, 2 Dec 2019 03:14:39 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:37316 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726214AbfLBIOY (ORCPT ); Mon, 2 Dec 2019 03:14:24 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 96B92106611D16A3E7B5; Mon, 2 Dec 2019 16:14:17 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Mon, 2 Dec 2019 16:14:09 +0800 From: "zhangyi (F)" To: CC: , , , , , , , , , , , Subject: [PATCH 4.4 2/7] sched/core: Add try_get_task_stack() and put_task_stack() Date: Mon, 2 Dec 2019 16:35:14 +0800 Message-ID: <20191202083519.23138-3-yi.zhang@huawei.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20191202083519.23138-1-yi.zhang@huawei.com> References: <20191202083519.23138-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski commit c6c314a613cd7d03fb97713e0d642b493de42e69 upstream. There are a few places in the kernel that access stack memory belonging to a different task. Before we can start freeing task stacks before the task_struct is freed, we need a way for those code paths to pin the stack. Signed-off-by: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Jann Horn Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/17a434f50ad3d77000104f21666575e10a9c1fbd.1474003868.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: zhangyi (F) --- include/linux/sched.h | 16 ++++++++++++++++ init/Kconfig | 3 +++ 2 files changed, 19 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index d6b2e77aad3f..761247c966a5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2858,11 +2858,19 @@ static inline struct thread_info *task_thread_info(struct task_struct *task) { return &task->thread_info; } + +/* + * When accessing the stack of a non-current task that might exit, use + * try_get_task_stack() instead. task_stack_page will return a pointer + * that could get freed out from under you. + */ static inline void *task_stack_page(const struct task_struct *task) { return task->stack; } + #define setup_thread_stack(new,old) do { } while(0) + static inline unsigned long *end_of_stack(const struct task_struct *task) { return task->stack; @@ -2898,6 +2906,14 @@ static inline unsigned long *end_of_stack(struct task_struct *p) } #endif + +static inline void *try_get_task_stack(struct task_struct *tsk) +{ + return task_stack_page(tsk); +} + +static inline void put_task_stack(struct task_struct *tsk) {} + #define task_stack_end_corrupted(task) \ (*(end_of_stack(task)) != STACK_END_MAGIC) diff --git a/init/Kconfig b/init/Kconfig index 5dec7d424980..f9fb621c9562 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -33,6 +33,9 @@ config THREAD_INFO_IN_TASK make this work, an arch will need to remove all thread_info fields except flags and fix any runtime bugs. + One subtle change that will be needed is to use try_get_task_stack() + and put_task_stack() in save_thread_stack_tsk() and get_wchan(). + menu "General setup" config BROKEN -- 2.17.2