Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp6335607pxb; Mon, 8 Nov 2021 07:01:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXzf0Y8RantdLmwkm7RbF4WzEt49KZL1U96XXC8twolbsjsrUnc9WOkSYY+0HGttPk1qL9 X-Received: by 2002:a02:ceb9:: with SMTP id z25mr133482jaq.121.1636383702384; Mon, 08 Nov 2021 07:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636383702; cv=none; d=google.com; s=arc-20160816; b=FCL82bkeChJxMDc7w9OXn5BWS5C5cGxN6Bh+HqRxuMnCN4k1bCBq1tCz2RSwKWeu+b zMzsAMi6mVIKaec+jbkGL9iOfC+KNtfxGYRaOwI0IcuKwrerJ8Ohep5LQqhqSuROd4J7 rbk1U5m9oKCMrLU5m/AwGL4O8bYcT/UycxfI4XMdPkBaikC7KJA23wyB7kwfL9ucMcHn 6EiQ1AJLw6qErGcRhvsablFLLnupzmO6TIWXqJPEy7RRe5WJCFOImBaMAkKcQ1qcKkKk e4E8oi4Dmg01ibLdQaMmpzfyR7sAtfU3LgQmX9SvzfBe9aKFh6av5hWZOUJAJwmksxVv WsZQ== 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=5TP6wWhpgPVEkA3TsjVQnhtqFfZ4XssB8CseC+DQ6CI=; b=ITMQnD+s1DZzEtCiXJtz6ewpUqffZQhQsxtuBsZLQDUl3snWithmEp2C75jCPIwjYY VU7qZXjJ6+5wq1cAV9O3WJMbr9wNeUG5sXzrkUVIbuVzLZUgC437CUwochAG9J3hq1Vt 4G2p66kaFEKt8uceIB6mPVpToHYWrVmVcpK8AJJHMg3Fh4FpAZVuapYsN578S5Xb6DN1 Z9OD/YGFdspc27f2HVKKlHBD6j8gHZS+lK2nHlwhkSJCWhg5ttf61oC0b1NwZ7B3wjlM 13zo9dehWmwBuwyLH5g6+7ry7PAsJMktVedzbHIRgElkzEnTLxLJ5dGGZrKaI/Iz4CCS cL0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=cWJR2ikZ; 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 g2si33724301ile.118.2021.11.08.07.01.24; Mon, 08 Nov 2021 07:01:42 -0800 (PST) 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=cWJR2ikZ; 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 S235503AbhKHKLL (ORCPT + 99 others); Mon, 8 Nov 2021 05:11:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbhKHKLL (ORCPT ); Mon, 8 Nov 2021 05:11:11 -0500 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 E6DFAC061570 for ; Mon, 8 Nov 2021 02:08:26 -0800 (PST) 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=5TP6wWhpgPVEkA3TsjVQnhtqFfZ4XssB8CseC+DQ6CI=; b=cWJR2ikZKkDvMN4ptq85OMr01r HXDoOwoLhFG5ixYOULxhc2qQacei1ooewjYQbrPWAcm35wKklRFubD3kG9pr/Jd6tnUZmRlqfLPWT 47YhcSajQfcp3ZIxrFUVxmCF0rIjWH6c0ZyQEsSzKmJrrvKMGL6Q91iKghxogfWA65wZ+b1KmBakT bp6x0zNYRIEcSZ5WNCkpZgezZ6OGaCaJvNgLg8oXopOolQucPTVzt0t5S7z1/JoZ3yNlXJoJurMQU QMJ61yFibQKKp6cACwVyDAc50c85LILi9CSjhGwgAaviy+AuiHGzPLZOv9suKShjRkE5lmdZ3Sh+B RVdbSS4w==; 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 1mk1ZP-00ErcZ-El; Mon, 08 Nov 2021 10:08:07 +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 D204230022C; Mon, 8 Nov 2021 11:08:04 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7616C2D38726D; Mon, 8 Nov 2021 11:08:04 +0100 (CET) Date: Mon, 8 Nov 2021 11:08:04 +0100 From: Peter Zijlstra To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , Quentin Perret , Catalin Marinas , James Morse , Will Deacon , Frederic Weisbecker , Kees Cook , Sami Tolvanen , Andy Lutomirski , Josh Poimboeuf , Steven Rostedt Subject: Re: [PATCH v6 1/2] static_call: use non-function types to refer to the trampolines Message-ID: References: <20211105145917.2828911-1-ardb@kernel.org> <20211105145917.2828911-2-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211105145917.2828911-2-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 05, 2021 at 03:59:16PM +0100, Ard Biesheuvel wrote: > In order to prevent CFI enabled code from grabbing a jump table entry > that jumps to the trampoline, rather than the trampoline itself, use an > incomplete non-function type for the trampoline, and cast it to the > right type only when invoking it. > > Signed-off-by: Ard Biesheuvel Very grudingly: Acked-by: Peter Zijlstra (Intel) > --- > include/linux/static_call.h | 4 ++-- > include/linux/static_call_types.h | 11 ++++++++--- > 2 files changed, 10 insertions(+), 5 deletions(-) > > diff --git a/include/linux/static_call.h b/include/linux/static_call.h > index 3e56a9751c06..616607393273 100644 > --- a/include/linux/static_call.h > +++ b/include/linux/static_call.h > @@ -151,7 +151,7 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool > > #define static_call_update(name, func) \ > ({ \ > - typeof(&STATIC_CALL_TRAMP(name)) __F = (func); \ > + typeof(&STATIC_CALL_TYPE(name)) __F = (func); \ > __static_call_update(&STATIC_CALL_KEY(name), \ > STATIC_CALL_TRAMP_ADDR(name), __F); \ > }) > @@ -306,7 +306,7 @@ static inline void __static_call_nop(void) { } > void *func = READ_ONCE(STATIC_CALL_KEY(name).func); \ > if (!func) \ > func = &__static_call_nop; \ > - (typeof(STATIC_CALL_TRAMP(name))*)func; \ > + (typeof(&STATIC_CALL_TYPE(name)))func; \ > }) > > #define static_call_cond(name) (void)__static_call_cond(name) > diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h > index 5a00b8b2cf9f..5e658ef537e4 100644 > --- a/include/linux/static_call_types.h > +++ b/include/linux/static_call_types.h > @@ -18,6 +18,9 @@ > #define STATIC_CALL_TRAMP(name) __PASTE(STATIC_CALL_TRAMP_PREFIX, name) > #define STATIC_CALL_TRAMP_STR(name) __stringify(STATIC_CALL_TRAMP(name)) > > +#define STATIC_CALL_TYPE_PREFIX __SCtype__ > +#define STATIC_CALL_TYPE(name) __PASTE(STATIC_CALL_TYPE_PREFIX, name) > + > /* > * Flags in the low bits of static_call_site::key. > */ > @@ -36,11 +39,13 @@ struct static_call_site { > > #define DECLARE_STATIC_CALL(name, func) \ > extern struct static_call_key STATIC_CALL_KEY(name); \ > - extern typeof(func) STATIC_CALL_TRAMP(name); > + extern struct static_call_tramp STATIC_CALL_TRAMP(name); \ > + extern typeof(func) STATIC_CALL_TYPE(name) > > #ifdef CONFIG_HAVE_STATIC_CALL > > -#define __raw_static_call(name) (&STATIC_CALL_TRAMP(name)) > +#define __raw_static_call(name) \ > + ((typeof(&STATIC_CALL_TYPE(name)))&STATIC_CALL_TRAMP(name)) > > #ifdef CONFIG_HAVE_STATIC_CALL_INLINE > > @@ -96,7 +101,7 @@ struct static_call_key { > }; > > #define static_call(name) \ > - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) > + ((typeof(&STATIC_CALL_TYPE(name)))(STATIC_CALL_KEY(name).func)) > > #endif /* CONFIG_HAVE_STATIC_CALL */ > > -- > 2.30.2 >