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=-15.9 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 4568EC433EF for ; Wed, 8 Sep 2021 19:06:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B9DB610A3 for ; Wed, 8 Sep 2021 19:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349717AbhIHTHV (ORCPT ); Wed, 8 Sep 2021 15:07:21 -0400 Received: from home.keithp.com ([63.227.221.253]:35386 "EHLO elaine.keithp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347196AbhIHTHU (ORCPT ); Wed, 8 Sep 2021 15:07:20 -0400 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id B7B0F3F30886; Wed, 8 Sep 2021 12:05:47 -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 jjqKtPL7fQVo; Wed, 8 Sep 2021 12:05:47 -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 4484C3F30881; Wed, 8 Sep 2021 12:05:47 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id 4D1691E6011A; Wed, 8 Sep 2021 12:06:09 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Alexei Starovoitov , Andrew Morton , Andrii Nakryiko , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Ben Segall , Bjorn Andersson , bpf@vger.kernel.org, Christoph Lameter , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , devicetree@vger.kernel.org, Dietmar Eggemann , Florian Fainelli , Frank Rowand , Geert Uytterhoeven , Ingo Molnar , Jason Wang , Jens Axboe , Joe Perches , John Fastabend , Juri Lelli , Keith Packard , KP Singh , kvm@vger.kernel.org, Linus Walleij , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Martin KaFai Lau , Mel Gorman , Michael Ellerman , "Michael S. Tsirkin" , Miguel Ojeda , Mike Rapoport , netdev@vger.kernel.org, Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Peter Zijlstra , Rob Herring , Russell King , Song Liu , Srikar Dronamraju , Steven Rostedt , Tejun Heo , Thomas Gleixner , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Valentin Schneider , Vincent Guittot , virtualization@lists.linux-foundation.org, "Wolfram Sang (Renesas)" , YiFei Zhu , Yonghong Song Subject: [PATCH v4 0/7] ARM: support THREAD_INFO_IN_TASK Date: Wed, 8 Sep 2021 12:05:58 -0700 Message-Id: <20210908190605.419064-1-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 fourth 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 independently 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) Patches across the kernel which ensure that linux/sched.h has been included whenever raw_smp_processor_id() is used. 5) Disable the optimization storing per_cpu_offset in TPIDRPRW. This leaves 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 Keith Packard (7): ARM: Pass cpu number to secondary_start_kernel ARM: Pass task to secondary_start_kernel ARM: Use smp_processor_id() in vfp_pm_suspend instead of ti->cpu Make sure task_struct is available for raw_smp_processor_id ARM: Stop using TPIDRPRW to hold per_cpu_offset ARM: Use TPIDRPRW for current ARM: Move thread_info into task_struct (v7 only) arch/arm/Kconfig | 5 +++ arch/arm/include/asm/assembler.h | 12 +++++++ arch/arm/include/asm/current.h | 54 ++++++++++++++++++++++++++++++ arch/arm/include/asm/percpu.h | 31 ----------------- arch/arm/include/asm/smp.h | 8 ++++- arch/arm/include/asm/thread_info.h | 12 ++++++- arch/arm/kernel/asm-offsets.c | 4 +++ arch/arm/kernel/entry-armv.S | 8 +++++ arch/arm/kernel/head-nommu.S | 2 ++ arch/arm/kernel/head.S | 2 ++ arch/arm/kernel/setup.c | 14 +------- arch/arm/kernel/smp.c | 16 +++++---- arch/arm/mm/proc-v7-bugs.c | 1 + arch/arm/vfp/vfpmodule.c | 15 +++++++-- drivers/vhost/vhost.c | 1 + drivers/vhost/vhost.h | 1 + include/asm-generic/irq_regs.h | 1 + include/linux/of_address.h | 1 + include/linux/random.h | 1 + include/linux/topology.h | 1 + init/calibrate.c | 1 + kernel/bpf/bpf_lru_list.h | 1 + kernel/bpf/percpu_freelist.h | 1 + kernel/sched/cpuacct.c | 2 +- lib/irq_regs.c | 1 + 25 files changed, 140 insertions(+), 56 deletions(-) create mode 100644 arch/arm/include/asm/current.h -- 2.33.0