Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3890998imw; Mon, 18 Jul 2022 16:53:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQdAuk2qo9kaDte7h2VujFY2TRS/l5wd8Avyvslk47Z5WkbQsdbl6RemDflbZrGT6rppAp X-Received: by 2002:a17:906:dc8d:b0:72f:2993:ed84 with SMTP id cs13-20020a170906dc8d00b0072f2993ed84mr7622452ejc.251.1658188394146; Mon, 18 Jul 2022 16:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658188394; cv=none; d=google.com; s=arc-20160816; b=UNGXIkHGFHovGrBwaxuctmFG+CUjdmfHouU+G7jTfR56ZuVk77J1Y3x261dv515Roc 8zyUlZvF9Ekf1ad52ORFqjKxFipyZrGer042NwJuluvkre99vrLoHsLCOf0jFfxnM8y9 /9z4fx6n3cOyGKb+SuGSJJngvA2ZOx1xc3iXA9pXWznhTW0uVtlXx/AP+iLmgsEYGY2f N9qd1W1Yrgi5KlpgDB0blAGAU4qHLrW2tSyYw3yGZed0uGr0Pni+leXKE8JsiMaKdZgw PtlgesqFCy7tOIYFy2jaPnS8hu635p1G+zTIlI/NWqrdn79v6MRr9VAH3ywXFmHBM9+D 13hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=wZSpOTDestuFHoUeoXRQFtReCw+twh88oerHixDKi5U=; b=iinCjuf21Y/0TjhyQ903LHPXmXarEtlAMdCVjFge5j92W1CAg4a4NSFlmqTCO122Ay IIM5iRIfRAFpY+5+6mNxFKf2258pRlrIMhsIxJg26EINPWnerLgoOR8RX1Vd2h4MIaHC db6+q8IBVWLVJlFvbh+2TH9c0VRp4vydKh/hthH4XU1St9MFxZEAMKZdMIjv9oBh6kUb H3p9Ms65rznvfj+SS55TNfrWJvgWZGVvWm7TTktNMxkJ0Cqg/RcMyQYWPuDvufd5axAt NTFhDTEq2Kfh/Q7L4QO5rrvuPpt6PJVDzd0hxRKny9VM8u39JAhw6dRu9bUy1UMt8DQO S1sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="euqTh/FF"; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a056402254d00b00435c0205537si20623881edb.29.2022.07.18.16.52.49; Mon, 18 Jul 2022 16:53:14 -0700 (PDT) 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; dkim=pass header.i=@linutronix.de header.s=2020 header.b="euqTh/FF"; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233865AbiGRXTg (ORCPT + 99 others); Mon, 18 Jul 2022 19:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233585AbiGRXTf (ORCPT ); Mon, 18 Jul 2022 19:19:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBBA42CCA4 for ; Mon, 18 Jul 2022 16:19:34 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658186373; 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=wZSpOTDestuFHoUeoXRQFtReCw+twh88oerHixDKi5U=; b=euqTh/FFDOit4+8O7vcor/ydhHgIRcJBqk+XMcwF7TVPkPkd8ItPG3x3zN2q7K8pu159SN q4VJt7JHNgfnK63lfROQD2ipqlbtTb9/dhVtPP+DEszkae7NmbFgoNnP48BbDrZ+0P34f/ 2IZ36TwZQStkGdbl89P4rbou1xT9QDmwVbcWRFsYlkrKTsTfAjMgu84WyTbZWIWkiH/GRG WGUPsLbyPFU7jwi7j7jSKOTWlACD68e4tIoDynqueD2+U1sEF+0iXBrKH54GlIOO5ztJk/ DLrXZII6hygYeLBaqWLNQB1hAAxrIXFT7BFwE5tbV2390TilJisz87zRdevp2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658186373; 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=wZSpOTDestuFHoUeoXRQFtReCw+twh88oerHixDKi5U=; b=IHBwpJ5ObJ0cwe/woJNYdLuxKXTt/NMUiN2PY7SfIbx0B31YCVGjm50Y7XPCt0Z2FTBrkZ iBcqzAjhkTLq8WBg== To: Sami Tolvanen , Joao Moreira Cc: Peter Zijlstra , "Torvalds, Linus" , LKML , the arch/x86 maintainers , Tim Chen , Josh Poimboeuf , "Cooper, Andrew" , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , "Moreira, Joao" , "Nuzman, Joseph" , Steven Rostedt , "Gross, Jurgen" , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann , Peter Collingbourne Subject: Re: [patch 00/38] x86/retbleed: Call depth tracking mitigation In-Reply-To: References: <20220716230344.239749011@linutronix.de> <87wncauslw.ffs@tglx> <87tu7euska.ffs@tglx> <87o7xmup5t.ffs@tglx> <87lesqukm5.ffs@tglx> <2f7f899cb75b79b08b0662ff4d2cb877@overdrivepizza.com> Date: Tue, 19 Jul 2022 01:19:32 +0200 Message-ID: <87fsiyuhyz.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Mon, Jul 18 2022 at 15:55, Sami Tolvanen wrote: > On Mon, Jul 18, 2022 at 3:47 PM Joao Moreira wrote: >> Thus the hash will be 6 bytes before the function entry point. Then we >> can get the compiler to emit a padding area before the __cfi_\func >> snippet and, during boot, if the CPU needs the call depth tracking >> mitigation, we: >> - move the __cfi_func into the padding area >> - patch the call depth tracking snippet ahead of it (overwriting the old >> __cfi_\func:) >> - fix the cmpl offset in the caller >> >> func_whatever: >> ... >> cmpl $0x\hash, -FIXED_OFFSET(%rax) >> je 1f >> ud2 >> 1: >> call *%rax >> ... > > The problem with this is that the cmpl instruction contains the full > type hash, which means that any instruction that's FIXED_OFFSET from > the cmpl is a valid indirect call target as far as KCFI is concerned. > -6 was chosen specifically to make the ud2 the only possible target. But that's an implementation detail, right? Whatever we put in between will still be a fixed offset, no? It's a different offset, but that's what patching can deal with. Thanks, tglx