From patchwork Fri Nov 5 14:59:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12604843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D27C433EF for ; Fri, 5 Nov 2021 15:01:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C1C1611C0 for ; Fri, 5 Nov 2021 15:01:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C1C1611C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=b84LHpCY01jfEJ1BZKUNnxM68aMlpYK44iyhxl6uc8c=; b=ZLq5Sgzhatb+od 4Gwr/xhyPaCZZTb9iqNDa1SOm3Y5HxI3NAu/wxd8uWD5L4md5kwtGP5w2bjTFddS2eqEMt8hF9H/l 4eSKQ+ADKuqWj2nqp9hzuCw0dhGjCbjI1aO3Wp0v9JT0IHUjRN2lduEvxdY1cZPQwhXnauDUunbaX 0uZHRtQgyFEClAB+EjVh3de0RBq+iCxXgsE5goO+Fy9dvVumsz8RoDsUz+taeB5A2VcMH4gJwqshS 0zru9nq5vaEcgEHnMZr9E4WLqaR3tzPLzIW+o3tMtysDekcV4Gcghc9Nc4IxvP2lR3GhGPk+DDjkh i+sHzpwnqQ8vn7Djbglg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mj0gt-00BdJf-Dy; Fri, 05 Nov 2021 14:59:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mj0gi-00BdGs-87 for linux-arm-kernel@lists.infradead.org; Fri, 05 Nov 2021 14:59:29 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA2F56120E; Fri, 5 Nov 2021 14:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636124367; bh=LTEQ9tKb2OswdfIaK6ja2qhw7vJe2vjWwbgDDi2F2KI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KHxZwMnWoLSCh3BplkdKQx55GLWP3miOHICLoAs65/DObBdbqbanivKtkFLGBTuPX LoKuOKGJxg1p8owN4n16YXrjCtiBJ3vv8EqGGgmENYLyo2zoAsoXnVT/LCRHQtWK4/ a5jXUFpY1g3uktx/gbFOsIWxX+pN19J/PMuQjUupzVwlqQbr8EonJG4JEXaHt8CNwz q7/0GorvtpHTpOC7yvvtpHxJjrARgaPMwD4BSlJOEqxNVGQYJUauSMRGGq7Eaa/pUC 5dc8ljuRm9kCJPyA2yBDdLiYoVEsZNRIu1e66LeVaNsVlc8i8WntNsFNPw75cs7O4A yi22ifteqDnSQ== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Mark Rutland , Quentin Perret , Catalin Marinas , James Morse , Will Deacon , Frederic Weisbecker , Peter Zijlstra , Kees Cook , Sami Tolvanen , Andy Lutomirski , Josh Poimboeuf , Steven Rostedt Subject: [PATCH v6 1/2] static_call: use non-function types to refer to the trampolines Date: Fri, 5 Nov 2021 15:59:16 +0100 Message-Id: <20211105145917.2828911-2-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211105145917.2828911-1-ardb@kernel.org> References: <20211105145917.2828911-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2779; h=from:subject; bh=LTEQ9tKb2OswdfIaK6ja2qhw7vJe2vjWwbgDDi2F2KI=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhhUbCOTl4Vs8hTbJG0j/c1dP2rCZXXb9EsgKFaSQ5 V6x8sKCJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYYVGwgAKCRDDTyI5ktmPJBQJC/ 495LgbATNfrHgBMTSiz5iUUHKuHyFuSuB3KqdYiLLGeiwplhoXPUY91mlb+XOWWhox+63pVm5xXZt/ bBq0peBfZugdvP7N6V7jFzGiWS3De4Ogo/0h57OJUZhp2KljqWkE8dmr38s6/z5f+zje2+faPEdPia iOWFLNWDiYazX+RO40O1JfnlUmDRXNdMpPHPLU/UCE6yxUuoyOIq820m8PIlG1Tv45Q4UzcriodI2H 5tQzOgnHgSB0jZLjqa8FeD92OgK37SjHDyQgaATBHQ4Bnc8r4FT5fsL+JLqZ6L4SnOTppR5tQ2XhvG eifgHLi+P7DZWaUkh1klmgIXIkF6os06+6lTn+CiQJxrkak1Np/kxc13b0toiny/Zf8THtbzOgYl6t jifC8hYC8RcKDowGjmc5s5bUwpjWdA3iONKUtjl49Fi15/zFEzThtg3apWyeHyFuOTQkEnHso7EXj9 OJ2ZyshYWzKbyvVJn4vbJJZB0GKRHvimvvL+JHEdeKNz0= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211105_075928_396583_8A4BAD58 X-CRM114-Status: GOOD ( 15.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 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 */