Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp485798pxb; Wed, 18 Nov 2020 09:22:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTel4i9+Keb4tJs/9TbMecl/wYFVZ3b+IgxlTTew6L6mVZXBg0tg82Q5uM298fpmYdCgeG X-Received: by 2002:a17:906:b101:: with SMTP id u1mr2852407ejy.457.1605720124597; Wed, 18 Nov 2020 09:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605720124; cv=none; d=google.com; s=arc-20160816; b=oeuQkNd2AA1d50jXGUvkmdeRpeluGHI3F+lldJlZQU0OhukkogPJiNy4JiM3MP26gG hEXviS9fWVHEdAuQ13HYJzy+PadJXfz6GGQJ76u25XVqhdl4mmWCtYW3JrpNuXNs3f9r uevJIYETW5PrG3aj+TBUonLlbMTs2czLnrQfmoOVwKZp3UleYZb00KwX6RC4GZWNjZ+W JOuFy6iWxeMk3x3OF/3tfrzIMCLd/Vh/c2MEzM7tgZYvoid8ngQRvukV1PPBUiLgXlPu gXOooxcseg+5feSsl1bs1rFiAscykkQRi3EEMGcsEQS/FcaSc77VthDF2kxv/DTiEJc8 O7xQ== 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:subject:cc:to:from:date; bh=XzVodKm6RASwOtJbXhi20o45TI824kDSgkN77HUYxFA=; b=my4Gz3fUxE3jc234Nbi/rnRtwxnYOSzcWuf7scSrzKp6WnXXni7wAmnnNwkFlLN4hO thSNIrQIATEijF1KcetOAaIgLvYf+o/EDey53PxoougPMr1bz929QBVx2q01ggqlwuFh FZqUa+L1dt8SMOAa4JrM0NDzuNaAv+gje+6YQvt+rWwAfkfSTh/lAeeWFSAEx9sld+51 iccrn+rQuDF1EnogCJg7Xr7QaCBBsV4oFNuEIOkZ6F7XoNIRqHdDKX7os6rZXsAF7v1V H3cztBJZSclsXoGrSD5j+A3cOZ+qs6pePlIoN9hku/GaZxyD7QDq9CYdkX/aOwEwKsD4 GKIA== ARC-Authentication-Results: i=1; mx.google.com; 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 q3si3553296edr.472.2020.11.18.09.21.40; Wed, 18 Nov 2020 09:22:04 -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; 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 S1727857AbgKRRRg (ORCPT + 99 others); Wed, 18 Nov 2020 12:17:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:47692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbgKRRRg (ORCPT ); Wed, 18 Nov 2020 12:17:36 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E3EA8248A7; Wed, 18 Nov 2020 17:17:32 +0000 (UTC) Date: Wed, 18 Nov 2020 12:17:30 -0500 From: Steven Rostedt To: Nick Desaulniers Cc: Peter Zijlstra , Sami Tolvanen , Mathieu Desnoyers , linux-kernel , Matt Mullins , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Dmitry Vyukov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev , bpf , Kees Cook , Josh Poimboeuf , linux-toolchains@vger.kernel.org Subject: Re: violating function pointer signature Message-ID: <20201118121730.12ee645b@gandalf.local.home> In-Reply-To: References: <20201116175107.02db396d@gandalf.local.home> <47463878.48157.1605640510560.JavaMail.zimbra@efficios.com> <20201117142145.43194f1a@gandalf.local.home> <375636043.48251.1605642440621.JavaMail.zimbra@efficios.com> <20201117153451.3015c5c9@gandalf.local.home> <20201118132136.GJ3121378@hirez.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Nov 2020 08:50:37 -0800 Nick Desaulniers wrote: > On Wed, Nov 18, 2020 at 5:23 AM Peter Zijlstra wrote: > > > > On Tue, Nov 17, 2020 at 03:34:51PM -0500, Steven Rostedt wrote: > > > > > > > Since all tracepoints callbacks have at least one parameter (__data), we > > > > > could declare tp_stub_func as: > > > > > > > > > > static void tp_stub_func(void *data, ...) > > > > > { > > > > > return; > > > > > } > > > > > > > > > > And now C knows that tp_stub_func() can be called with one or more > > > > > parameters, and had better be able to deal with it! > > > > > > > > AFAIU this won't work. > > > > > > > > C99 6.5.2.2 Function calls > > > > > > > > "If the function is defined with a type that is not compatible with the type (of the > > > > expression) pointed to by the expression that denotes the called function, the behavior is > > > > undefined." > > > > > > But is it really a problem in practice. I'm sure we could create an objtool > > > function to check to make sure we don't break anything at build time. > > > > I think that as long as the function is completely empty (it never > > touches any of the arguments) this should work in practise. > > > > That is: > > > > void tp_nop_func(void) { } > > or `void tp_nop_func()` if you plan to call it with different > parameter types that are all unused in the body. If you do plan to > use them, maybe a pointer to a tagged union would be safer? This stub function will never use the parameters passed to it. You can see the patch I have for the tracepoint issue here: https://lore.kernel.org/r/20201118093405.7a6d2290@gandalf.local.home I could change the stub from (void) to () if that would be better. > > > > > can be used as an argument to any function pointer that has a void > > return. In fact, I already do that, grep for __static_call_nop(). > > > > I'm not sure what the LLVM-CFI crud makes of it, but that's their > > problem. > > If you have instructions on how to exercise the code in question, we > can help test it with CFI. Better to find any potential issues before > they get committed. If you apply the patch to the Linux kernel, and then apply: https://lore.kernel.org/r/20201116181638.6b0de6f7@gandalf.local.home Which will force the failed case (to use the stubs). And build and boot the kernel with those patches applied, you can test it with: # mount -t tracefs nodev /sys/kernel/tracing # cd /sys/kernel/tracing # echo 1 > events/sched/sched_switch/enable # mkdir instances/foo # echo 1 > instances/foo/events/sched/sched_switch/enable # echo 0 > events/sched/sched_switch/enable Which add two callbacks to the function array for the sched_switch tracepoint. The remove the first one, which would add the stub instead. -- Steve