Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2619392ybf; Mon, 2 Mar 2020 12:17:46 -0800 (PST) X-Google-Smtp-Source: ADFU+vv7VEirHBOY2JfEL3XIl5d4k13M8zpJiITVMrp907O6tTBPnKXC3jzHxU8LSmo0M29urfij X-Received: by 2002:a05:6808:289:: with SMTP id z9mr135544oic.48.1583180266102; Mon, 02 Mar 2020 12:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583180266; cv=none; d=google.com; s=arc-20160816; b=rpD7FBqQ9mz0y/rho7sipjYF6ut/uhJJZAMVZgU8jOZ0NHWBvFwtPvijSypzCHZn+g Y/tVFb2aRzKMxnHuuHO0U8w1Jjxig4UVdFmTMVRLSpgNYy6Kehm4mDaQWK8xqYPkRld7 83n6hVgsFjr/wsO5JeQd4DqRughKJZmwDkmCB7ZsHp37ssNar/t/LPzAHVOTmzG1fHYU OW/cCzyLsF+j5g+p14RJfpVFKANUOMuWjQU++koewN3aTaiWJel7aDcGEmnLCQRgKyfW Pzw7mqc5dFE07QA/PkokCDpmwgnUUb/HuhUsoQcn2QT/jmIjkhwmipLGApT0RGYBtlD2 2NoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender: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=vUQHSN2S8pO8DYDTLlHsHq6yUAxZUvhQdiudOhqhxns=; b=Gy++yVZfa6qVwura5RB8bqeaeU8sFCgu3WZQuAQf3NLqLUUAz1EFWwJvMoAuHstkFa KtdnZK8Za5g6MZpocfZw9mu4PR2rsMPm/cj4rTkya0GV7PivKjMCSzVWjwEnJLeuMzfZ zKcJc7JhRFJTE1VQlKPIHMW5llzD0IEg7BWFsJoJJlrorM/9I7RyWsHHchI5GY+Veqhv GGlKOwpA0shJGpqmopU/M3hzxy81b+PrShG0hZKtXD9ToJ5W1T5hhorhJUZ/LU7/xcD+ gxqlMGL/XH1zw7ll0ejxAayvT+BPJN71RilOnOy0r+1+coi8w4b898IixQJuSeB4/iiM 7O3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Enc+4Ffz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id w142si6747129oia.132.2020.03.02.12.17.33; Mon, 02 Mar 2020 12:17:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Enc+4Ffz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726545AbgCBURJ (ORCPT + 99 others); Mon, 2 Mar 2020 15:17:09 -0500 Received: from mail.efficios.com ([167.114.26.124]:54650 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbgCBURJ (ORCPT ); Mon, 2 Mar 2020 15:17:09 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id B07D02433D8; Mon, 2 Mar 2020 15:17:07 -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 LioklzsSvCIl; Mon, 2 Mar 2020 15:17:07 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 475E1243444; Mon, 2 Mar 2020 15:17:07 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 475E1243444 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1583180227; bh=vUQHSN2S8pO8DYDTLlHsHq6yUAxZUvhQdiudOhqhxns=; h=Date:From:To:Message-ID:MIME-Version; b=Enc+4Ffz7rCzbWymLqCB6N6ph3xhXCJBXojVPGYxIDDoxxOebgcZpVOHxEasZ6sIP r9KjnjgBZSjPeu1bj7WPWY3BrM99zDRaXSQUXDN28LB82qExEqIQ4inr4SuGrE63ra b7DzPecMSl0fsOYIBSJvLvKXvdcla9bJyqaxQQo7lH6xSJa31baO9H1THau3PDfmtK 02ey1lKCGG0d0dLhu7MR+Io95626cR7xN0bxvOuel3DykiDqNcXEFhcN0UCmrlV3Ue E3caFiG2m15vWq0aqSYevHodOlualByFdofaOiS/jVJE9cdQ5AA8X40m0dsMSUovEV wbY7GREUcla1w== 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 i8EEFes_nu-J; Mon, 2 Mar 2020 15:17:07 -0500 (EST) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 34EA52434AD; Mon, 2 Mar 2020 15:17:07 -0500 (EST) Date: Mon, 2 Mar 2020 15:17:07 -0500 (EST) From: Mathieu Desnoyers To: Greg Kroah-Hartman Cc: Will Deacon , linux-kernel , kernel-team , Andrew Morton , "K . Prasad" , Thomas Gleixner , Frederic Weisbecker , Christoph Hellwig , Quentin Perret , Alexei Starovoitov , Masami Hiramatsu , rostedt Message-ID: <1183544004.13859.1583180227118.JavaMail.zimbra@efficios.com> In-Reply-To: <20200302193957.GA276441@kroah.com> References: <20200221114404.14641-1-will@kernel.org> <20200302192811.n6o5645rsib44vco@localhost> <20200302193658.GA272023@kroah.com> <20200302193957.GA276441@kroah.com> Subject: Re: [PATCH 0/3] Unexport kallsyms_lookup_name() and kallsyms_on_each_symbol() 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_3901 (ZimbraWebClient - FF73 (Linux)/8.8.15_GA_3895) Thread-Topic: Unexport kallsyms_lookup_name() and kallsyms_on_each_symbol() Thread-Index: fos3cr6ROn/KiR3DQsae2mE8DEbr3Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Mar 2, 2020, at 2:39 PM, Greg Kroah-Hartman gregkh@linuxfoundation.org wrote: > On Mon, Mar 02, 2020 at 08:36:58PM +0100, Greg Kroah-Hartman wrote: >> On Mon, Mar 02, 2020 at 02:28:11PM -0500, Mathieu Desnoyers wrote: >> > On 21-Feb-2020 11:44:01 AM, Will Deacon wrote: >> > > Hi folks, >> > > >> > > Despite having just a single modular in-tree user that I could spot, >> > > kallsyms_lookup_name() is exported to modules and provides a mechanism >> > > for out-of-tree modules to access and invoke arbitrary, non-exported >> > > kernel symbols when kallsyms is enabled. >> > > >> > > This patch series fixes up that one user and unexports the symbol along >> > > with kallsyms_on_each_symbol(), since that could also be abused in a >> > > similar manner. >> > >> > Hi, >> > >> > I maintain a GPL kernel tracer (LTTng) since 2005 which happens to be >> > out-of-tree, even though we have made unsuccessful attempts to upstream >> > it in the past. It uses kallsyms_lookup_name() to fetch a few symbols. I >> > would be very glad to have them GPL-exported upstream rather than >> > relying on this work-around. Here is the list of symbols we would need >> > to GPL-export: >> > >> > stack_trace_save >> > stack_trace_save_user >> > vmalloc_sync_all (CONFIG_X86) >> > get_pfnblock_flags_mask >> > disk_name >> > block_class >> > disk_type >> >> I hate to ask, but why does anyone need block_class? or disk_name or >> disk_type? I need to put them behind a driver core namespace or >> something soon... > In LTTng, we have a "statedump" which dumps all the relevant state of the kernel at trace start (or when the user asks for it) into the kernel trace. It is used to collect information which helps translating compact numeric data into human-readable information at post-processing. For block devices, the statedump contains the mapping between the device number and the disk name [1]. It uses the "block_class", "disk_name", and "disk_type" symbols for this. Here is the post-processing output: [14:48:41.388934812] (+?.?????????) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 1048576, diskname = "ram0" } [...] [14:48:41.442548745] (+0.003574998) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 1048591, diskname = "ram15" } [14:48:41.446064977] (+0.003516232) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 265289728, diskname = "vda" } [14:48:41.449579781] (+0.003514804) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 265289729, diskname = "vda1" } [14:48:41.453113808] (+0.003534027) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 265289744, diskname = "vdb" } [14:48:41.456640876] (+0.003527068) compudjdev lttng_statedump_block_device: { cpu_id = 0 }, { dev = 265289745, diskname = "vdb1" } This information is then used in our I/O analyses to show information comprehensible to a user. > Wait, disk_type is a static variable. And there's multiple ones of > them, how does that work? Yes, this is far from ideal. Here are the ones I observe in the kernel sources: block/genhd.c 40:static const struct device_type disk_type; <---- the one we use lib/raid6/test/test.c 41:static char disk_type(int d) <---- this is a stand-alone user-space test program, not part of the kernel image. crypto/async_tx/raid6test.c (depends on CONFIG_ASYNC_RAID6_TEST) 44:static char disk_type(int d, int disks) <---- the compiler optimizes away this function, so this symbol is not present in the kernel image. I think a better approach to solve this would be to implement and expose an iterator function in the core kernel which could invoke a callback. However, the main issue remains: if the only user is out-of-tree, I cannot justify adding an exported kernel helper for this. Thanks, Mathieu [1] https://github.com/lttng/lttng-modules/blob/master/lttng-statedump-impl.c#L125 -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com