From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB3F1C433EF for ; Tue, 7 Sep 2021 22:01:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C91761103 for ; Tue, 7 Sep 2021 22:01:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7C91761103 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0070F6B007E; Tue, 7 Sep 2021 18:01:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF8206B0080; Tue, 7 Sep 2021 18:01:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE9DF6B0081; Tue, 7 Sep 2021 18:01:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id CE6C96B007E for ; Tue, 7 Sep 2021 18:01:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 88FF38249980 for ; Tue, 7 Sep 2021 22:01:46 +0000 (UTC) X-FDA: 78562150212.19.73F1B1B Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf04.hostedemail.com (Postfix) with ESMTP id 1AA06500030F for ; Tue, 7 Sep 2021 22:00:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 8839D3F30869; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id D1flVso7MpDe; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id D3EF03F30864; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id CACEA1E6011A; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 0/7] ARM: support THREAD_INFO_IN_TASK (v3) Date: Tue, 7 Sep 2021 15:00:31 -0700 Message-Id: <20210907220038.91021-1-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210904060908.1310204-1-keithp@keithp.com> References: <20210904060908.1310204-1-keithp@keithp.com> MIME-Version: 1.0 Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf04.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1AA06500030F X-Stat-Signature: ijpoe5h8r8cwya3qegdjjywokaohab5b X-Rspam: Yes X-HE-Tag: 1631052045-706005 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Placing thread_info in the kernel stack leaves it vulnerable to stack overflow attacks. This short series addresses that by using the existing THREAD_INFO_IN_TASK infrastructure. This is the third version of this series, in this version the changes are restricted to hardware which provides the TPIDRPRW register. This register is repurposed from holding the per_cpu_offset value to holding the 'current' value as that allows fetching this value atomically so that it can be used in a preemptable context. The series is broken into seven pieces: 1) Change the secondary_start_kernel API to receive the cpu number. This avoids needing to be able to find this value independent= ly in future patches. 2) Change the secondary_start_kernel API to also receive the 'task' value. Passing the value to this function also avoids needing to be able to discover it independently. 3) A cleanup which avoids assuming that THREAD_INFO_IN_TASK is not set. 4) A hack, borrowed from the powerpc arch, which allows locating the 'cp= u' field in either thread_info or task_struct, without requiring linux/s= ched.h to be included in asm/smp.h 5) Disable the optimization storing per_cpu_offset in TPIDRPRW. This lea= ves the register free to hold 'current' instead. 6) Use TPIDRPRW for 'current'. This is enabled for either CPU_V6K or CPU= _V7, but not if CPU_V6 is also enabled. 7) Enable THREAD_INFO_IN_TASK whenever TPIDRPRW is used to hold 'current= '. Signed-off-by: Keith Packard