Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4533746pxb; Tue, 2 Nov 2021 11:15:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYx4WiTFm9yA+2tP4NfAEXnXhc4CW54eibau1U0ffj2B4oasdRkD05uFoP/gO0pgALPouI X-Received: by 2002:a05:6e02:1686:: with SMTP id f6mr26150200ila.123.1635876959772; Tue, 02 Nov 2021 11:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635876959; cv=none; d=google.com; s=arc-20160816; b=dTR6pHYxAArJKqO8/wdsn2dam2FlUWDOIvwwyApRyLjcOHfMLUqo1gbNX5YP9p5kTI Lk3GIYwkr+Pjim5/BwAZPZ8O7tjqCkMPGLw7f6T6lXFt8Vhd4XbXD6IqLWlmNaBpltkf p6YCMAhahj3xtdYg9A8pR6o+HaNjTB4wmv2iIjhug3n/82HbFHRJXI2c9j9SmMv0E+MS dAoAeG++GlZ4x5XD1dWOOrRHcRD4CgLbVbmjoj92D1Vu4rj7dXy4i2AGUiRANjLB1UfT 1y40jcCh5B4a/iOaEqoUXbA3b30jvaHCZIhfoEpdsaYVBpUuBur+a5kGjeMR6uuz9Mmd bhyA== 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=apcnU7ismDMGqhT244nxT/5OUNxzvS18BDxORL1RIIY=; b=Y/Fp+o/Buqxu//2jXASK92g6PYwLCBBBRZC3jLcnQtx7DY3mpt7z+Uy9fcGuxx5d9M 0zq6NRx1FIs1T8ra2fmE2uuYOyF3j3lj7a1IRNxDBHm2VHFQoNHpW31XFUiU1dcvJhf4 6LrCJ5A3rCmA5oNc9n6Z+KoJtPHkGW2+xS1ECTXI/cZBiu+F7LUu5V69uDK7+4urFQGB 1dQawldLYeans/OeDYX7wCQRbAJFBDPYpEmPvakeIcRv0M+va4eBpOIx5CjKoGeWcO4Z kH6fGnyooGmj9w1P3251i/ridXsF/e9z5O6HebvxsQHz1v2s3vqTX+UyWVlhSTKLRHWj +hTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=UG4CE4sK; 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 u18si31350594jat.31.2021.11.02.11.15.45; Tue, 02 Nov 2021 11:15:59 -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=UG4CE4sK; 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 S234922AbhKBSRZ (ORCPT + 99 others); Tue, 2 Nov 2021 14:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKBSRY (ORCPT ); Tue, 2 Nov 2021 14:17:24 -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 3B773C061714; Tue, 2 Nov 2021 11:14:49 -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=apcnU7ismDMGqhT244nxT/5OUNxzvS18BDxORL1RIIY=; b=UG4CE4sK5Ph3+yQomBR8Ofbygx eJa7ofiHw6NzIXdD4e6gpwxgKNuX+K8zMLnbBSwNvYv7Drxs69Pi6IJSGBvTzwoYPDMiYxVLX7q+V ZbEitT0HDCnIBbrhgtuIaGeBlVdHCqQZJFPuxwAYfaRBeF9tuHz5eMMds4TJI3C1o0WpSOIizc6+j /qrDzfCuj4GBmgzQNxirtD+fCwTIlPTCePR8lz5CCCQSCET4LLLQyraaVhd5LNobwCA2G9ZOKnRiU mtJrBT/t4ldrqDZ2JNpRvInKHzqe4pNQygTuOI6FJ3p9n6GXGNdATh98C0jxFwu0/U6n0o0ARB7QG TsRm3gzA==; 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 1mhyIl-00DnQw-75; Tue, 02 Nov 2021 18:14:27 +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 4EA0C3000D5; Tue, 2 Nov 2021 19:14:25 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 33DF22D53269E; Tue, 2 Nov 2021 19:14:25 +0100 (CET) Date: Tue, 2 Nov 2021 19:14:25 +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: <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 06:44:56PM +0100, Ard Biesheuvel wrote: > On Tue, 2 Nov 2021 at 16:15, Peter Zijlstra wrote: > > > > 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 > > > > > So are these supposed to go into the jump tables? If so, there still > needs to be a check against the boundary of the table at the call > site, to ensure that we are not calling something that we shouldn't. > > If they are not going into the jump tables, I don't see the point of > having them, as only happy flow/uncomprised code would bother to use > them. I don't understand. If you can scribble your own code, you can circumvent pretty much any range check anyway. But if you can't scribble your own code, you get to use the branch here and that checks the callsite and callee signature. The range check isn't fundamental to CFI, having a check is the important thing AFAIU.