Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4233241pxb; Tue, 17 Nov 2020 15:17:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg49ydeRLpkcetKZVZXDcMgOo2TcQGuqNCBv2JeZBoR1yvQNSbRol4ZkaWMu/oG1g0HPk/ X-Received: by 2002:a17:906:f8cd:: with SMTP id lh13mr17118437ejb.551.1605655038718; Tue, 17 Nov 2020 15:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605655038; cv=none; d=google.com; s=arc-20160816; b=A4rLINo2Xwczq1/YGelqg1s7eo/TjH+jCUNFTw//Yje1samUbIZh0Nh+KKO5dQnXQz BctJA1PJPBKdmrTzC2y7xBLaGCoBhbFHiT7npTS+HOZkJAu/b3OMFxZfxCtBctAWgSzW mBYBdMNJtlKCrEFhUhEQ2DYoXTQlf8T4dfl/wMcaxmf2eRK89L9WTBrBKzqkQHyxFbTv qRnRBQcS8I+QdHl7If6zQ5Efiz7Bg12LDAdJMF1GPl8hd7E4QZtsfzc9VEu97sVhIld7 uEV3xrNU5uWkx4IMmBNFuZh6c3BAKp90vAAn2MEeDygNzmrutkpNcv+j8RW4Ss2Dxxl/ 34RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=vLdftlX/55MeTq+v64XuxgW7pzs9L8WtPSZDqfhYEZc=; b=dfWLQane5mzNQX0OLA1NBcaVD/NSbQZTIYiGXJ0NlNkZUhi6A2hHlpUDZEfHW1yH6m Yv/7zyupk4NaJMqUw5iU74PNo2dxWBgwqXDvy/HgE5cxxRBB3sVD/sWEhTkpontbDvgp BAqZXviJRxv6k32ZUYP2q6b1Q8xeHTIYyBvBoqUL5ebBeKswjENK4xFZ7fjZLgTEaAEa 7p1+moXSqOPF8CoTUHPGJHG/gUNmhT9yx9GYMmHc1mP8dAlj90CmTB+bo201y4IBylOA 8PfE6j/Nn9oI4yE4sXwL2GyVLUw/LI5ZJVtbSSndJs0EcTvnCZRw7b3MBMtZ39mxJdrK QvuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=r00UlGbY; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l63si16896753ede.607.2020.11.17.15.16.56; Tue, 17 Nov 2020 15:17:18 -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=@efficios.com header.s=default header.b=r00UlGbY; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbgKQXM5 (ORCPT + 99 others); Tue, 17 Nov 2020 18:12:57 -0500 Received: from mail.efficios.com ([167.114.26.124]:50378 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725613AbgKQXM4 (ORCPT ); Tue, 17 Nov 2020 18:12:56 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 3EFB82E55CE; Tue, 17 Nov 2020 18:12:55 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id pBa8GWPfhX9y; Tue, 17 Nov 2020 18:12:55 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id D76CA2E57BA; Tue, 17 Nov 2020 18:12:54 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com D76CA2E57BA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1605654774; bh=vLdftlX/55MeTq+v64XuxgW7pzs9L8WtPSZDqfhYEZc=; h=Date:From:To:Message-ID:MIME-Version; b=r00UlGbYXVI23qEfKALHSeTvyEOjnafOtLQV4K/7L4ZmLD3S70oyS0KU+sT6RBdwV 4LwlwIqCa1rU5XZJvRID9f9EJ+xaVuzr6NeF2o1kKdKBAKV2wU0H6ZVbgBfOOFS6EH RKycNc0RrviB/56ZlPjWLVziKCqEE9CtnBlfbU6oGxQAXxdAQJ5HR57HsIye4UpcM9 xt6J60/yLMlhSthcceepNrHaDbXJ49rb/XTdMz/r8aWLxE7//Nhf0Yt3dvaDRvdMba UoFNE2EmWYdeElJLLTpFtJCuWkKTBIkJ9PlFjprz6/uQQ65WRyDzsE6gWNmNNvdDPO hggjt+T982wbg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id SHMRXlDdwvao; Tue, 17 Nov 2020 18:12:54 -0500 (EST) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id C05152E57B9; Tue, 17 Nov 2020 18:12:54 -0500 (EST) Date: Tue, 17 Nov 2020 18:12:54 -0500 (EST) From: Mathieu Desnoyers To: rostedt Cc: Kees Cook , 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 Message-ID: <1473764147.48847.1605654774757.JavaMail.zimbra@efficios.com> In-Reply-To: <20201117171904.2d455699@gandalf.local.home> References: <20201116175107.02db396d@gandalf.local.home> <202011171330.94C6BA7E93@keescook> <20201117171904.2d455699@gandalf.local.home> Subject: Re: [PATCH] tracepoint: Do not fail unregistering a probe due to memory allocation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3975 (ZimbraWebClient - FF82 (Linux)/8.8.15_GA_3975) Thread-Topic: tracepoint: Do not fail unregistering a probe due to memory allocation Thread-Index: Y/jQdv3dPGXvTPsmYxooPni6/fazNg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Nov 17, 2020, at 5:19 PM, rostedt rostedt@goodmis.org wrote: > On Tue, 17 Nov 2020 13:33:42 -0800 > Kees Cook wrote: > >> As I think got discussed in the thread, what you had here wouldn't work >> in a CFI build if the function prototype of the call site and the >> function don't match. (Though I can't tell if .func() is ever called?) >> >> i.e. .func's prototype must match tp_stub_func()'s. >> > > > Hmm, I wonder how you handle tracepoints? This is called here: > > include/linux/tracepoint.h: > > > #define DEFINE_TRACE_FN(_name, _reg, _unreg, proto, args) \ > static const char __tpstrtab_##_name[] \ > __section("__tracepoints_strings") = #_name; \ > extern struct static_call_key STATIC_CALL_KEY(tp_func_##_name); \ > int __traceiter_##_name(void *__data, proto); \ > struct tracepoint __tracepoint_##_name __used \ > __section("__tracepoints") = { \ > .name = __tpstrtab_##_name, \ > .key = STATIC_KEY_INIT_FALSE, \ > .static_call_key = &STATIC_CALL_KEY(tp_func_##_name), \ > .static_call_tramp = STATIC_CALL_TRAMP_ADDR(tp_func_##_name), \ > .iterator = &__traceiter_##_name, \ > .regfunc = _reg, \ > .unregfunc = _unreg, \ > .funcs = NULL }; \ > __TRACEPOINT_ENTRY(_name); \ > int __traceiter_##_name(void *__data, proto) \ > { \ > struct tracepoint_func *it_func_ptr; \ > void *it_func; \ > \ > it_func_ptr = \ > rcu_dereference_raw((&__tracepoint_##_name)->funcs); \ > do { \ > it_func = (it_func_ptr)->func; \ > __data = (it_func_ptr)->data; \ > > ((void(*)(void *, proto))(it_func))(__data, args); \ > > ^^^^ called above ^^^^ > > Where args is unique for every tracepoint, but func is simply a void > pointer. That being said, the called functions have a prototype which match the caller prototype exactly. So within the tracepoint internal data structures, this function pointer is indeed a void pointer, but it is cast to a prototype matching the callees to perform the calls. I suspect that as long as CFI checks that caller/callees prototypes are compatible at runtime when the actual calls happen, this all works fine. Thanks, Mathieu > > -- Steve > > > } while ((++it_func_ptr)->func); \ > return 0; \ > } \ -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com