Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp609230pxh; Tue, 9 Nov 2021 16:07:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzVC6OfiAbmLXJwv3rOSmI0k7jSm8rFuBF/i59fom46FS9dV+K0aQvmSCTrF0T6VuW1IPG X-Received: by 2002:a05:6e02:1561:: with SMTP id k1mr8558888ilu.135.1636502861057; Tue, 09 Nov 2021 16:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636502861; cv=none; d=google.com; s=arc-20160816; b=JjhArB2z4dknBI4JBx8cyB9/smPAurD7+DGdxhnSjwCYq1PgPbqLEjxwqxUXBFTx0K dG/VtUdoPaGZbiESxHRj6T4VSwhcR3iIsGufzZpEhTSDFcFplUh6XPNB9wQ6HyivGu0M /u8odGPmtnMpvyBUQAu6N89kYBLYyr9xbLSasVkEmYXosAoyndrBIRd1R0qB8lkByfYZ Kg0v07wyGkZdVU1tRTdz8XX6xY8SygqKqCtg+mZKCTO84BHwFNTyH/nZolhiylh3PBrR IIsZJBLthmfnVkR77bJlxGdCAriaZrE7+Q8DjJteqj9y2WMgDfUgn7iEO3foMXw0FIaD AKsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2LJOv7s9d9rw2hmuCP08QMNnqueMPLPL8ti/txma0nw=; b=UJnGybzE2vv0IIqYt2ZUMFqM972V70ePSlrQww/tqGpIalPc72gFFOqbz64NfqMXyn kiSPHKKDoTiLrSuvZ+/25ASx54tXTPbW9VzgePnLvh2dvLyHxuHxjOenAjzhSJcdYgyt VJ396jdqLmWtWP7QKZcreGXIMeFIYqzk8lDj6v6fgsSKkU0AfN70tr2fQDJYMEOuOx5a Z2eTWycGHXqzXhxQHfYEAtFmJzPJJ0kItCwRVvA+HJ/Ok0mmDhN7b8fzud0N0TYPVEj+ j5rnrSnoXgtX8Z9JA+WekRkfaDKp/9pSY6VqojHUA6KvpT7xH4+yJHGhHHuSpAMF+4HD YlCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K2HMR0Hh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si7591521jat.116.2021.11.09.16.07.28; Tue, 09 Nov 2021 16:07:41 -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=@kernel.org header.s=k20201202 header.b=K2HMR0Hh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240349AbhKIQtL (ORCPT + 97 others); Tue, 9 Nov 2021 11:49:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:59916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239801AbhKIQtG (ORCPT ); Tue, 9 Nov 2021 11:49:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 77B5361208; Tue, 9 Nov 2021 16:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636476380; bh=y4wX9s7+HTFSjvSFbSz19j1vGuRP1pTMfkmfOmSDxk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K2HMR0HhOmDIjnKehI2zVcTXPq9wGyta0DEKpQg2jTiHG7jhmALFUsLkzG08xldsA wlo+v7aGh7S5m0+NIUatxOL3oigNXbkSK9UbDbZ0fC29FYujAGOWXta3q2Ln87m5sK TjgZnVTKb+MRpDVnhqAz7xrCKyE9ty+/9J7WEFLfiHEShFXsXGqo0ho41zIj4lvdZ5 LBbtzM8HnhgCk7aT6cLYhT8rSy+batd5g11u/dmBVx8Vk9Q+4u/m6EDttdcoVXFVFY bi4K/tcPEx/2fxY2rtuSB6IrUiRocgtULA7Wjw/+ZdWm0vAzBYcE9QfGVyxcbEetFM r0n//gdXyinoA== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Mark Rutland , Kees Cook Subject: [RFC PATCH 5/7] static_call: use non-function types to refer to the trampolines Date: Tue, 9 Nov 2021 17:45:47 +0100 Message-Id: <20211109164549.1724710-6-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109164549.1724710-1-ardb@kernel.org> References: <20211109164549.1724710-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3650; h=from:subject; bh=y4wX9s7+HTFSjvSFbSz19j1vGuRP1pTMfkmfOmSDxk0=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhiqW4kuuGzSKDlkzz0Prr9jyqVx4AQlIlqxGFdRli /7KncCGJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYYqluAAKCRDDTyI5ktmPJE3UC/ 4p0HTDMxRSJjJf/8PM0gRDp1+LIR1qeOeEhRxErabIqKkFs93BL+JUNgdDqFVDedZnHVP06Gw7zFZl gH4Kb9cn5wVIkLg+3UnZf1hHAu9r0cDk+jZHWlqY1Z4jVIYWBY6eKqZ5icgGd45gWeMSubeBJ7zcex RZCgqSdFvzhmRBnB9X5s+Rkv9EMuDtwQGYUPdHlh+ezQu9fQTo0H31kdlesKhqeXM8cY+fr9rYcPPx CGdv/TXZQJjoQyoB6Ldua6xst+ruUyuQT20FPD5v8s9536+0r148lSCGXlFQPGgpjd87c1TTf0Y+L3 +01rsbJAGslVw6m89pEQ6HsIgyUY5M89x77pYZLoi6UwrFK5L+VIqQLkUaI7QuD9+fRp3AfCMlTGro jjhjuHPikYB7skd5HoKLkjJAbpu9y9KWX/La123QpTghAuZ1eL1F9cT9e1W7rmX6t0hQQ6ukzQqus5 gMy0TLikfsxKQ9Lo8XvdyZStVt6eGnpmE+J0dMTJDh3H4= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. Acked-by: Peter Zijlstra Signed-off-by: Ard Biesheuvel --- include/linux/static_call.h | 2 +- include/linux/static_call_types.h | 6 +++--- tools/include/linux/static_call_types.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/static_call.h b/include/linux/static_call.h index 391f737496eb..6b261fe96ba3 100644 --- a/include/linux/static_call.h +++ b/include/linux/static_call.h @@ -144,7 +144,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_QUERY(name)()) __F = (func); \ __static_call_update(&STATIC_CALL_KEY(name), \ STATIC_CALL_TRAMP_ADDR(name), __F); \ }) diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h index 2fce9aa8a995..eae11c5b015d 100644 --- a/include/linux/static_call_types.h +++ b/include/linux/static_call_types.h @@ -47,7 +47,7 @@ struct static_call_site { extern __weak struct static_call_key STATIC_CALL_KEY(name); \ extern __weak struct static_call_key *STATIC_CALL_GETKEY(name)(void);\ extern __weak typeof(func) *STATIC_CALL_QUERY(name)(void); \ - extern typeof(func) STATIC_CALL_TRAMP(name) + extern struct static_call_tramp STATIC_CALL_TRAMP(name) #define __static_call_query(name) \ ((typeof(STATIC_CALL_QUERY(name)()))READ_ONCE(STATIC_CALL_KEY(name).func)) @@ -66,7 +66,7 @@ struct static_call_site { #define static_call(name) \ ({ \ __STATIC_CALL_ADDRESSABLE(name); \ - (&STATIC_CALL_TRAMP(name)); \ + ((typeof(STATIC_CALL_QUERY(name)()))&STATIC_CALL_TRAMP(name)); \ }) #ifdef CONFIG_HAVE_STATIC_CALL_INLINE @@ -107,7 +107,7 @@ struct static_call_key { }; #define static_call(name) \ - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) + ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func)) #endif /* CONFIG_HAVE_STATIC_CALL */ diff --git a/tools/include/linux/static_call_types.h b/tools/include/linux/static_call_types.h index 2fce9aa8a995..eae11c5b015d 100644 --- a/tools/include/linux/static_call_types.h +++ b/tools/include/linux/static_call_types.h @@ -47,7 +47,7 @@ struct static_call_site { extern __weak struct static_call_key STATIC_CALL_KEY(name); \ extern __weak struct static_call_key *STATIC_CALL_GETKEY(name)(void);\ extern __weak typeof(func) *STATIC_CALL_QUERY(name)(void); \ - extern typeof(func) STATIC_CALL_TRAMP(name) + extern struct static_call_tramp STATIC_CALL_TRAMP(name) #define __static_call_query(name) \ ((typeof(STATIC_CALL_QUERY(name)()))READ_ONCE(STATIC_CALL_KEY(name).func)) @@ -66,7 +66,7 @@ struct static_call_site { #define static_call(name) \ ({ \ __STATIC_CALL_ADDRESSABLE(name); \ - (&STATIC_CALL_TRAMP(name)); \ + ((typeof(STATIC_CALL_QUERY(name)()))&STATIC_CALL_TRAMP(name)); \ }) #ifdef CONFIG_HAVE_STATIC_CALL_INLINE @@ -107,7 +107,7 @@ struct static_call_key { }; #define static_call(name) \ - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) + ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func)) #endif /* CONFIG_HAVE_STATIC_CALL */ -- 2.30.2