Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6080851rwi; Tue, 18 Oct 2022 07:55:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HMowDb5oEOHDWNzWJo/jeeGQ1QX7qONRP03+Ue5Rs48NQM+PeVjYfYdUfmX/QfjncefxO X-Received: by 2002:a63:c5d:0:b0:460:17cc:73a6 with SMTP id 29-20020a630c5d000000b0046017cc73a6mr2975962pgm.332.1666104934102; Tue, 18 Oct 2022 07:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666104934; cv=none; d=google.com; s=arc-20160816; b=Ac56KM7vfQeBkrwKmpsUqTHeZ0+txcgjLpDoXQPP0DnQfZBUhXVPER0eIDSeW8MqoE wuj2Ju4FOhJW6VJ5V7cvPk2Wl+Rc/YzoKz8xqWDak6Y3Dp/St1twNHjEh8gB1QVB7MSv 7mTuFFQlqfvvGGAxtfL0g8H5KV6wXNsSmVHPZhwe+Yyiq6fBUpYeM5If0ncHbpYSuWry jDAEbKJoVezrqFU5teJ5kWvobskpxFEskyn8vIYN+lEnlaPaOd5u8mSurUJN/ybKjgh0 Hry+vkX71m3IQtlErT90A8pd03nt5SxNj0S2N/uUfPnKkHzoO6IOsejsmKdl6CMMxyr2 +4tQ== 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=kzV0xBAqYeM4CQwWeNDGhj3bcn64aQixREWVnecx2HM=; b=vnuoUg2ckeRYY82TEHpDeZ5JNyhMcL5gXeJx5GFWr7HlEWERi18VkvLUbHKydaMKev p8bmhCO8VF+68Yv8n+V5wtlrWSJGpqpar54/zCE0KrTy+UA0sO2Q0RwQx1qa55UhvG8f r7t3yx57gnp59653gbfqqgcGnYQ/TG8NA7eR9riN2I6ed6lDtYsd+0opUP4uHTTLclPq iDvyNPvzPueMFbHV/SqznrzmIOJ51rmJ3dkx9LmWF/1LncF9xwnN03bNVIG60Rx84Wj0 jtvitoGM41g8vHXf1zsyE+g1vnWlcJCReZCxaqxTGdVKv7Wx9rQOnMiOkZ1HmG5RMr3W c4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=A8QuBlfR; 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 m2-20020a656a02000000b00452bad3abcfsi18514727pgu.324.2022.10.18.07.55.21; Tue, 18 Oct 2022 07:55:34 -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=@infradead.org header.s=desiato.20200630 header.b=A8QuBlfR; 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 S230304AbiJROr4 (ORCPT + 99 others); Tue, 18 Oct 2022 10:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbiJROry (ORCPT ); Tue, 18 Oct 2022 10:47:54 -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 59722D77D5 for ; Tue, 18 Oct 2022 07:47:54 -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=kzV0xBAqYeM4CQwWeNDGhj3bcn64aQixREWVnecx2HM=; b=A8QuBlfRgB25HDjMK4IocfrsXD wyyXHFkYBUs5q97tTqDN0N315gQAf/x1EgMRPsKsqL/7QV6SFd7OSvCiS835qW5/+61jFxIbQvTqM V82EzDqhW/qvLsDd8C0fwuEwSLRQRMGR6nyBtGzdYEPiyBBOoZZQwLjDvMS3znCT9mpoHfl7kLKHw 2+8LZyO+s5KT7k5S9Zs7bRJhTrqf6RgF7PeGr3mbFSj6VkdfU+MrFrqh9erMS+6Rf3cYCSzkcnTZ1 aTBygXewzNwcIo8Dog4dhNye8nDW1/GmzGjuc++JronxavbDf8KI76YH5jmJIevvdvqNzh5ZJdA2s QdDK9maA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oknse-004VeC-Ti; Tue, 18 Oct 2022 14:47:45 +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 (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7CCA130012F; Tue, 18 Oct 2022 16:47:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 550482133E7EC; Tue, 18 Oct 2022 16:47:44 +0200 (CEST) Date: Tue, 18 Oct 2022 16:47:44 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: Kees Cook , Sami Tolvanen , Joao Moreira , linux-kernel@vger.kernel.org, Mark Rutland , Josh Poimboeuf , "H.J. Lu" Subject: Re: [PATCH] x86/ibt: Implement FineIBT Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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_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, Oct 18, 2022 at 03:35:50PM +0200, Peter Zijlstra wrote: > +asm( ".pushsection .rodata \n" > + "fineibt_caller_start: \n" > + " movl $0x12345678, %r10d \n" > + " sub $16, %r11 \n" > + ASM_NOP4 > + "fineibt_caller_end: \n" > + ".popsection \n" > +); Note: this hard relies on the indirection using %r11 and %r11 being clobbered by the call-abi. That is, there is no expectation on the value of %r11 after this. If GCC were to grow kCFI support this needs additional changes; one option would be to use the 4 byte nop to rewrite it into something like: movl $0x12345678, %r10d movl %[reg], %r11 sub $16, %r11 > +static int cfi_rewrite_callers(s32 *start, s32 *end) > +{ > + s32 *s; > + > + for (s = start; s < end; s++) { > + void *addr = (void *)s + *s; > + u32 hash; > + > + addr -= fineibt_caller_size; > + hash = decode_caller_hash(addr); > + if (hash) { > + text_poke_early(addr, fineibt_caller_start, fineibt_caller_size); > + WARN_ON(*(u32 *)(addr + fineibt_caller_hash) != 0x12345678); > + text_poke_early(addr + fineibt_caller_hash, &hash, 4); > + } > + /* rely on apply_retpolines() */ > + } > + > + return 0; > +}