为什么内核版本 5.4.156 上的 kallsyms 和 System.map 中缺少 security_path_* 符号?

发布于 2025-01-10 18:26:45 字数 1423 浏览 2 评论 0原文

我无法加载使用 kprobe 跟踪路径重命名的 eBPF 脚本:

int kprobe__security_path_rename( struct pt_regs *ctx, const struct path *old_dir, struct dentry *old_dentry, const struct path *new_dir, struct dentry *new_dentry )
{
    ...
}

它在我的 Ubuntu 计算机(内核 5.13.0)上运行良好,但在 AWS 节点(内核 5.4.156)上失败,并出现以下错误:

sh-4.2$ sudo ./tracker.py
cannot attach kprobe, probe entry may not exist
Traceback (most recent call last):
  File "./tracker.py", line 698, in <module>
    bpf = BPF(text=program)
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 372, in __init__
    self._trace_autoload()
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 1232, in _trace_autoload
    fn_name=fn.name)
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 684, in attach_kprobe
    (fn_name, event))
Exception: Failed to attach BPF program b'kprobe__security_path_rename' to kprobe b'security_path_rename'

我检查了 < code>/proc/kallsyms 和 /boot/System.map-$(uname -r) 以及符号security_path_{mknod,mkdir,unlink,rename} 全部存在于我的计算机上,但在 AWS 节点上缺失。

我还观察到,将 AWS 内核版本更新到 5.4.176 后,符号出现并且我的程序可以运行。然而,这些符号都出现在所有(相关)内核版本的源代码中,标记为staticnotrace,并通过<代码>EXPORT_SYMBOL。

不能在内核 5.4.156 上对这些符号进行 kprobed 吗?

I am failing to load an eBPF script that traces path renames by using kprobe:

int kprobe__security_path_rename( struct pt_regs *ctx, const struct path *old_dir, struct dentry *old_dentry, const struct path *new_dir, struct dentry *new_dentry )
{
    ...
}

It works fine on my Ubuntu machine (kernel 5.13.0), but fails on an AWS node (kernel 5.4.156) with the following error:

sh-4.2$ sudo ./tracker.py
cannot attach kprobe, probe entry may not exist
Traceback (most recent call last):
  File "./tracker.py", line 698, in <module>
    bpf = BPF(text=program)
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 372, in __init__
    self._trace_autoload()
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 1232, in _trace_autoload
    fn_name=fn.name)
  File "/usr/lib/python3.7/site-packages/bcc/__init__.py", line 684, in attach_kprobe
    (fn_name, event))
Exception: Failed to attach BPF program b'kprobe__security_path_rename' to kprobe b'security_path_rename'

I checked /proc/kallsyms and /boot/System.map-$(uname -r) and indeed the symbols security_path_{mknod,mkdir,unlink,rename} all exist on my machine and are missing on the AWS node.

I also observed that after updating the AWS kernel version to 5.4.176 the symbols appear and my program works. However, these symbols all appear in the source of all (relevant) kernel versions, are not marked static or notrace and are explicitly exported via EXPORT_SYMBOL.

Can't these symbols be kprobed on kernel 5.4.156?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2025-01-17 18:26:45

我找到了原因。该问题与内核版本没有直接关系,而是与内核配置有关。

显然,AWS 节点的内核版本 5.4.156 是在没有 CONFIG_SECURITY_PATH 的情况下配置的,而同一节点的较新内核 5.4.176 是使用此标志配置的。在前面的配置中,问题中提到的 security_path_* 符号不存在,因为它们的整个代码路径受到 #ifdef 的保护。

可以通过检查配置文件来测试启用了哪些内核配置标志,例如使用以下命令之一:

grep CONFIG_SECURITY_PATH /boot/config-`uname -r`
grep CONFIG_SECURITY_PATH /boot/config
gunzip < /proc/config.gz | grep CONFIG_SECURITY_PATH

I found the cause. The problem was not directly related to kernel versions, but rather to kernel config.

Apparently, the kernel version 5.4.156 for AWS nodes was configured without CONFIG_SECURITY_PATH, while newer kernel 5.4.176 for the same node was configured with this flag. In the former configuration, the security_path_* symbols mention in the question do not exist since their whole code path is guarded with #ifdefs.

One can test which kernel configuration flags are enabled by inspecting the config file, e.g. use one of the following commands:

grep CONFIG_SECURITY_PATH /boot/config-`uname -r`
grep CONFIG_SECURITY_PATH /boot/config
gunzip < /proc/config.gz | grep CONFIG_SECURITY_PATH
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文