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=-3.8 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 4F534C433ED for ; Thu, 1 Apr 2021 22:46:03 +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 BB03E610F8 for ; Thu, 1 Apr 2021 22:46:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB03E610F8 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=xGsq2Snhr6A8prH5iaYs7OGp1k0VbL8woTkssIlimLE=; b=nLEUhMINtuHIm3TOIm+tC5qFx 1TlH0mZ9nOPyNe3kjrdnisLQf3Sl1QRWqea5u7Q71zlFvWJKfAowkTYSZoh45pag0qoIq8Ifk6a3B yFgqALV/wsZZKVvy5U1RrI7htneJtCFa0wio7JNbojt6WS8GmxJHAt8tblpy1qtRVp//AzlQ0BwPo 0zuuyXDPCXBOudcFxA+4Q6M/g1flcj6VQdznTACPWlx81kqU/0O7/wdU7pld38qsN2xx+gztJKrTZ vVhK67tIZbY42CeSZnz3u+xkzwjKpsEnksQfWoojLJ6s//vGITrZASlbV5nS7pwW6u+hWaoZ35Wbe /IpGhyMkQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lS61E-00BEEa-Qr; Thu, 01 Apr 2021 22:42:29 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lS611-00BEDD-9g for linux-arm-kernel@lists.infradead.org; Thu, 01 Apr 2021 22:42:26 +0000 Received: by mail-pg1-x534.google.com with SMTP id f10so2473490pgl.9 for ; Thu, 01 Apr 2021 15:42:12 -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=XHU/CSlbR0tXIQ7skc+D9M4sQ8Nf+DFxpytkWh85RTc=; b=Cdeb4TJryjuUvq0PZ22+p9aZ80XrqpLOQqZBbyxQf2b3KNvemF9hZdYHkWk2rvgvr9 +SpPIdq+JMo2g9UMPmRHYMNVYDXvm5KREo94cbMizN1C/uol3pIjbIlmE2pjHUirEook l3tfPMZVPC0JP0fRuhcSZ92o1n77ukI4HC3SY= 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=XHU/CSlbR0tXIQ7skc+D9M4sQ8Nf+DFxpytkWh85RTc=; b=H0rUh+lVdd3PgJfuwMq+XzFokBEs17MgWuzaXqcESeQfQx3F0sfge8Kax7Y1a7OYlQ 5r90Gme3Wt2dUFZ71dhFcLK9yLj9ywFo/on9j6GXM7Iz7WOKrtRFVuIpsvmWr6aIJRvQ JKN3Gklts8YZmGyJCb7eniSH6KwTuGkuXotD2d5RAjbASiLLCYhe5LZClHXu4doEkSDP h1EY6ASQXqGkpelOxeLsWgyPNm1J1nxb3Bv2ZZ51tPzDIn+0pnKehEczEJ/mE33bZqPd Vifq2hRQhDJM8TiaKOpSpoGrrWNfh44q+PPj9QCO4/BHIjPFar2Xf5v0e65D/iiort6a tlXg== X-Gm-Message-State: AOAM530/CONV49JQhQMgygIVY0/yjziVtU/mBQr+wSMcdldQOCXDkMy+ O8oLheDagr7L/HKwp2SwKSWrkg== X-Google-Smtp-Source: ABdhPJy5OYaYtgibg+iSJ6TbNgMEMp0Li4wFRje6LCbJMZHyUSADLtOfsJcpWv8pBVkoh3+T2eGIQA== X-Received: by 2002:a65:56cc:: with SMTP id w12mr9470880pgs.354.1617316931239; Thu, 01 Apr 2021 15:42:11 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a7sm6246426pfo.105.2021.04.01.15.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 15:42:10 -0700 (PDT) Date: Thu, 1 Apr 2021 15:42:08 -0700 From: Kees Cook To: David Laight Cc: 'Will Deacon' , Thomas Gleixner , Elena Reshetova , "x86@kernel.org" , Andy Lutomirski , Peter Zijlstra , Catalin Marinas , 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 v8 3/6] stack: Optionally randomize kernel stack offset each syscall Message-ID: <202104011447.2E7F543@keescook> References: <20210330205750.428816-1-keescook@chromium.org> <20210330205750.428816-4-keescook@chromium.org> <20210401083034.GA8554@willie-the-truck> <61ae9398a03d4fe7868b68c9026d5998@AcuMS.aculab.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <61ae9398a03d4fe7868b68c9026d5998@AcuMS.aculab.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210401_234224_382033_F1A09360 X-CRM114-Status: GOOD ( 25.86 ) 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 Thu, Apr 01, 2021 at 11:15:43AM +0000, David Laight wrote: > From: Will Deacon > > Sent: 01 April 2021 09:31 > ... > > > +/* > > > + * These macros must be used during syscall entry when interrupts and > > > + * preempt are disabled, and after user registers have been stored to > > > + * the stack. > > > + */ > > > +#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); \ > > > + u8 *ptr = __builtin_alloca(KSTACK_OFFSET_MAX(offset)); \ > > > + asm volatile("" : "=m"(*ptr) :: "memory"); \ > > > > Using the "m" constraint here is dangerous if you don't actually evaluate it > > inside the asm. For example, if the compiler decides to generate an > > addressing mode relative to the stack but with writeback (autodecrement), then > > the stack pointer will be off by 8 bytes. Can you use "o" instead? I see other examples of empty asm, but it's true, none are using "=m" read constraints. But, yes, using "o" appears to work happily. > Is it allowed to use such a mode? > It would have to know that the "m" was substituted exactly once. > I think there are quite a few examples with 'strange' uses of memory > asm arguments. > > However, in this case, isn't it enough to ensure the address is 'saved'? > So: > asm volatile("" : "=r"(ptr) ); > should be enough. It isn't, it seems. Here's a comparison: https://godbolt.org/z/xYGn9GfGY So, I'll resend with "o", and with raw_cpu_*(). Thanks! -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel