lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1640157803-106978-1-git-send-email-xiaojiangfeng@huawei.com>
Date:   Wed, 22 Dec 2021 15:23:23 +0800
From:   Jiangfeng Xiao <xiaojiangfeng@...wei.com>
To:     <peterz@...radead.org>, <mingo@...hat.com>, <acme@...nel.org>,
        <mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
        <jolsa@...hat.com>, <namhyung@...nel.org>, <james.clark@....com>,
        <leo.yan@...aro.org>, <shaolexi@...wei.com>, <qiuxi1@...wei.com>,
        <wangbing6@...wei.com>, <nixiaoming@...wei.com>,
        <xiaojiangfeng@...wei.com>
CC:     <linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] perf dso: Avoid copying redundant kallsyms in th buildid_dir

The issue is occurs in following step:
(1)copy the kernel module (such as test.ko) to /root directory
(2)load the kernel module (such as insmod test.ko)
(3)run perf-record as: perf record sleep 1
Then /proc/kallsyms will be copied not only to
/root/.debug/[kernel.kallsyms]/<buildid>/kallsyms,
but also be copied to
/root/.debug/[test]/<buildid>/kallsyms(this is redundant).

Say a kallsyms file content takes 5MB memory,
100 out-of-tree kernel modules will take 500MB,
which is not bearable on embedded environment.

__cmd_record():
  __perf_session__new():
    perf_session__create_kernel_maps():
      machine__create_kernel_maps():
        machine__create_modules():
          machine__set_modules_path(): perf will only search for kernel
                                      modules in "/lib/modules/`uname -r`/"
                                      /root/test.ko is not in scope.
            maps__set_modules_path_dir():
              maps__set_module_path():
                dso__set_long_name(): the dso->long_name of test.ko has
                                      not changed, it is still [test].

record__finish_output():
  perf_session__write_header():
    [...]
      dso__cache_build_id():
        bool is_kallsyms = dso__is_kallsyms(dso);
          dso__is_kallsyms(): return dso->kernel&&dso->long_name[0] != '/';
                              [test] will be wrongly judged as kallsyms,
                              and then the value of is_kallsyms is true.
        build_id_cache__add_b(, is_kallsyms,):
          build_id_cache__add_s(, is_kallsyms,):
            build_id_cache__add(, is_kallsyms,):
              if (is_kallsyms)
                copyfile("/proc/kallsyms", filename): /proc/kallsyms will
                be copied to /root/.debug/[test]/<buildid>/kallsyms.

Why can this modification can avoid the redundancy of kallsyms:
  if (dso->kernel == DSO_SPACE__KERNEL) there are only two possibilities,
  one is dso__is_kallsyms, and the other is dso__is_kmod. After
  modification, [test] is no longer incorrectly judged as kallsyms.
Why can dso__is_kmod judge correctly?
  __cmd_record():
    __perf_session__new():
      perf_session__create_kernel_maps():
        machine__create_kernel_maps():
          machine__create_modules():
            modules__parse(): for each line in /proc/modules,
                              not just in "/lib/modules/`uname -r`/".
              machine__create_module():
                machine__addnew_module_map():
                  machine__findnew_module_dso():
                    dso__set_module_info(): assign dso->symtab_type to
                    DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE and so on.

Reported-by: Lexi Shao <shaolexi@...wei.com>
Signed-off-by: Jiangfeng Xiao <xiaojiangfeng@...wei.com>
---
 tools/perf/util/dso.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 011da39..57a6ab5 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -380,9 +380,17 @@ static inline bool dso__is_kcore(struct dso *dso)
 	       dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE;
 }
 
+static inline bool dso__is_kmod(struct dso *dso)
+{
+	return dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
+		dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
+		dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
+		dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
+}
+
 static inline bool dso__is_kallsyms(struct dso *dso)
 {
-	return dso->kernel && dso->long_name[0] != '/';
+	return dso->kernel && !dso__is_kmod(dso);
 }
 
 void dso__free_a2l(struct dso *dso);
-- 
1.8.5.6

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ