Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp162916rwd; Wed, 7 Jun 2023 21:39:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40v8RF3Ajv00KNnuhnC9jjYDPNBwI03thJCoY+LMoGYFzlKJjdpu0NltuI8yqaiTDrBBif X-Received: by 2002:a17:90b:82:b0:255:ee94:df7 with SMTP id bb2-20020a17090b008200b00255ee940df7mr6937249pjb.16.1686199196435; Wed, 07 Jun 2023 21:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686199196; cv=none; d=google.com; s=arc-20160816; b=OsIYGJLdb4n0K6/lRY3ZBnU/RSr5GTN5gdzuMD4II1G0/V/2XIBzJHI2NvEa59decJ mMNyhUnRlMYEQ5KgJQEXpWyZMydU6iUwr40/yndUN0kjrrJrky/u8U9zk/58w9T4j3NL H3Rcdnqkpv/J0GnClBcXdoCgP5jUqLTCkN5ECGanvFRXKBNU7mYAT4Ug0aH6SR+EAtAv zGfPzKlIaklxpLhf4jBdvgaPzZNkU90mWo/Xy/CWo5HVY5Keio4c45wdPMgmuxn0DXj6 QQ/pYVKy3VzWT3Thew0Ykq2k1/dxqkJFiH6Vxn44tBMEOId1r6Kj3gIJuLOWD+kpZNGw rLxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=2Fz2DLJhxQC3RZTzyXiXAqOxcnw3R376ukqCFr/l8z0=; b=mBYcW2ZnV2YQFp/QPyUCkvxwzwQPpQQgQy9eDdSBKoUCQr+JEpvFo+CJyZyx5nEpdF VD+20BQjSWDliNUpGBZymGBESiJDIqAer3Lnr98y66JiP47qgaYh+Y68iqfqfTLi0IOy RYROobk3+U4IKlMijHv91260M3rr1QIK8Zv0xMSg/Suo2UBJiBApYkTQWLe/9wssxGve K/wurTQ2xWkB7ygfbcAYHNIUxjvZoVkRrCcYUrVify/vz5ct0CXeIQFoaLxgQOT+wYrF R3gGda8rRJpgFaeESX7AC7F5DML8qKFCoVvlW8GqJkEBUokLbTqJSIklEYLgjeYICyTp fFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OFrFG3By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v23-20020a17090abb9700b00255d8dda719si430905pjr.148.2023.06.07.21.39.42; Wed, 07 Jun 2023 21:39:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OFrFG3By; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233608AbjFHDjO (ORCPT + 99 others); Wed, 7 Jun 2023 23:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbjFHDjN (ORCPT ); Wed, 7 Jun 2023 23:39:13 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9411926A2 for ; Wed, 7 Jun 2023 20:39:10 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230608033908epoutp044c06ba3d722d0ef2ca855734372828e7~mkerggug80136201362epoutp04E for ; Thu, 8 Jun 2023 03:39:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230608033908epoutp044c06ba3d722d0ef2ca855734372828e7~mkerggug80136201362epoutp04E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1686195548; bh=2Fz2DLJhxQC3RZTzyXiXAqOxcnw3R376ukqCFr/l8z0=; h=From:To:Cc:Subject:Date:References:From; b=OFrFG3BycUk0yJMGsdG1dEfcWOn1dCDx2EBgDEo4NCZKYvq3ezpDLTHaSNZBJwZeo AX3dWMq12e+9kNMKykDjgKGh674IVWxoROy6ZtC9bCnH9D7zW/bbk4CthrgZlyQ2ix Ars0O/pre0tAK/f5JDBrWF8INCTukXIa88ps38FM= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20230608033907epcas5p27c6e3d9457ba227b42747c5bff110f02~mkeqsDaw93270632706epcas5p26; Thu, 8 Jun 2023 03:39:07 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 19.A9.44881.B5D41846; Thu, 8 Jun 2023 12:39:07 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230608033132epcas5p22208020abf46fc8667086c31b6d7c63d~mkYDAYZcV0732707327epcas5p2u; Thu, 8 Jun 2023 03:31:32 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230608033132epsmtrp13712376939b39ccc0b0100f2126a2a06~mkYC9UIIf0357103571epsmtrp1a; Thu, 8 Jun 2023 03:31:32 +0000 (GMT) X-AuditID: b6c32a4a-ea9fa7000001af51-ca-64814d5ba94e Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 02.F2.28392.49B41846; Thu, 8 Jun 2023 12:31:32 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230608033125epsmtip19c2d6d633b95d95b1875734d8cf2b767~mkX8i8neI0805408054epsmtip1F; Thu, 8 Jun 2023 03:31:25 +0000 (GMT) From: Maninder Singh To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, thunder.leizhen@huawei.com, mcgrof@kernel.org, boqun.feng@gmail.com, vincenzopalazzodev@gmail.com, ojeda@kernel.org, jgross@suse.com, brauner@kernel.org, michael.christie@oracle.com, samitolvanen@google.com, glider@google.com, peterz@infradead.org, keescook@chromium.org, stephen.s.brennan@oracle.com, alan.maguire@oracle.com, pmladek@suse.com Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Maninder Singh , Onkarnath Subject: [PATCH v5 1/2] kallsyms: move kallsyms_show_value() out of kallsyms.c Date: Thu, 8 Jun 2023 09:01:18 +0530 Message-Id: <20230608033119.1543638-1-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02SfVSTVRzHu8/bHuZZPQxP3sAgSSIxRlDmtRL4w+pJwyOd8lSgtOAJrQ13 NibpqeN4CQ/DwZyaMN4jj7yIwBoeXgXGcqLlwSGJGLXlprwk8ZYmyDHHIyf/+/5+9/O93/v7 nUvj4hLKl96dksopU6SyQEpInOlZ82JoXEx60svV2pVo0JJOoLvzRTiavXddgE6Z0zE0Y7VR aLxnGqDKijs4OjjVgSOLrVOAiq9FoIzmKgxZjxpx9HOuHN06q8NQf2sxhXrK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EhNquXRuMK5SS38DRlEhEVkDAAA= X-CMS-MailID: 20230608033132epcas5p22208020abf46fc8667086c31b6d7c63d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20230608033132epcas5p22208020abf46fc8667086c31b6d7c63d References: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org function kallsyms_show_value() is used by other parts like modules_open(), kprobes_read() etc. which can work in case of !KALLSYMS also. e.g. as of now lsmod do not show module address if KALLSYMS is disabled. since kallsyms_show_value() defination is not present, it returns false in !KALLSYMS. / # lsmod test 12288 0 - Live 0x0000000000000000 (O) So kallsyms_show_value() can be made generic without dependency on KALLSYMS. Thus moving out function to a new file ksyms_common.c. With this patch code is just moved to new file and no functional change. Co-developed-by: Onkarnath Signed-off-by: Onkarnath Signed-off-by: Maninder Singh Reviewed-by: Zhen Lei --- earlier conversations:(then it has dependancy on other change, but that was stashed from linux-next, now it can be pushed) https://lore.kernel.org/lkml/202205111525.92B1C597@keescook/T/ https://lkml.org/lkml/2022/4/13/47 v1 -> v2: separate out bpf and kallsyms change v2 -> v3: make kallsym changes in2 patches, non functional and functional change v3 -> v4: patch order changed, file name changed form knosyms -> ksyms_common and copyright header modified. v4 -> v5: license changed to kallsyms.c file, and bpf changes are dropped as confirmed from BPF side: https://lore.kernel.org/lkml/CAEf4Bzb4B9FxMnf3t81D22FWkciLOvwDPLY0BbEPGGe7R5QPrg@mail.gmail.com/T/ kernel/Makefile | 2 +- kernel/kallsyms.c | 35 --------------------------------- kernel/ksyms_common.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 kernel/ksyms_common.c diff --git a/kernel/Makefile b/kernel/Makefile index f9e3fd9195d9..3947122d618b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \ extable.o params.o \ kthread.o sys_ni.o nsproxy.o \ notifier.o ksysfs.o cred.o reboot.o \ - async.o range.o smpboot.o ucount.o regset.o + async.o range.o smpboot.o ucount.o regset.o ksyms_common.o obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o obj-$(CONFIG_MULTIUSER) += groups.o diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 8193e947aa10..0f82c3d5a57d 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -907,41 +907,6 @@ late_initcall(bpf_ksym_iter_register); #endif /* CONFIG_BPF_SYSCALL */ -static inline int kallsyms_for_perf(void) -{ -#ifdef CONFIG_PERF_EVENTS - extern int sysctl_perf_event_paranoid; - if (sysctl_perf_event_paranoid <= 1) - return 1; -#endif - return 0; -} - -/* - * We show kallsyms information even to normal users if we've enabled - * kernel profiling and are explicitly not paranoid (so kptr_restrict - * is clear, and sysctl_perf_event_paranoid isn't set). - * - * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to - * block even that). - */ -bool kallsyms_show_value(const struct cred *cred) -{ - switch (kptr_restrict) { - case 0: - if (kallsyms_for_perf()) - return true; - fallthrough; - case 1: - if (security_capable(cred, &init_user_ns, CAP_SYSLOG, - CAP_OPT_NOAUDIT) == 0) - return true; - fallthrough; - default: - return false; - } -} - static int kallsyms_open(struct inode *inode, struct file *file) { /* diff --git a/kernel/ksyms_common.c b/kernel/ksyms_common.c new file mode 100644 index 000000000000..3840fa1c9c86 --- /dev/null +++ b/kernel/ksyms_common.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ksyms_common.c: A split of kernel/kallsyms.c + * Contains a few generic function definations independent of config KALLSYMS. + */ +#include +#include + +#ifdef CONFIG_KALLSYMS +static inline int kallsyms_for_perf(void) +{ +#ifdef CONFIG_PERF_EVENTS + extern int sysctl_perf_event_paranoid; + + if (sysctl_perf_event_paranoid <= 1) + return 1; +#endif + return 0; +} + +/* + * We show kallsyms information even to normal users if we've enabled + * kernel profiling and are explicitly not paranoid (so kptr_restrict + * is clear, and sysctl_perf_event_paranoid isn't set). + * + * Otherwise, require CAP_SYSLOG (assuming kptr_restrict isn't set to + * block even that). + */ +bool kallsyms_show_value(const struct cred *cred) +{ + switch (kptr_restrict) { + case 0: + if (kallsyms_for_perf()) + return true; + fallthrough; + case 1: + if (security_capable(cred, &init_user_ns, CAP_SYSLOG, + CAP_OPT_NOAUDIT) == 0) + return true; + fallthrough; + default: + return false; + } +} +#endif -- 2.17.1