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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41AF7C4332F for ; Mon, 24 Jan 2022 17:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbiAXRtY (ORCPT ); Mon, 24 Jan 2022 12:49:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244574AbiAXRtR (ORCPT ); Mon, 24 Jan 2022 12:49:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773B4C061749 for ; Mon, 24 Jan 2022 09:49:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1729D612ED for ; Mon, 24 Jan 2022 17:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A668CC36AE3; Mon, 24 Jan 2022 17:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643046553; bh=7/tPcs0AmFlFig2nf32yKs0oXHAh78N7PZcSvkHYuEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ix2obOLvTb/6d1w5I5g0g94HOPKD4OFWz2YGwtrQlnDFUF56aFaNnfwyABSMPZxpF gzXcLgS1t6I64zBhnNOYtUOos6GX48qM6FN41EoTbWBULO7Bx/DXxEpqIGSfZ8tdQI c2TfrzDgMnbWLFf5TvUMqjk8tfeDPFJGkaiObNP47JzDUwbpUrXGXP2K5APNngMCol +ZjlUV9ZRFZ7KcoffeCo8znRH+cCVzYzaa4/FmL0IsBplhe9ihNoiGXIjdfYXsoSM8 gUaV1Apos2fHBUUbYcw9jaUUw4GovptdDYrq8StYosSVMVuVGo8SNciGhKTHSNtrh1 Av6QbJbJzUlfQ== From: Ard Biesheuvel To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren , Marc Zyngier , Vladimir Murzin , Jesse Taube Subject: [PATCH v5 24/32] ARM: run softirqs on the per-CPU IRQ stack Date: Mon, 24 Jan 2022 18:47:36 +0100 Message-Id: <20220124174744.1054712-25-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124174744.1054712-1-ardb@kernel.org> References: <20220124174744.1054712-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2406; h=from:subject; bh=7/tPcs0AmFlFig2nf32yKs0oXHAh78N7PZcSvkHYuEk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh7uYv4B3wns+3iHt4GTJhZo+OVZXNyvKE6fQuPEiS KvEVNBWJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYe7mLwAKCRDDTyI5ktmPJLenDA CyQSCZqXOD56Vhh+YnyWJmMe8xfbgBj1bMYXUtsZsP1J9T5rB9Yw7WBHzdzsB8UhY1D22YcB1CFCLu EFJETkK4aJHEPvIg+CkC6o5fypRX5oFxUDi6f0XWNiqHxQfBAkgnPGjVnrAU9OzIgjmsKwHiZM+lUs /uNJMlkcTCrVQryAHrpQKtEnkMjzB/JTPCXHm7gG4p08apbOfnL0cOyQPMHOXgW0iI2D0GvKVAoBk2 7FfV5PWaC5DQ0My4bPaschjK/oS5Bd7vIaXYtOxyUNwjANZVIVQ+ygP/ElGu9LutnOc1D7PoFC5y4Y 7porgJKvrOuBi1czxnwsp33uDXMpaHC5aGKW4OF5Cvur7J7wLfjuOeytImanaKJENlkvgyLAnPkD07 CQGBTyDAN+D81vDmYJD76x1cIujuYMOdwlGueW1oP/PFF0aUWHux/J+v/XPlvx3E8MkWuSFSD1pLKX XOX6foFqjgSDULN8KYdRZng64HDILZahR0hCNdtggoYgM= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Now that we have enabled IRQ stacks, any softIRQs that are handled over the back of a hard IRQ will run from the IRQ stack as well. However, any synchronous softirq processing that happens when re-enabling softIRQs from task context will still execute on that task's stack. Since any call to local_bh_enable() at any level in the task's call stack may trigger a softIRQ processing run, which could potentially cause a task stack overflow if the combined stack footprints exceed the stack's size, let's run these synchronous invocations of do_softirq() on the IRQ stack as well. Signed-off-by: Ard Biesheuvel Reviewed-by: Arnd Bergmann Acked-by: Linus Walleij Tested-by: Keith Packard Tested-by: Marc Zyngier Tested-by: Vladimir Murzin # ARMv7M --- arch/arm/Kconfig | 2 ++ arch/arm/kernel/irq.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 108a7a872084..b959249dd716 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -128,6 +128,8 @@ config ARM select RTC_LIB select SYS_SUPPORTS_APM_EMULATION select THREAD_INFO_IN_TASK + select HAVE_IRQ_EXIT_ON_IRQ_STACK + select HAVE_SOFTIRQ_ON_OWN_STACK select TRACE_IRQFLAGS_SUPPORT if !CPU_V7M # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c index 92ae80a8e5b4..380376f55554 100644 --- a/arch/arm/kernel/irq.c +++ b/arch/arm/kernel/irq.c @@ -36,11 +36,14 @@ #include #include #include +#include #include #include #include #include +#include "reboot.h" + unsigned long irq_err_count; asmlinkage DEFINE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr); @@ -58,6 +61,17 @@ static void __init init_irq_stacks(void) } } +static void ____do_softirq(void *arg) +{ + __do_softirq(); +} + +void do_softirq_own_stack(void) +{ + call_with_stack(____do_softirq, NULL, + __this_cpu_read(irq_stack_ptr)); +} + int arch_show_interrupts(struct seq_file *p, int prec) { #ifdef CONFIG_FIQ -- 2.30.2 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94BA1C433F5 for ; Mon, 24 Jan 2022 18:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7VQ/77QqYEL6zQgjp8Z/6uZCi4D5VAI4NPb/An/DlxI=; b=MZEZlqu3QKrnyg 2WCqa7i5qbb0kWEjtkDPIJAy2PLzV/z5luJwnterDY3YqX+147Q4xvivMcVb0VjuyxB9I0ry71IYm Jw7GWCpSkUYSv1U3ASQEvbEDe1F1YVPWsmsJqUBGV+encDr3tnhBOfSf7PVt66VKfebEaGXa3R/Li EWcg4pZRJr5+PyrGv3no73pkHLE0Xm7UyI5/fNJfobiQBucOpHUUnUlLZu1PkZEqk45gxtdMw2KUO MNZ5bYmqh7xsyLoMJJX7szy70JzzQU1pPJBR4wKfE5CTvZEyL8wvbhHDliVe/SIpb1sDNEJLn9zcG 1WIQdwxvCbdUXsEhctew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3j9-004N4u-FO; Mon, 24 Jan 2022 18:06:03 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3Ss-004FdZ-Kq for linux-arm-kernel@lists.infradead.org; Mon, 24 Jan 2022 17:49:16 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 173406132D; Mon, 24 Jan 2022 17:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A668CC36AE3; Mon, 24 Jan 2022 17:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643046553; bh=7/tPcs0AmFlFig2nf32yKs0oXHAh78N7PZcSvkHYuEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ix2obOLvTb/6d1w5I5g0g94HOPKD4OFWz2YGwtrQlnDFUF56aFaNnfwyABSMPZxpF gzXcLgS1t6I64zBhnNOYtUOos6GX48qM6FN41EoTbWBULO7Bx/DXxEpqIGSfZ8tdQI c2TfrzDgMnbWLFf5TvUMqjk8tfeDPFJGkaiObNP47JzDUwbpUrXGXP2K5APNngMCol +ZjlUV9ZRFZ7KcoffeCo8znRH+cCVzYzaa4/FmL0IsBplhe9ihNoiGXIjdfYXsoSM8 gUaV1Apos2fHBUUbYcw9jaUUw4GovptdDYrq8StYosSVMVuVGo8SNciGhKTHSNtrh1 Av6QbJbJzUlfQ== From: Ard Biesheuvel To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren , Marc Zyngier , Vladimir Murzin , Jesse Taube Subject: [PATCH v5 24/32] ARM: run softirqs on the per-CPU IRQ stack Date: Mon, 24 Jan 2022 18:47:36 +0100 Message-Id: <20220124174744.1054712-25-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124174744.1054712-1-ardb@kernel.org> References: <20220124174744.1054712-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2406; h=from:subject; bh=7/tPcs0AmFlFig2nf32yKs0oXHAh78N7PZcSvkHYuEk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh7uYv4B3wns+3iHt4GTJhZo+OVZXNyvKE6fQuPEiS KvEVNBWJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYe7mLwAKCRDDTyI5ktmPJLenDA CyQSCZqXOD56Vhh+YnyWJmMe8xfbgBj1bMYXUtsZsP1J9T5rB9Yw7WBHzdzsB8UhY1D22YcB1CFCLu EFJETkK4aJHEPvIg+CkC6o5fypRX5oFxUDi6f0XWNiqHxQfBAkgnPGjVnrAU9OzIgjmsKwHiZM+lUs /uNJMlkcTCrVQryAHrpQKtEnkMjzB/JTPCXHm7gG4p08apbOfnL0cOyQPMHOXgW0iI2D0GvKVAoBk2 7FfV5PWaC5DQ0My4bPaschjK/oS5Bd7vIaXYtOxyUNwjANZVIVQ+ygP/ElGu9LutnOc1D7PoFC5y4Y 7porgJKvrOuBi1czxnwsp33uDXMpaHC5aGKW4OF5Cvur7J7wLfjuOeytImanaKJENlkvgyLAnPkD07 CQGBTyDAN+D81vDmYJD76x1cIujuYMOdwlGueW1oP/PFF0aUWHux/J+v/XPlvx3E8MkWuSFSD1pLKX XOX6foFqjgSDULN8KYdRZng64HDILZahR0hCNdtggoYgM= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220124_094914_801362_7C4ED48A X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now that we have enabled IRQ stacks, any softIRQs that are handled over the back of a hard IRQ will run from the IRQ stack as well. However, any synchronous softirq processing that happens when re-enabling softIRQs from task context will still execute on that task's stack. Since any call to local_bh_enable() at any level in the task's call stack may trigger a softIRQ processing run, which could potentially cause a task stack overflow if the combined stack footprints exceed the stack's size, let's run these synchronous invocations of do_softirq() on the IRQ stack as well. Signed-off-by: Ard Biesheuvel Reviewed-by: Arnd Bergmann Acked-by: Linus Walleij Tested-by: Keith Packard Tested-by: Marc Zyngier Tested-by: Vladimir Murzin # ARMv7M --- arch/arm/Kconfig | 2 ++ arch/arm/kernel/irq.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 108a7a872084..b959249dd716 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -128,6 +128,8 @@ config ARM select RTC_LIB select SYS_SUPPORTS_APM_EMULATION select THREAD_INFO_IN_TASK + select HAVE_IRQ_EXIT_ON_IRQ_STACK + select HAVE_SOFTIRQ_ON_OWN_STACK select TRACE_IRQFLAGS_SUPPORT if !CPU_V7M # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c index 92ae80a8e5b4..380376f55554 100644 --- a/arch/arm/kernel/irq.c +++ b/arch/arm/kernel/irq.c @@ -36,11 +36,14 @@ #include #include #include +#include #include #include #include #include +#include "reboot.h" + unsigned long irq_err_count; asmlinkage DEFINE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr); @@ -58,6 +61,17 @@ static void __init init_irq_stacks(void) } } +static void ____do_softirq(void *arg) +{ + __do_softirq(); +} + +void do_softirq_own_stack(void) +{ + call_with_stack(____do_softirq, NULL, + __this_cpu_read(irq_stack_ptr)); +} + int arch_show_interrupts(struct seq_file *p, int prec) { #ifdef CONFIG_FIQ -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel