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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 7ABB8C433E0 for ; Sun, 28 Mar 2021 14:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 455F261971 for ; Sun, 28 Mar 2021 14:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231301AbhC1OmR (ORCPT ); Sun, 28 Mar 2021 10:42:17 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:37974 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbhC1OmE (ORCPT ); Sun, 28 Mar 2021 10:42:04 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616942523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D54Z2PmLCo200yXOSvaj2hVPC2HaVunYq4YcYHV7CLI=; b=nOSANqfo4EtIMAP5mGifyuzW2Af52m5HsKAtyMqUUKMzc0XR6FoAXid/2jQwT1JZL0bk7z XPx6W8UmnTT3Jx8MOw6POYFwlaSRgC40XHyAM5M5FsbPbyOmckgM3CeZ6439glilf+vtSq sV/a3k181wHYDoGE2YkUj9wK8HnMhNzpeJaVEDbXe5/Xjgk8QNWJBHO+6uqjcNoR+FXFCZ yESHY04k4zxypQtFZ8DrCTzA11YAhm/q9JYc/rH+HEA/Aq5HxI9j53+8VORvF9pvloSBK+ YRfZClUyO8fKSqfnrPgq+eK5DxXnt0UkMYLx1a/LsXp/dt707mjcotvIBxFSaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616942523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D54Z2PmLCo200yXOSvaj2hVPC2HaVunYq4YcYHV7CLI=; b=2/R47s1sLunWDFbaoDjixBAOVW6iJ5IR9uZH6pLWwX8sxIDwqn63g4zVRcfcZhQBqAGFeV mga+yqnJjOZqMqCQ== To: Kees Cook Cc: Kees Cook , Elena Reshetova , x86@kernel.org, Andy Lutomirski , Peter Zijlstra , Catalin Marinas , Will Deacon , Mark Rutland , Alexander Potapenko , Alexander Popov , Ard Biesheuvel , Jann Horn , Vlastimil Babka , David Hildenbrand , Mike Rapoport , Andrew Morton , Jonathan Corbet , Randy Dunlap , kernel-hardening@lists.openwall.com, linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 3/6] stack: Optionally randomize kernel stack offset each syscall In-Reply-To: <20210319212835.3928492-4-keescook@chromium.org> References: <20210319212835.3928492-1-keescook@chromium.org> <20210319212835.3928492-4-keescook@chromium.org> Date: Sun, 28 Mar 2021 16:42:03 +0200 Message-ID: <87eefzcpc4.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kees, On Fri, Mar 19 2021 at 14:28, Kees Cook wrote: > +/* > + * Do not use this anywhere else in the kernel. This is used here because > + * it provides an arch-agnostic way to grow the stack with correct > + * alignment. Also, since this use is being explicitly masked to a max of > + * 10 bits, stack-clash style attacks are unlikely. For more details see > + * "VLAs" in Documentation/process/deprecated.rst VLAs are bad, VLAs to the rescue! :) > + * The asm statement is designed to convince the compiler to keep the > + * allocation around even after "ptr" goes out of scope. > + */ > +void *__builtin_alloca(size_t size); > + > +#define add_random_kstack_offset() do { \ > + if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ > + &randomize_kstack_offset)) { \ > + u32 offset = this_cpu_read(kstack_offset); \ Not that it matters on x86, but as this has to be called in the interrupt disabled region of the syscall entry, shouldn't this be a raw_cpu_read(). The asm-generic version has a preempt_disable/enable pair around the raw read for native wordsize reads, otherwise a irqsave/restore pair. __this_cpu_read() is fine as well, but that has an sanity check before the raw read when CONFIG_DEBUG_PREEMPT is on, which is harmless but also pointless in this case. Probably the same for the counterpart this_cpu_write(). Thanks, tglx 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=-2.9 required=3.0 tests=BAYES_00,DATE_IN_PAST_12_24, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 5DDFFC433DB for ; Mon, 29 Mar 2021 18:35:28 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3682B6191F for ; Mon, 29 Mar 2021 18:35:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3682B6191F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References:In-Reply-To: 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=JcV+QQnU0kTGokhPjBYXlLxYoTFZqCSlKyWVPfKQ9d4=; b=NGEcw2znk79pLoG2FTne2PlN0 tvb/KZm78Cmz7WYCTLe4xy704yPJTLJpi4SNV8vb91pFiH0IyAFNKWU2jRpPam5JDd5yA/uUquee7 /QZO0v0uB24GBRTzRub1DM5y4GNxTnOe033gZUV1HXl4TSulGYF/BK0/ZuzZB7fqei1NzbHb4QZ/3 Ji36p5AF4dZRxPMnLUWeqR+lfMKwLcM4MnHpqs74S0J1G3SyU9RJUIshAjTYp4nrRG7J/zMK9foI7 qcNlU1bOKQmJbquNK7XceKQ9mQ74SpNbzEL64gKsI1Hb3sj/sjdDGW0NWuYjFTfxt5J+dXrPxkacZ q7n/tK1tA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lQwey-0013sk-Cd; Mon, 29 Mar 2021 18:30:44 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lQpFS-000aXi-68 for linux-arm-kernel@lists.infradead.org; Mon, 29 Mar 2021 10:35:55 +0000 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616942523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D54Z2PmLCo200yXOSvaj2hVPC2HaVunYq4YcYHV7CLI=; b=nOSANqfo4EtIMAP5mGifyuzW2Af52m5HsKAtyMqUUKMzc0XR6FoAXid/2jQwT1JZL0bk7z XPx6W8UmnTT3Jx8MOw6POYFwlaSRgC40XHyAM5M5FsbPbyOmckgM3CeZ6439glilf+vtSq sV/a3k181wHYDoGE2YkUj9wK8HnMhNzpeJaVEDbXe5/Xjgk8QNWJBHO+6uqjcNoR+FXFCZ yESHY04k4zxypQtFZ8DrCTzA11YAhm/q9JYc/rH+HEA/Aq5HxI9j53+8VORvF9pvloSBK+ YRfZClUyO8fKSqfnrPgq+eK5DxXnt0UkMYLx1a/LsXp/dt707mjcotvIBxFSaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616942523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D54Z2PmLCo200yXOSvaj2hVPC2HaVunYq4YcYHV7CLI=; b=2/R47s1sLunWDFbaoDjixBAOVW6iJ5IR9uZH6pLWwX8sxIDwqn63g4zVRcfcZhQBqAGFeV mga+yqnJjOZqMqCQ== To: Kees Cook Cc: Kees Cook , Elena Reshetova , x86@kernel.org, Andy Lutomirski , Peter Zijlstra , Catalin Marinas , Will Deacon , Mark Rutland , Alexander Potapenko , Alexander Popov , Ard Biesheuvel , Jann Horn , Vlastimil Babka , David Hildenbrand , Mike Rapoport , Andrew Morton , Jonathan Corbet , Randy Dunlap , kernel-hardening@lists.openwall.com, linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 3/6] stack: Optionally randomize kernel stack offset each syscall In-Reply-To: <20210319212835.3928492-4-keescook@chromium.org> References: <20210319212835.3928492-1-keescook@chromium.org> <20210319212835.3928492-4-keescook@chromium.org> Date: Sun, 28 Mar 2021 16:42:03 +0200 Message-ID: <87eefzcpc4.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210329_113554_367133_9D1C7BC1 X-CRM114-Status: GOOD ( 15.68 ) 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 Kees, On Fri, Mar 19 2021 at 14:28, Kees Cook wrote: > +/* > + * Do not use this anywhere else in the kernel. This is used here because > + * it provides an arch-agnostic way to grow the stack with correct > + * alignment. Also, since this use is being explicitly masked to a max of > + * 10 bits, stack-clash style attacks are unlikely. For more details see > + * "VLAs" in Documentation/process/deprecated.rst VLAs are bad, VLAs to the rescue! :) > + * The asm statement is designed to convince the compiler to keep the > + * allocation around even after "ptr" goes out of scope. > + */ > +void *__builtin_alloca(size_t size); > + > +#define add_random_kstack_offset() do { \ > + if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ > + &randomize_kstack_offset)) { \ > + u32 offset = this_cpu_read(kstack_offset); \ Not that it matters on x86, but as this has to be called in the interrupt disabled region of the syscall entry, shouldn't this be a raw_cpu_read(). The asm-generic version has a preempt_disable/enable pair around the raw read for native wordsize reads, otherwise a irqsave/restore pair. __this_cpu_read() is fine as well, but that has an sanity check before the raw read when CONFIG_DEBUG_PREEMPT is on, which is harmless but also pointless in this case. Probably the same for the counterpart this_cpu_write(). Thanks, tglx _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel