Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10322562rwl; Wed, 11 Jan 2023 18:25:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXuZ9Wt+Ur+bVIvdqTWU86aSk5vqyeE4xdDr9BYKXw/8UofbxlcJCulLKfvi6+r7FrIuhzTW X-Received: by 2002:a17:906:36ce:b0:838:1b80:9a7a with SMTP id b14-20020a17090636ce00b008381b809a7amr62205820ejc.12.1673490309341; Wed, 11 Jan 2023 18:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673490309; cv=none; d=google.com; s=arc-20160816; b=QjKG8PmlktyAtEsZOZmLLZTqvXG1lat1CzHozL/gx0LCopLwcmb0FnBvkpBwWkM3yY iSIbKa9gsWBO/9/h2/AuKVW9MvWu5lclaXbrVr6teCidXcHl5AfM9WB5YO/c5Xi0GH6Z caa7SonV+qyT+FpcBjpgOE4sEfA+llIsLOtqoopY0h+6Z1JFbQGN4gHkoeCXBiKzaFb2 auGpfu+zwggdeZijz1kLJJYYAJoDBdZjfzEtgL2hYhad8ub1JPiiSAU4PsGO/c3/8XhQ UL11OtJ5t+9h6MGDAuGX97bHMOPD+NRK1J2BA5EJGEB1CH0OSupvBUBQH/L6Y/9M4Z9+ k/OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=Fv3Y2mhP7BVcbgbyio+YwarAJc0e1siveG0VlfGMxHI=; b=fzGZtynzfNyc/R0fh81Y1mKuAuNWKea30xnW4jgjTkz8C7IJOPr5mc8yPToGDDqJxO op7mEvq4wTBcWoIm7LKkcs9v4f5P+MSpLIkaB606fGxaP8RN3GF1Vx3pxtlvFb9TDQ6K AxNuZ0D8tsoZ7eqb9KFgWkqH3ZvtqOBgK7QGUMFwZdXxs2Mgble1ceDGdUb+TH1/uGGC C2GmerUqgHBWniPMG7u4Ff+bQlSsQP/fcRlF5nAytTKZMtipeYKyyJWfa9gV6tN+iV+4 GhMDDc62XRrw1A2PjZXWyDhlIKtFIlNrQa/rSalWmLo3kC8/HP3lQQX0SJaITOObqNS7 ymVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb13-20020a170907160d00b007d97d797c8dsi19619476ejc.215.2023.01.11.18.24.57; Wed, 11 Jan 2023 18:25:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235689AbjALBee (ORCPT + 50 others); Wed, 11 Jan 2023 20:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234565AbjALBec (ORCPT ); Wed, 11 Jan 2023 20:34:32 -0500 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4D6B927186 for ; Wed, 11 Jan 2023 17:34:31 -0800 (PST) Received: by angie.orcam.me.uk (Postfix, from userid 500) id ECDB692009C; Thu, 12 Jan 2023 02:34:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id E5A1E92009B; Thu, 12 Jan 2023 01:34:29 +0000 (GMT) Date: Thu, 12 Jan 2023 01:34:29 +0000 (GMT) From: "Maciej W. Rozycki" To: "Jason A. Donenfeld" cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] x86: Disable kernel stack offset randomization for !TSC In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 Jan 2023, Jason A. Donenfeld wrote: > > Index: linux-macro/arch/x86/include/asm/entry-common.h > > =================================================================== > > --- linux-macro.orig/arch/x86/include/asm/entry-common.h > > +++ linux-macro/arch/x86/include/asm/entry-common.h > > @@ -5,6 +5,7 @@ > > #include > > #include > > > > +#include > > #include > > #include > > #include > > @@ -85,7 +86,8 @@ static inline void arch_exit_to_user_mod > > * Therefore, final stack offset entropy will be 5 (x86_64) or > > * 6 (ia32) bits. > > */ > > - choose_random_kstack_offset(rdtsc() & 0xFF); > > + if (cpu_feature_enabled(X86_FEATURE_TSC)) > > + choose_random_kstack_offset(rdtsc() & 0xFF); > > What would happen if you just called `get_random_u8()` here? Thank you for your input. I've had a look at the function and it seems a bit heavyweight compared to a mere single CPU instruction, but I guess why not. Do you have any performance figures (in terms of CPU cycles) for the usual cases? Offhand I'm not sure how I could benchmark it myself. I have made a patch and of course it makes the system boot too, although it's not clear to me how I can actually verify randomisation works. I can assume it does I suppose. Maciej