Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4372611pxb; Tue, 2 Nov 2021 08:40:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3A/c6Lg9hvm2a6xNMf0B+kdz0F7qHzzArZMgbF3uSyNAz1IXbUmMCNWpaZjHK/YZCHSeS X-Received: by 2002:a17:907:3fa5:: with SMTP id hr37mr49335253ejc.417.1635867605553; Tue, 02 Nov 2021 08:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635867605; cv=none; d=google.com; s=arc-20160816; b=pJZ06X5woPgZQVAieo/Fi0QW9LFDL7v0i5ublzpC7ieeBUuYWRQl39X8OGisvH+BE5 U7ilJEwo7yw2m/8VZTVjArwtjYFepCE0bpd3jLiuRxO9+6CaSASSgUuc7/hylp1OvhTf GnSottQ3tRYYoCok1LUMA7Oc2BZu21uzMOSsYSP5B4Z2hQ+9o54clXf/zQ5GwXjcnYxG dF7pmPLkL8aKRSfXhKfVdtLmiSMO9PDY/BgR9o/i7M+yB64UM+0PFOjGgtCp8B7+bko3 gF2CT3FIQm4D93PKR5d8put8B/3/ob6yKp5ljj7NSH46TLnWPHAt4VifptfNPkdjdbRo Kklw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Lji0Q0mKscbCR4s6xv/OULJVtCJGnkPpvCozvtfPKyM=; b=lilzXpQXodlaZJiP6/olOOfiidbpz4KfC+V1WiI7VMU5/o1SpGYhjJcHa09lqYRaYf W/OTY21bW6C6yswUyUCqeBEK2XShngglTRjJ35UxaDeW81wtLnHC4/O9a0epH1kGDc84 h4lXrERFKb/VPRL+iBn7Qcp7WkcVxX+D2scKpZ/ERzio0ejwDmP0xDbuls5T8LbPvy7q TCDqYPjWu0Jhs4h+wihoy1Dm4ExYt78eD/3c8vt54RCa8P5+n+UTYRo1gnvsZN6TsBkC wb3OY3ct0wNnJ0HWNkjYEDEOih2PaObnikDPU+MioKP1g9Kn4putrU3sOPSfp8FOmk9G gyfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=rQyjFmdA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di1si8495162ejc.772.2021.11.02.08.39.40; Tue, 02 Nov 2021 08:40:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=rQyjFmdA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234288AbhKBPS3 (ORCPT + 99 others); Tue, 2 Nov 2021 11:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234185AbhKBPS2 (ORCPT ); Tue, 2 Nov 2021 11:18:28 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E05A3C061714; Tue, 2 Nov 2021 08:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Lji0Q0mKscbCR4s6xv/OULJVtCJGnkPpvCozvtfPKyM=; b=rQyjFmdABWfQuxVIFtBoZm6409 f7Q8mBnnIbnhARKu8AfsBA+4oU06whRCygb0Kmatd7/iZv1bYZsEWfsGsixFCGVYvb84ZDTeWPrCp Q6jCl/jLsDBIJ0mcDOI6pJvQ8RlkyBRHWj8FjpOu/YcCrGs13flAN4Igvu4smCRzFdUkiQYzuSUb1 6es1pUMYkJOvoNjyCsH0ehnNGvmn8bAy43xYzwsGy3VH+5/D/uiBNNq0DomJQKUaKqwYD21X2okrq VEuxt2Gfwz+P27cZgCnyOIvyi6YhiZE/m01nwh44rhuizmTlrOLtuZ0qOfiu//1K+/L7/4sth9g6M 5L7zz5Wg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhvVb-00DluO-H2; Tue, 02 Nov 2021 15:15:31 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 989D1300366; Tue, 2 Nov 2021 16:15:30 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7D7AA2D5FE2D6; Tue, 2 Nov 2021 16:15:30 +0100 (CET) Date: Tue, 2 Nov 2021 16:15:30 +0100 From: Peter Zijlstra To: Ard Biesheuvel Cc: Sami Tolvanen , Mark Rutland , X86 ML , Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, Linux Kernel Mailing List , llvm@lists.linux.dev, joao@overdrivepizza.com Subject: Re: [PATCH] static_call,x86: Robustify trampoline patching Message-ID: References: <20211031163920.GV174703@worktop.programming.kicks-ass.net> <20211101090155.GW174703@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 02, 2021 at 01:57:44PM +0100, Peter Zijlstra wrote: > So how insane is something like this, have each function: > > foo.cfi: > endbr64 > xorl $0xdeadbeef, %r10d > jz foo > ud2 > nop # make it 16 bytes > foo: > # actual function text goes here > > > And for each hash have two thunks: > > > # arg: r11 > # clobbers: r10, r11 > __x86_indirect_cfi_deadbeef: > movl -9(%r11), %r10 # immediate in foo.cfi > xorl $0xdeadbeef, %r10 # our immediate > jz 1f > ud2 > 1: ALTERNATIVE_2 "jmp *%r11", > "jmp __x86_indirect_thunk_r11", X86_FEATURE_RETPOLINE > "lfence; jmp *%r11", X86_FEATURE_RETPOLINE_AMD > > > > # arg: r11 > # clobbers: r10, r11 > __x86_indirect_ibt_deadbeef: > movl $0xdeadbeef, %r10 > subq $0x10, %r11 > ALTERNATIVE "", "lfence", X86_FEATURE_RETPOLINE > jmp *%r11 > These two thunks could of course be one big alternative. > And have the actual indirect callsite look like: > > # r11 - &foo > ALTERNATIVE_2 "cs call __x86_indirect_thunk_r11", > "cs call __x86_indirect_cfi_deadbeef", X86_FEATURE_CFI > "cs call __x86_indirect_ibt_deadbeef", X86_FEATURE_IBT Also simplifying this. > Although if the compiler were to emit: > > cs call __x86_indirect_cfi_deadbeef > > we could probaly fix it up from there. > > > Then we can at runtime decide between: > > {!cfi, cfi, ibt} x {!retpoline, retpoline, retpoline-amd} >