Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp560513rwd; Wed, 31 May 2023 02:08:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6yapgcdv61MfWnfH/wX6kjKMpn9n7YtoTO8SdXYd6XXvG6zj5ZvWxl+LJFOJmziDw26+8N X-Received: by 2002:a05:6358:52d0:b0:123:2d9a:5edb with SMTP id z16-20020a05635852d000b001232d9a5edbmr1345405rwz.15.1685524114118; Wed, 31 May 2023 02:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685524114; cv=none; d=google.com; s=arc-20160816; b=lvAXw4VirvaxfGVLNqmQBFIgxuZY1mtCMEXuftD6g50Z6gpNqtaV34ZLCNaZCAi34F XYZOv7VD38FyQUfnw4KpIU6+rOve7h1gJf+/fmLn20+VqPZL3ZgcZ+qR+Y7RnyNVAPff EPd5qFsunqE0f3EbacCTqj4NmNH5UFZMTczBefCfPdim67vSaFbG513sMDAtIVg1zUlG HHs3ZEzQQPJKFn65AWtnXpTSnTmIKF21QomJDFecqs+GKvgIyhWHpW5rmEZzziUlfC9e cX7Vz4Ifrl3qDRrl/y+zD/usgK3GzHCHtKG7P00eJyGXnFAGPXnGAtQUpuzQTrja0lVy a36Q== 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:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=s0725QwcTW3BEZD38ZtJrSmnGOHUK1uQ30n4RkrditY=; b=h0mSsifot85lyavrSDqfACWWlElo8EQZtmPyvcDQZSc5XpjHeEFQAmRmdQMI3jcRiZ 2IcXxR7u/+IpXpCEtZNGNIMf6kS7ZzUALQW/XbERTXP1oHXYT7oKCAPJTiwClySCFsF+ eJNgfkY/tTx/hMtsVVPjKlMpK1aFKIOzi8ApcMtD98xM2Kuumqc5Vh6/2S14JchnaZ/6 Cz06bQxFtLiDPPqJxOmIIVdT2sngplfjPLYwRr5aRwoCyI/h3vF6M8hMXDc+wbAaUO4O TjEkjmWSULP/C3fvH67wmL0pDvGaK+mPLs3UYJ2GKMT33GPdSb76PLDJbdJX5Z5kmKxv Bv3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="ObX9n//k"; 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 p1-20020a17090a2d8100b0024b91006d29si298114pjd.48.2023.05.31.02.08.21; Wed, 31 May 2023 02:08:34 -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="ObX9n//k"; 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 S235136AbjEaItV (ORCPT + 99 others); Wed, 31 May 2023 04:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235242AbjEaIsy (ORCPT ); Wed, 31 May 2023 04:48:54 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9C0192 for ; Wed, 31 May 2023 01:48:26 -0700 (PDT) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230531084824epoutp01a28cacdb532824120af0d66b965205dc~kLibRiByK1098310983epoutp01e for ; Wed, 31 May 2023 08:48:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230531084824epoutp01a28cacdb532824120af0d66b965205dc~kLibRiByK1098310983epoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1685522904; bh=s0725QwcTW3BEZD38ZtJrSmnGOHUK1uQ30n4RkrditY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObX9n//kiXZT985nYnGdIh0Xuw+OKOZH/Ft8FM6LPAFnWd71KuD7jN4Qq+kuVSnp0 ZACNtL1tacjZRlMagKFhPPx+HwQbkqUzIrBf1OX3vIXtIYelhcYlNFoOhRmKkmMf81 urv2bgh6o1Mh+rf24HaC8aD22kcxOVHWxs2XjnMc= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20230531084824epcas5p4e332b734c30995d8cf0ce80497257a50~kLiam8fGy2502925029epcas5p4f; Wed, 31 May 2023 08:48:24 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id BF.B4.16380.7D907746; Wed, 31 May 2023 17:48:23 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20230531084808epcas5p4a782bf6bb5655f2d320c246057e7bb63~kLiLrvqHG2996829968epcas5p4Y; Wed, 31 May 2023 08:48:08 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230531084808epsmtrp2b0aabe5ad0888f954b4264a9bba6a819~kLiLqZRrJ1909719097epsmtrp2W; Wed, 31 May 2023 08:48:08 +0000 (GMT) X-AuditID: b6c32a4b-56fff70000013ffc-9f-647709d7a89e Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id D0.47.28392.7C907746; Wed, 31 May 2023 17:48:07 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230531084802epsmtip1f97dd27b6b24d3ca7e1a9da5b235d9a1~kLiG9Q-0z2391523915epsmtip1V; Wed, 31 May 2023 08:48:02 +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 v2 2/2] kallsyms: add kallsyms_show_value defination in all cases Date: Wed, 31 May 2023 14:17:45 +0530 Message-Id: <20230531084745.877337-2-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531084745.877337-1-maninder1.s@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0ybVRjGd75L+7Wx8lkIOwNlBkcWLnZzzuWosC1G3ZeIMsE/jMucDf0G Q262IAMXLaPOjAmDARuUhnGbBYQxoExWuUhprCugGyop041b2RQC0pbZ0gFz5Stx/z3veX/v eZ735FC4uIUXQB1LzWDlqdLkYJ6QuDoQGvq8RZAl2+ncgyyGXAI5H1TiaGn5Dz5q1uViyGE0 8dDcgB2gupp/cfSVrQdHBlMfH2nG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8d0ux+KJbG+0HhmpBWy5HOt3UblBaTnf0dzwvtUbc1Z9ZjfI kcxSyZRUyFf3kFwmftP06ZJWjS3rtp9l+tf6MuP7jiNlNtXsSizFGYmGWsxFxYkAVddDy3ID AAA= X-CMS-MailID: 20230531084808epcas5p4a782bf6bb5655f2d320c246057e7bb63 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20230531084808epcas5p4a782bf6bb5655f2d320c246057e7bb63 References: <20230531084745.877337-1-maninder1.s@samsung.com> X-Spam-Status: No, score=-4.6 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,URIBL_BLOCKED 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 kallsyms_show_value return false if KALLSYMS is disabled, but it is getting used in module.c also for fetching module address. Thus when KALLSYMS is disabled, system will not print module load address: Earlier: ======= / # insmod test.ko / # lsmod test 12288 0 - Live 0x0000000000000000 (O) // No Module Load address / # With change: ========== / # insmod test.ko / # lsmod test 12288 0 - Live 0xffff800000fc0000 (O) // Module address / # cat /proc/modules test 12288 0 - Live 0xffff800000fc0000 (O) New file knosyms.c is added (name suggested by Kees Cook), which includes common defination irrespective of CONFIG_KALLSYMS. 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 include/linux/kallsyms.h | 10 +++----- kernel/Makefile | 2 +- kernel/kallsyms.c | 35 --------------------------- kernel/knosyms.c | 52 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 kernel/knosyms.c diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index fe3c9993b5bf..3f3559ba0c56 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -24,6 +24,9 @@ struct cred; struct module; +/* How and when do we show kallsyms values? */ +extern bool kallsyms_show_value(const struct cred *cred); + static inline int is_kernel_text(unsigned long addr) { if (__is_kernel_text(addr)) @@ -95,8 +98,6 @@ extern int sprint_backtrace_build_id(char *buffer, unsigned long address); int lookup_symbol_name(unsigned long addr, char *symname); int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); -/* How and when do we show kallsyms values? */ -extern bool kallsyms_show_value(const struct cred *cred); #else /* !CONFIG_KALLSYMS */ @@ -160,11 +161,6 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u return -ERANGE; } -static inline bool kallsyms_show_value(const struct cred *cred) -{ - return false; -} - static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long), void *data) { diff --git a/kernel/Makefile b/kernel/Makefile index b69c95315480..76efc634b1a4 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 77747391f49b..1dcb7051f852 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -961,41 +961,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..f2c8755e22e7 --- /dev/null +++ b/kernel/knosyms.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 Samsung Electronics Co., Ltd + * + * Author: + * Maninder singh + * Onkarnath + * + * A split of kernel/kallsyms.c + * to contain few generic function definations independent of config KALLSYMS + * or defined under KALLSYMS disabled. + */ + +#include +#include + +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; + } +} + -- 2.17.1