Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp768260ybt; Wed, 17 Jun 2020 13:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyps7KF+089at3Kb2SHXsRBOZ3MoQEGeoxLbKIovG6kAPm0d9lZ27yujBHdWVYt1KhsFgll X-Received: by 2002:a17:906:5645:: with SMTP id v5mr888502ejr.533.1592425855755; Wed, 17 Jun 2020 13:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592425855; cv=none; d=google.com; s=arc-20160816; b=aZvSQudmoNUjF71iWDKJOG2mIObjibW8cEX+EO1/0kCyrE9jdwWz8mhWFT/WZaYZyO x33JI5Hq7Mav3ZK5hAdHMT5ZXPvV6/Xc6wZuuX1sZQHP4Php7jmo89fVQpBZuPdkh6v3 xfPUmxo+dVpOxaXYGQqU5wjk6Z5rT4hjJUnxeJAXQTRtAHC1LmSN3HDUvDmNrjDbpk2r CFvjQD2JeELCpWEN8hYSBZWgIFcBOxXXp1VZYGVKVN2MUNSIED6tjGHTzMAF2msJwV9r /8021xkpUuT7TQ23EsUww7cdcwftFl9cc5xILT4Qn2b6rQbGxAbdzmaZUSvXK82ir7vb F6Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=RJ74UQCi7b0gXVUonfSAccyANQgI71/JGbvk+ktuXbE=; b=FtfB1fjYir3M3QxahDzaRf6ZvqKeg/rdQfgh+g4v7vuyXqev9OGv3N0caqSO1OeDC5 aGTbWEPipLTR8fX0AT08B7pZdgtNxTLc+TZXbRv943z8hlKbJdExEiomdOgSaNJfHHY3 H/OpFowA4XGkgqXfs1Dr3pj7k2fMhUZ6txqvTWgTGHHlKECYowDe09ahJbaQiLyTHYJg aHB9QkMgUzJRIVC1+r0hGuW5/TRLeoU/NkgGLV0hlPU1UOAyNTq4Wi7IwW0NI2LOzFub iI0FYlWXQoijw7rhmzTBZD5jkz/QpCsGBas+Yhb8GEBwyjlXr3MfPYIDSOBSSO/BsFww 3oYA== 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 sa14si542401ejb.297.2020.06.17.13.30.32; Wed, 17 Jun 2020 13:30:55 -0700 (PDT) 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 S1726926AbgFQU2E (ORCPT + 99 others); Wed, 17 Jun 2020 16:28:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbgFQU2D (ORCPT ); Wed, 17 Jun 2020 16:28:03 -0400 Received: from oasis.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 8E900214DB; Wed, 17 Jun 2020 20:28:02 +0000 (UTC) Date: Wed, 17 Jun 2020 16:28:00 -0400 From: Steven Rostedt To: Oscar Carter Cc: Kees Cook , Ingo Molnar , kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/trace: Remove function callback casts Message-ID: <20200617162800.05a12502@oasis.local.home> In-Reply-To: <20200615162245.13d3feff@oasis.local.home> References: <20200614070154.6039-1-oscar.carter@gmx.com> <20200615161738.18d07ce6@oasis.local.home> <20200615162245.13d3feff@oasis.local.home> 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 15 Jun 2020 16:22:45 -0400 Steven Rostedt wrote: > As I was saying. This typecast is being paranoid, as archs will call > the ftrace_ops_list_func directly, and only pass in two parameters. > > Now one way around this is to instead of having the typecast, I could > use linker magic to create another function that I can define without > the typecast to get the same effect. Similar to what I did in commit: > > 46f9469247c6f ("ftrace: Rename ftrace_graph_stub to ftrace_stub_graph") Would something like this work for you? -- Steve diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index db600ef218d7..120babd9ba44 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -145,13 +145,18 @@ * Need to also make ftrace_stub_graph point to ftrace_stub * so that the same stub location may have different protocols * and not mess up with C verifiers. + * + * ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func + * as some archs will have a different prototype for that function + * but ftrace_ops_list_func() will have a single prototype. */ #define MCOUNT_REC() . = ALIGN(8); \ __start_mcount_loc = .; \ KEEP(*(__mcount_loc)) \ KEEP(*(__patchable_function_entries)) \ __stop_mcount_loc = .; \ - ftrace_stub_graph = ftrace_stub; + ftrace_stub_graph = ftrace_stub; \ + ftrace_ops_list_func = arch_ftrace_ops_list_func; #else # ifdef CONFIG_FUNCTION_TRACER # define MCOUNT_REC() ftrace_stub_graph = ftrace_stub; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index f060838e9cbb..b775d399026e 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -119,14 +119,9 @@ struct ftrace_ops __rcu *ftrace_ops_list __read_mostly = &ftrace_list_end; ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; struct ftrace_ops global_ops; -#if ARCH_SUPPORTS_FTRACE_OPS -static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, - struct ftrace_ops *op, struct pt_regs *regs); -#else -/* See comment below, where ftrace_ops_list_func is defined */ -static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip); -#define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops) -#endif +/* Defined by vmlinux.lds.h see the commment above arch_ftrace_ops_list_func for details */ +void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct pt_regs *regs); static inline void ftrace_ops_init(struct ftrace_ops *ops) { @@ -6859,21 +6854,23 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, * Note, CONFIG_DYNAMIC_FTRACE_WITH_REGS expects a full regs to be saved. * An architecture can pass partial regs with ftrace_ops and still * set the ARCH_SUPPORTS_FTRACE_OPS. + * + * In vmlinux.lds.h, ftrace_ops_list_func() is defined to be + * arch_ftrace_ops_list_func. */ #if ARCH_SUPPORTS_FTRACE_OPS -static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, - struct ftrace_ops *op, struct pt_regs *regs) +void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct pt_regs *regs) { __ftrace_ops_list_func(ip, parent_ip, NULL, regs); } -NOKPROBE_SYMBOL(ftrace_ops_list_func); #else -static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip) +void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip) { __ftrace_ops_list_func(ip, parent_ip, NULL, NULL); } -NOKPROBE_SYMBOL(ftrace_ops_no_ops); #endif +NOKPROBE_SYMBOL(arch_ftrace_ops_list_func); /* * If there's only one function registered but it does not support