Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5120252rwd; Sun, 4 Jun 2023 21:21:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QgPNoxYTSglzFKqhks9WPE926k7Ni6sc7sKLwXJc3nbotRZTwTyhtJq018m/RVyDwBeA2 X-Received: by 2002:a17:90a:c902:b0:250:2384:120d with SMTP id v2-20020a17090ac90200b002502384120dmr6521474pjt.19.1685938873737; Sun, 04 Jun 2023 21:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685938873; cv=none; d=google.com; s=arc-20160816; b=J48F10SiZH4L84vDoWDzHetD7rbgxb3owGx4HoqdnGc7W7lMg4Q2CdmQS4+orpw2+T ep8yqLJ+j+o/+FsKthm9ZLXBPpKtRNq2Ifdn/souI/4tMp/cqjG+BMOJ+1jOQ9htXMTM xVqQpt+kX/DeKm0ZsCFpFG6dciHrrVXKqZGs/z+66eQDJ+uprofKM84KHaRJX3xwzhBd sgsedC/SpFGX5uYMgPqBIpzCbCeuSnwR35jIS38nhvUMAAm6fcPtpFi2/OoMxXpTZQR/ ncrv2PIl+5DcyIbrhWwjqLGUO/sDiwCNfXHwnb/bMlq4VeGyCPpkZTkPUXwRBYZ1iqjX 2BJw== 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=4EdxGjMWJn2JfCI0JELUBSu8bBR8MwE5bGC3vqvog7Y=; b=oEfFM3HG0eBCVAXsV4yjl/qr+/L3xtF4J6T9iV5MKY/RyvogM48jeq6LyN8hTU2YZG PdxgKO4TzjohoxUxViclq0H0QVWAfQd3FcrONunIaudOMFkkCOQ3V/zTvpkDkDqobv6W kwFlkaz1TsglTUiWTn9+OBQo1WjbEyX2buYnDlU6b0+0d3zJlU2/T6d7z6Mq3NYtMlad QJoeY3sMAiEvTcCV2sGEPE/I9zQSqcBaXmQqBmosrH4OTBFiiiLe+1QLOUsTldsABpjm Vqt6TH8SlB2zRRa3c7jprs/unNSqMd2uR1JA5BDn8gtcTUY4XzTMr/65Kd1rM7FLlp2C gq2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=PwMSMqen; 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 i8-20020a639d08000000b0053b86623b3asi4872965pgd.577.2023.06.04.21.21.01; Sun, 04 Jun 2023 21:21:13 -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=PwMSMqen; 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 S233043AbjFEELn (ORCPT + 99 others); Mon, 5 Jun 2023 00:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233041AbjFEELT (ORCPT ); Mon, 5 Jun 2023 00:11:19 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BE781998 for ; Sun, 4 Jun 2023 21:09:41 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230605040937epoutp045ec0c6197fa19e52ab37457708cb817a~lp9cOAd880567505675epoutp04E for ; Mon, 5 Jun 2023 04:09:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230605040937epoutp045ec0c6197fa19e52ab37457708cb817a~lp9cOAd880567505675epoutp04E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1685938177; bh=4EdxGjMWJn2JfCI0JELUBSu8bBR8MwE5bGC3vqvog7Y=; h=From:To:Cc:Subject:Date:References:From; b=PwMSMqen65TqhP64/eeBw8wRbUdfIeOORlJd3m71ZGSJ2t02ClvQ8Cabl9IFQJO35 02OBV/8+SqqgD7oST2jejUYzPRYfrEf2VzIR2pi3wF/zgoG/oICapLApJjSD9YrhkR 5M5YboPBG+tmt3CcrfUOdQkeLPNMFMqdubB17/u4= Received: from epsmges5p1new.samsung.com (unknown [182.195.42.73]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20230605040936epcas5p1e9c91a397d374fe85d3e490793f48609~lp9a3iDJ12840328403epcas5p15; Mon, 5 Jun 2023 04:09:36 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D9.6B.04567.FFF5D746; Mon, 5 Jun 2023 13:09:36 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230605040744epcas5p21968bee09fba5c3505a729fe2f57c507~lp7yiGBU71115111151epcas5p2a; Mon, 5 Jun 2023 04:07:44 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230605040744epsmtrp2349389775d2c0e03e8140da802e0f5ab~lp7ygs5xF1080610806epsmtrp2W; Mon, 5 Jun 2023 04:07:44 +0000 (GMT) X-AuditID: b6c32a49-db3fe700000011d7-d8-647d5fff6686 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id A7.B8.28392.F8F5D746; Mon, 5 Jun 2023 13:07:43 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230605040738epsmtip23ac210ce26d7c724f2b2ab94d60d31fd~lp7tqqucA0036900369epsmtip2o; Mon, 5 Jun 2023 04:07:38 +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 v3 1/3] kallsyms: move kallsyms_show_value() out of kallsyms.c Date: Mon, 5 Jun 2023 09:37:29 +0530 Message-Id: <20230605040731.13828-1-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Sf1CTZRzved93737o4nV4+giFObRkxYDOrseOlAq7V++8qLw6tU4GvIK1 AW388LcgHN0gdoOwE8YJXHDMxYUN5uFM1sZqZ0XGgBx4GKdQxBA3tjmQ0GAvXP73+X6+n8/3 8/0+9/BwURMZwTuSnccos2VyMSkgLvfESGKfSj2VEd8zjCOXrZhAwXkdjvxzt7iorbMYQz67 g0TunhmAvm56gKPPvddwZHNYuKh+6GV0tkuPIXtNHY5+rVCgv7srMdRvridRT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yaWbgy/M+ijYu 6QHxuWvFJqh8em/cPUGJpTgj0VCLuag4EQA4+1cdVwMAAA== X-CMS-MailID: 20230605040744epcas5p21968bee09fba5c3505a729fe2f57c507 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20230605040744epcas5p21968bee09fba5c3505a729fe2f57c507 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 knosyms.c. With this patch code is just moved to new file and no functional change. Next patch will enable defination of function for all cases. Co-developed-by: Onkarnath Signed-off-by: Onkarnath Signed-off-by: Maninder Singh --- earlier conversations:(then it has dependancy on other change, but that was stashed from linux-next, now it can be pushed) https://lkml.org/lkml/2022/5/11/212 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 kernel/Makefile | 2 +- kernel/kallsyms.c | 35 ---------------------------------- kernel/knosyms.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 kernel/knosyms.c diff --git a/kernel/Makefile b/kernel/Makefile index f9e3fd9195d9..918d3e9b14bc 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 knosyms.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/knosyms.c b/kernel/knosyms.c new file mode 100644 index 000000000000..9e2c72a89ea5 --- /dev/null +++ b/kernel/knosyms.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 Samsung Electronics Co., Ltd + * + * A split of kernel/kallsyms.c + * It will contain 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