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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 75C51C433DB for ; Tue, 30 Mar 2021 00:09:40 +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 0F7E26192E for ; Tue, 30 Mar 2021 00:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F7E26192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4V1njN0Ql3KNpVkKf0AqIZRLi+VqfDtJGEWAexiX3Uk=; b=eHJI8ODd+RJOBqPMVYYhKTLoT 7fmZ3JMIOcrWDofbSFpK8acghP876+CdSSpA9XueQUKDSmjM3VXQpOT+OtZ9L7aKYHebmwUyOFjuV GUpwjPjPaFRgmbYojKpIuAfq6FptER6s6xbQ6duudSDCd6GqZEYpQ+qzUDrGAMy1utGC1fB7pdwW5 lOtdiAfEjemzU1yxUioQUEBUKQffuKgFhNEv/xO6fYqbAc0gBlfu+kTkXjslVVwLDCG5PQ+RGuAAv WdgNUtEF+TrhqnOds9vnugQlwA8VpoI6J0rB5U6WRdr3uOepWWj0yakTnztkOp0UoVybzSxtyg3Ef rCMJj6VRQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lR1tz-0026zq-Mv; Tue, 30 Mar 2021 00:06:36 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lQwpH-0015qR-Ig for linux-arm-kernel@lists.infradead.org; Mon, 29 Mar 2021 18:41:26 +0000 Received: by mail-pg1-x52c.google.com with SMTP id t140so2642557pgb.13 for ; Mon, 29 Mar 2021 11:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=aYL/dbQ14QTXXMSkWSQ/z+qzj6yL6Ve3lzeO159+/Vc=; b=ILRNFBaUrvYS27aWFLaYXO8LPj6pKTA2SBD59ksr9Fpfa7kG44gHIoQIIeiA0uW0DT INDEJxHCxLo9mNI1mXPwmIRMdAheSsDUl9E7dL0goqI8aLORifPfviS8NWFxCGPsRDpU h2HExNb2DqeqeKKnXrybXZvXygAADq2smXaJA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aYL/dbQ14QTXXMSkWSQ/z+qzj6yL6Ve3lzeO159+/Vc=; b=qV7OU8LyPd1SEfbH4XiDkTlks11cOnLdEQh0I9NjaKdP13BUPGHgZpDmEDdc6qPKIM s9vziZ4JALHXbHDH6vYfZGYdfFpe+cwL1pWpiyxoJ6nVnZmF25xQpGCAz9fztQFhGX7x mVFDDF/9b3LalmwFUFpGWi9ClCqLo9N9rxU20/rbCmkjJ4shQXVv71o8NqdmdJSHJ9SZ cT2vY1N3jRIFLrK3A4ZCBK4Ox2Q3QjKEV2qEsotLkPcoMtbk+DfhgikILs6SXy15qD5h jLckH0498EuNmfhKKpHkX1QX+y9HK2nDEiMC1CFv4uJGA4DvFpQxmSNdC1HQAmDf+aqL yIrA== X-Gm-Message-State: AOAM532KzvmwCpnd6lrgwsVwn8gYSzW3t41K7bNpbgjanbSsOuV9QdFU 8aj2VpP69IqWZL494c9DX/ChdA== X-Google-Smtp-Source: ABdhPJxjjtBRwQY4aFK1R1QLvwpTRJ9D0T4m5/43mE5p+szS6JXZVD5wBPAm/iQ4MzX4uEt8W4cEIA== X-Received: by 2002:aa7:8a19:0:b029:1f6:6839:7211 with SMTP id m25-20020aa78a190000b02901f668397211mr25877536pfa.40.1617043281318; Mon, 29 Mar 2021 11:41:21 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mm12sm196929pjb.49.2021.03.29.11.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 11:41:20 -0700 (PDT) Date: Mon, 29 Mar 2021 11:41:18 -0700 From: Kees Cook To: Thomas Gleixner Cc: 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 Message-ID: <202103291139.54AA7CDE@keescook> References: <20210319212835.3928492-1-keescook@chromium.org> <20210319212835.3928492-4-keescook@chromium.org> <87eefzcpc4.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87eefzcpc4.ffs@nanos.tec.linutronix.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210329_194123_904942_ECBCFFF7 X-CRM114-Status: GOOD ( 24.29 ) 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 On Sun, Mar 28, 2021 at 04:42:03PM +0200, Thomas Gleixner wrote: > 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! :) I'm aware of the irony, but luto's idea really makes things easy. As documented there, though, this has a hard-coded (low) upper bound, so it's not like "regular" VLA use. > > > + * 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(). Oh! Excellent point. I think this will make a big difference on arm64. I will adjust and test. -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel