Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6591139rwd; Mon, 5 Jun 2023 22:06:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6UgS4UQx7K2ge10l+LjGaWev/q1Giq3udQ+hy4LZZw7JU4GvplyOSDF364Uw2On7JNOrIT X-Received: by 2002:a92:c090:0:b0:33c:1c4:7fe with SMTP id h16-20020a92c090000000b0033c01c407femr1169774ile.3.1686028012878; Mon, 05 Jun 2023 22:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686028012; cv=none; d=google.com; s=arc-20160816; b=VVy/7fuIHc347+Mo+DihCRielc1r72EU4Mx4bUP/w/phgfRn2bZ0q6R2QBETxVtbWd AAy9Q6Ilk0ClIN3rWm+ax8rpbWtJJ6t8sJMvTuoQS06TqoxRl39EUjhV6mm6vIK2CtmU /u8LCW0Sp/e4eLDy7ygYx1edtG96pEWkF+aiKT+ESZn4KCLUVfuwSruCdZXzC0Ztlkzt yUkiWBcsbye2TMicKaQkYJR9wu0KNkSyjGSSlfw4xrCHBnbj5frX/999ytnlogVcg0GQ 7vEjHqRLCbYrOtoZmlNSPjF/ddWDFhgFk9XPNjYTN3Icnfg5hZq0GL4XgCx5xFfyRyiV nyLg== 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=UPFI0Fr7ya420xXG7/qmyA3ANnUzZPRg9R0PJ6qxvac=; b=uAooTl6PBriSS9R5R8aHCuHU2DVCHnVWbiFKZqOJewtj80AyHwDrIjxgocnlI2Dhg0 YuQogkuxoxejvn9rV9xVwrvjgItcXlx5wCTUM9lxOW22ceZ+5cF7nsNCQg60hwcZneSr ReiAslzpUylpMXyZjKGCQ7JY023y1XwTxdb1KRebhQLjp9b2NgeulVJYDJZtJzk5TqiM CZkO/yakE93kAsazNDvTATdAcHR1KGYI/vLRkyfzGdsuTvlKNDaTVgf8ONTNvVN5ph4a ltp6c0OTh69i0hQYLj9aTB3aJooNlXt6oimFGEX481ePD3dL9EkkWD2vo4qD/TMuXLwy qwMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=MQTZa+WJ; 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 k62-20020a636f41000000b005211941267asi6469772pgc.153.2023.06.05.22.06.40; Mon, 05 Jun 2023 22:06:52 -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=MQTZa+WJ; 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 S233408AbjFFE24 (ORCPT + 99 others); Tue, 6 Jun 2023 00:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbjFFE2v (ORCPT ); Tue, 6 Jun 2023 00:28:51 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD23187 for ; Mon, 5 Jun 2023 21:28:48 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230606042843epoutp02945155c009fcedf4dd34010b9b46ec11~l93ZgDZ0K2444324443epoutp02d for ; Tue, 6 Jun 2023 04:28:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230606042843epoutp02945155c009fcedf4dd34010b9b46ec11~l93ZgDZ0K2444324443epoutp02d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1686025723; bh=UPFI0Fr7ya420xXG7/qmyA3ANnUzZPRg9R0PJ6qxvac=; h=From:To:Cc:Subject:Date:References:From; b=MQTZa+WJslaNKMGhI0Kio7JA9mb0rvrV+H+Ck1PZTsvzZhRqAwXjJWrZTRfezlIik 3Lz2N2CxSyXI1UfnHbS+fzieeERAE9TGENLbhrbypQaipy2Kzv6bIBQQIrWk4yGcO0 RdAitLzxLQxOvSlgwwElcLTyj9waZMvmhRh0FG1k= Received: from epsmges5p2new.samsung.com (unknown [182.195.42.74]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20230606042842epcas5p3eb897c6d960d8f31f28f6dd854176e09~l93YawC7Z3179831798epcas5p3L; Tue, 6 Jun 2023 04:28:42 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 67.18.44881.9F5BE746; Tue, 6 Jun 2023 13:28:41 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230606042812epcas5p262df978931619b2d62e493d08147e120~l929LShmh2556625566epcas5p2C; Tue, 6 Jun 2023 04:28:12 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230606042812epsmtrp1cbf27e575176fc8450b477e77f929137~l929I3EUW0584405844epsmtrp1_; Tue, 6 Jun 2023 04:28:12 +0000 (GMT) X-AuditID: b6c32a4a-c47ff7000001af51-7b-647eb5f9c379 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id C3.13.28392.CD5BE746; Tue, 6 Jun 2023 13:28:12 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230606042807epsmtip1ac638ff8d094c6ebba5cb5c8d82d3039~l924Ng6aB1859118591epsmtip1A; Tue, 6 Jun 2023 04:28:07 +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 v4 1/3] kallsyms: move kallsyms_show_value() out of kallsyms.c Date: Tue, 6 Jun 2023 09:58:00 +0530 Message-Id: <20230606042802.508954-1-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0yTVxjGc75bS2PNB7h4BMWMYYZk0o7JciAyFzTui7MJIyMx6DIa+qV0 a7G2sO7mVmZTBxus3hIsHcKEcRkO6WAWtOPWUF1wmThJC8FghDHsOmkrl3LJRvuVzP9+7/O+ z3nOe3L4eEwdFcdXFJewmmKpMpESED8P7k7eE+z6TCa+vpiJXANlBFpcqcHR0+A4D7V1lmEo 4HBSyDPoB+hK/QKOzvjsOBpw9vKQxZ2GvrA1Y8hxwYyj4a9UaO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V hJvnrZh59iRNzctPQSKCixEH+eEyTvwbZdUy8VoDAAA= X-CMS-MailID: 20230606042812epcas5p262df978931619b2d62e493d08147e120 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20230606042812epcas5p262df978931619b2d62e493d08147e120 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, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 --- 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. 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..e776f12f0f5a --- /dev/null +++ b/kernel/ksyms_common.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * 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