Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3209233imu; Sat, 24 Nov 2018 00:08:54 -0800 (PST) X-Google-Smtp-Source: AJdET5dKGfSIqznbXnsuBqInjNc1LlyhLLKKb3q11LAaWByz7k6isWJVOpvN0paStjQfe+xiMqO1 X-Received: by 2002:a62:1a44:: with SMTP id a65mr19699871pfa.30.1543046934642; Sat, 24 Nov 2018 00:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046934; cv=none; d=google.com; s=arc-20160816; b=VURK+He3fvvqZZN50yXGHGDrz8lriu7Nu9T4RyLB2Bt9CR9dByJNDTeZ41lkVXYAHG w7cZThYDQaBNhumPI7sdCsq51leiLEVX7P0x+eGW0SlMz3i0CEd3kp4oXSE8qTiFp890 l1Spw7Wpe9EE0cIqqrimaGfRCz0T0fArw1vjn91W5x30PlxUT6O5TqB6P+k4cjHVYlxO NVbWv06X0Jem6QyL2Ml3GUdaetNSVn5oqE4aQ+X2thC32Wc6/IBSkxk20ALRoiJTuXQe j2LSV+DtfJW57Ts8dM5kmwtmEe3V+DWRxd6rpAqcSMaG1AtIq1qIA8BnExduBrnyNRaB CYcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CEZjfaiShnXJU2kL1EIn9H0NWBCcFkEo8e1PsVAJ3RA=; b=Tcl92UDmwDB7FrRSd3jeakLF6EX7BDXypeGptIPvbwesw3d6dZuGTLWU1Ie0Xu5DYa tk6Rsoo3hGekS7xdXRpzEuEC/UD1+xmiv3YFeBFcaNKQno55t48Q+W549q8qOo6tb1ks a0UQCySQYrADdJtWft7oT8+yThDRTNSffuQRTTMxi0u/+W97oRwyOjgKtSpwuKjJsGcr Vdx9aq4IXp2SfjYv7XOolocg9EK61UkXoLL73z+bd0txKauVyZekfCWbXzF6tFFRIMJr U8DPw32PrN7X7mKXlQgOOANRNJO3m4ThjzF6DIKppznfRpq7tXslTmLoBGdlqea4M9du +c3Q== 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 s80si17377731pfa.130.2018.11.24.00.08.40; Sat, 24 Nov 2018 00:08:54 -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 S2393505AbeKWSjM (ORCPT + 99 others); Fri, 23 Nov 2018 13:39:12 -0500 Received: from mx01.hxt-semitech.com ([223.203.96.7]:54727 "EHLO barracuda.hxt-semitech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390536AbeKWSjL (ORCPT ); Fri, 23 Nov 2018 13:39:11 -0500 X-ASG-Debug-ID: 1542959745-093b7e021a0b010001-xx1T2L Received: from HXTBJIDCEMVIW02.hxtcorp.net ([10.128.0.15]) by barracuda.hxt-semitech.com with ESMTP id h1wUzLptsjbR4O80 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Fri, 23 Nov 2018 15:55:45 +0800 (CST) X-Barracuda-Envelope-From: dongsheng.wang@hxt-semitech.com Received: from arch.localdomain (10.64.6.159) by HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 23 Nov 2018 15:55:02 +0800 From: Wang Dongsheng To: , CC: , , , , , , , , , Wang Dongsheng , Shunyong Yang Subject: [PATCH 1/1] sched/headers: fix thread_info. is overwritten by STACK_END_MAGIC Date: Fri, 23 Nov 2018 15:54:48 +0800 X-ASG-Orig-Subj: [PATCH 1/1] sched/headers: fix thread_info. is overwritten by STACK_END_MAGIC Message-ID: X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.64.6.159] X-ClientProxiedBy: HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) To HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) X-Barracuda-Connect: UNKNOWN[10.128.0.15] X-Barracuda-Start-Time: 1542959745 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA384 X-Barracuda-URL: https://192.168.50.101:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at hxt-semitech.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: SPAM GLOBAL 0.9457 1.0000 3.7240 X-Barracuda-Spam-Score: 3.72 X-Barracuda-Spam-Status: No, SCORE=3.72 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.62283 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When select ARCH_TASK_STRUCT_ON_STACK the first of thread_info variable is overwritten by STACK_END_MAGIC. In fact, the ARCH_TASK_STRUCT_ON_STACK is not a real task on stack, it's only init_task on init_stack. Commit 0500871f21b2 ("Construct init thread stack in the linker script rather than by union") added this macro and put task_strcut into thread_union. This brings us the following possibilities: TASK_ON_STACK THREAD_INFO_IN_TASK STACK ----- <-- thread_info & stack N N | | --- <-- task | | | | ----- --- ----- <-- stack N Y | | --- <-- task(Including thread_info) | | | | ----- --- ----- <-- stack & task & thread_info Y N | | | | ----- ----- <-- stack & task(Including thread_info) Y Y | | | | ----- The kernel has handled the first two cases correctly. For the third case: TASK_ON_STACK: Y. THREAD_INFO_IN_TASK: N. this case should never happen, because the task and thread_info will overlap. So when TASK_ON_STACK is selected, THREAD_INFO_IN_TASK must be selected too. For the fourth case: When task on stack, the end of stack should add a sizeof(task_struct) offset. This patch handled with the third and fourth case. Fixes: 0500871f21b2 ("Construct init thread stack in the linker ...") Signed-off-by: Wang Dongsheng Signed-off-by: Shunyong Yang --- arch/Kconfig | 1 + include/linux/sched/task_stack.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index e1e540ffa979..0a2c73e73195 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -251,6 +251,7 @@ config ARCH_HAS_SET_MEMORY # Select if arch init_task must go in the __init_task_data section config ARCH_TASK_STRUCT_ON_STACK bool + depends on THREAD_INFO_IN_TASK || IA64 # Select if arch has its private alloc_task_struct() function config ARCH_TASK_STRUCT_ALLOCATOR diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h index 6a841929073f..624c48defb9e 100644 --- a/include/linux/sched/task_stack.h +++ b/include/linux/sched/task_stack.h @@ -7,6 +7,7 @@ */ #include +#include #include #ifdef CONFIG_THREAD_INFO_IN_TASK @@ -25,7 +26,9 @@ static inline void *task_stack_page(const struct task_struct *task) static inline unsigned long *end_of_stack(const struct task_struct *task) { - return task->stack; + if (!IS_ENABLED(CONFIG_ARCH_TASK_STRUCT_ON_STACK) || task != &init_task) + return task->stack; + return (unsigned long *)(task + 1); } #elif !defined(__HAVE_THREAD_FUNCTIONS) -- 2.19.1