<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Ylarod’s Blog</title>
        <link>https://xtuly.cn/</link>
        <description>Stay hungry, stay foolish</description>
        <lastBuildDate>Fri, 12 Dec 2025 11:04:32 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2025, Ylarod</copyright>
        <item>
            <title><![CDATA[深入分析 Seccomp BPF ]]></title>
            <link>https://xtuly.cn/article/seccomp-bpf</link>
            <guid>https://xtuly.cn/article/seccomp-bpf</guid>
            <pubDate>Thu, 23 Oct 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[基于 GKI android12-5.10 内核源码，详细分析 Android 中 Seccomp BPF 的安装和验证全部流程，Seccomp User Notification 机制，以及 Android 上的 Seccomp BPF 使用。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-29438ec39d19802c874edaf6eb1baf88"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d1980659666efe39448cfc4" data-id="29438ec39d1980659666efe39448cfc4"><span><div id="29438ec39d1980659666efe39448cfc4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1980659666efe39448cfc4" title="概述"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">概述</span></span></h2><div class="notion-text notion-block-29438ec39d19814fb42ad29fcf067172">Seccomp (Secure Computing) 是 Linux 内核提供的一种安全机制，允许进程限制自己可以执行的系统调用。Seccomp Mode 2 (SECCOMP_MODE_FILTER) 使用 BPF (Berkeley Packet Filter) 程序实现灵活的系统调用过滤。但是不同于 eBPF，Seccomp BPF 使用 cBPF，对比 eBPF 仅保留了部分指令可以使用。</div><div class="notion-text notion-block-29538ec39d198050a998e0eb717bf156">Seccomp BPF 的安装和验证的主要流程如下：</div><div class="notion-text notion-block-29538ec39d1980ff8234c04dadf31dd9"><b>安装</b></div><ol start="1" class="notion-list notion-list-numbered notion-block-29538ec39d1980e7baf9f15c15709456" style="list-style-type:decimal"><li>用户空间通过 <code class="notion-inline-code">prctl</code> 提交 BPF 程序</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29538ec39d1980a7bd0de28141f22e0c" style="list-style-type:decimal"><li>内核验证权限（<code class="notion-inline-code">no_new_privs</code> 或 <code class="notion-inline-code">CAP_SYS_ADMIN</code>）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-29538ec39d1980ef9d4def403f4f51be" style="list-style-type:decimal"><li>从用户空间安全复制 BPF 指令</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-29538ec39d1980c498ebe3bdc807736d" style="list-style-type:decimal"><li>执行严格的 BPF 验证（基本检查 → 经典检查 → seccomp 特定检查）</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-29538ec39d1980e8b78be9dadd86beb5" style="list-style-type:decimal"><li>转换为 eBPF 格式并尝试 JIT 编译</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-29538ec39d1980b5a89cdf7901f2ffb7" style="list-style-type:decimal"><li>构建系统调用缓存以优化性能</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-29538ec39d19804c8238e43748e4eaeb" style="list-style-type:decimal"><li>附加到进程的过滤器链</li></ol><ol start="8" class="notion-list notion-list-numbered notion-block-29538ec39d1980d4b340fd6beeac8c2a" style="list-style-type:decimal"><li>设置 <code class="notion-inline-code">TIF_SECCOMP</code> 标志启用检查</li></ol><div class="notion-text notion-block-29538ec39d1980e8b6d4f413f6003981"><b>验证</b></div><ol start="1" class="notion-list notion-list-numbered notion-block-29538ec39d1980bdb69eee4327d525f0" style="list-style-type:decimal"><li>系统调用入口检测 <code class="notion-inline-code">TIF_SECCOMP</code> 标志</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29538ec39d1980a188e0c98bb05923a3" style="list-style-type:decimal"><li>填充 <code class="notion-inline-code">seccomp_data</code> 结构（系统调用号、参数、架构等）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-29538ec39d1980b09344f5a102164765" style="list-style-type:decimal"><li>首先检查缓存（快速路径）</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-29538ec39d198048a842d915b3e899fd" style="list-style-type:decimal"><li>遍历过滤器链，执行每个 BPF 程序</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-29538ec39d19806e93f4e42d5051ec1b" style="list-style-type:decimal"><li>选择最严格的返回动作</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-29538ec39d198087886ccf70ad3996e6" style="list-style-type:decimal"><li>根据动作类型处理（允许、拒绝、跟踪、杀死等）</li></ol><ol start="7" class="notion-list notion-list-numbered notion-block-29538ec39d1980328039da4219a4d287" style="list-style-type:decimal"><li>记录审计日志（如果配置）</li></ol><div class="notion-text notion-block-29538ec39d19802c824cd79531a8997a">具体源码分析见下文</div><hr class="notion-hr notion-block-29438ec39d1981e78c7cd7132836127c"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d19815dba73c3268c8b2cbd" data-id="29438ec39d19815dba73c3268c8b2cbd"><span><div id="29438ec39d19815dba73c3268c8b2cbd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19815dba73c3268c8b2cbd" title="安装流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装流程</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19810aba54e341c8168772" data-id="29438ec39d19810aba54e341c8168772"><span><div id="29438ec39d19810aba54e341c8168772" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19810aba54e341c8168772" title="1. 用户空间接口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 用户空间接口</span></span></h3><div class="notion-text notion-block-29438ec39d198174b16dd741f5416eac">用户通过 <code class="notion-inline-code">prctl</code> 系统调用安装 seccomp 过滤器：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198150816ff5d5f5f722d6" data-id="29438ec39d198150816ff5d5f5f722d6"><span><div id="29438ec39d198150816ff5d5f5f722d6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198150816ff5d5f5f722d6" title="2. 内核调用链"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 内核调用链</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198148886ac6c6be2a3f5c" data-id="29438ec39d198148886ac6c6be2a3f5c"><span><div id="29438ec39d198148886ac6c6be2a3f5c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198148886ac6c6be2a3f5c" title="2.1 入口函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 入口函数</span></span></h4><div class="notion-text notion-block-29438ec39d19811a9ec1e02c543753a5">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1962">kernel/seccomp.c:1962</a></div><div class="notion-text notion-block-29438ec39d19818ea57be1a60858beb6">该函数是 <code class="notion-inline-code">prctl(PR_SET_SECCOMP, ...)</code> 的内核入口点，负责：
- 根据 <code class="notion-inline-code">seccomp_mode</code> 确定操作类型（STRICT 或 FILTER）
- 将参数转换为内部格式
- 调用 <code class="notion-inline-code">do_seccomp()</code> 执行实际操作</div><div class="notion-text notion-block-29438ec39d19813f91fbff89904c5a67"><b>关键代码流程</b>:</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981e2b500e00296c58c64" data-id="29438ec39d1981e2b500e00296c58c64"><span><div id="29438ec39d1981e2b500e00296c58c64" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981e2b500e00296c58c64" title="2.2 统一入口处理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 统一入口处理</span></span></h4><div class="notion-text notion-block-29438ec39d1981ffad49f0d16659b8b7">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1924">kernel/seccomp.c:1924</a></div><div class="notion-text notion-block-29438ec39d198189aff8f7716561b764">该函数是 <code class="notion-inline-code">prctl</code> 和 <code class="notion-inline-code">seccomp</code> 系统调用的统一处理入口：
- <code class="notion-inline-code">SECCOMP_SET_MODE_STRICT</code>: 调用 <code class="notion-inline-code">seccomp_set_mode_strict()</code>
- <code class="notion-inline-code">SECCOMP_SET_MODE_FILTER</code>: 调用 <code class="notion-inline-code">seccomp_set_mode_filter()</code>
- <code class="notion-inline-code">SECCOMP_GET_ACTION_AVAIL</code>: 查询动作是否可用
- <code class="notion-inline-code">SECCOMP_GET_NOTIF_SIZES</code>: 获取通知结构大小</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981d58179f72e393d4985" data-id="29438ec39d1981d58179f72e393d4985"><span><div id="29438ec39d1981d58179f72e393d4985" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981d58179f72e393d4985" title="2.3 Filter 模式设置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.3 Filter 模式设置</span></span></h4><div class="notion-text notion-block-29438ec39d198116bd5beaeb7efd4655">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1787">kernel/seccomp.c:1787</a></div><div class="notion-text notion-block-29438ec39d1981eabcd6f756587c28d4">这是安装 BPF 过滤器的核心函数，执行以下步骤：</div><div class="notion-text notion-block-29438ec39d1981a7b9a1dd5587dc019d"><b>步骤 1：验证 flags</b></div><div class="notion-text notion-block-29438ec39d1981508fbcd36c36f95141">支持的 flags 包括：
- <code class="notion-inline-code">SECCOMP_FILTER_FLAG_TSYNC</code>: 同步所有线程
- <code class="notion-inline-code">SECCOMP_FILTER_FLAG_LOG</code>: 记录所有非 ALLOW 动作
- <code class="notion-inline-code">SECCOMP_FILTER_FLAG_SPEC_ALLOW</code>: 允许规避推测执行缓解
- <code class="notion-inline-code">SECCOMP_FILTER_FLAG_NEW_LISTENER</code>: 创建用户态通知监听器</div><div class="notion-text notion-block-29438ec39d19813ea14cf6cc4bddab98"><b>步骤 2：准备过滤器</b></div><div class="notion-text notion-block-29438ec39d1981848e2fedb65a246db3"><b>步骤 3：获取锁</b></div><div class="notion-text notion-block-29438ec39d198118a965caa7e34f9c1b"><b>步骤 4：检查并附加过滤器</b></div><div class="notion-text notion-block-29438ec39d198183bbded7bdb249ca49"><b>步骤 5：设置 seccomp 模式</b></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981fdbf32e6abe57b592a" data-id="29438ec39d1981fdbf32e6abe57b592a"><span><div id="29438ec39d1981fdbf32e6abe57b592a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981fdbf32e6abe57b592a" title="3. 过滤器准备"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 过滤器准备</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198187a54cc851801668f0" data-id="29438ec39d198187a54cc851801668f0"><span><div id="29438ec39d198187a54cc851801668f0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198187a54cc851801668f0" title="3.1 从用户空间复制过滤器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 从用户空间复制过滤器</span></span></h4><div class="notion-text notion-block-29438ec39d1981e29ebec07d4e0d5ce9">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#681">kernel/seccomp.c:681</a></div><div class="notion-text notion-block-29438ec39d19810b817debc5b0359f5a">该函数处理用户空间到内核空间的过滤器转换：</div><div class="notion-text notion-block-29438ec39d198177bf86cec900d251e7"><b>处理兼容模式</b>:</div><div class="notion-text notion-block-29438ec39d1981dbaaefde66077d54b2"><b>调用核心准备函数</b>:</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981fda6cefffed841cc78" data-id="29438ec39d1981fda6cefffed841cc78"><span><div id="29438ec39d1981fda6cefffed841cc78" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981fda6cefffed841cc78" title="3.2 核心过滤器准备"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.2 核心过滤器准备</span></span></h4><div class="notion-text notion-block-29438ec39d1981b89308e7a714d47078">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#629">kernel/seccomp.c:629</a></div><div class="notion-text notion-block-29438ec39d1981e09564c563a889a957"><b>权限检查</b>:</div><div class="notion-text notion-block-29438ec39d1981ecb56ede61e188ea3b">必须满足以下条件之一：
- 进程设置了 <code class="notion-inline-code">no_new_privs</code> 标志
- 进程具有 <code class="notion-inline-code">CAP_SYS_ADMIN</code> 能力</div><div class="notion-text notion-block-29438ec39d19810bbcedf26bc7140b14"><b>分配 seccomp_filter 结构</b>:</div><div class="notion-text notion-block-29438ec39d1981bbb789fbdfaa7ca173"><b>创建 BPF 程序</b>:</div><div class="notion-text notion-block-29438ec39d198145af0ef8fb22c1e0f0">这里调用了 <code class="notion-inline-code">net/core/filter.c</code> 中的函数，<code class="notion-inline-code">seccomp_check_filter</code> 作为转换函数传递。</div><div class="notion-text notion-block-29438ec39d1981dd879dd53e39ed8247"><b>初始化引用计数</b>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981ec9852d0142c40ae80" data-id="29438ec39d1981ec9852d0142c40ae80"><span><div id="29438ec39d1981ec9852d0142c40ae80" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981ec9852d0142c40ae80" title="4. BPF 程序创建与验证"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. BPF 程序创建与验证</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198177bafbf8a54028b0be" data-id="29438ec39d198177bafbf8a54028b0be"><span><div id="29438ec39d198177bafbf8a54028b0be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198177bafbf8a54028b0be" title="4.1 从用户空间创建 BPF 程序"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1 从用户空间创建 BPF 程序</span></span></h4><div class="notion-text notion-block-29438ec39d19815e8a37eb77d05ff7a1">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/net/core/filter.c#1414">net/core/filter.c:1414</a></div><div class="notion-text notion-block-29438ec39d198117b955f1314e26f504"><b>验证基本参数</b>:</div><div class="notion-text notion-block-29438ec39d1981f6afa8da1ded96be07"><b>分配 BPF 程序结构</b>:</div><div class="notion-text notion-block-29438ec39d198190b5eed17fe7dcc5b7"><b>从用户空间复制指令</b>:</div><div class="notion-text notion-block-29438ec39d1981d39efec1287ad3bbdd"><b>保存原始程序（用于检查点恢复）</b>:</div><div class="notion-text notion-block-29438ec39d19815da184dddb9e8e0533"><b>准备并验证过滤器</b>:</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198192b3bbff3a1d2e12d1" data-id="29438ec39d198192b3bbff3a1d2e12d1"><span><div id="29438ec39d198192b3bbff3a1d2e12d1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198192b3bbff3a1d2e12d1" title="4.2 准备 BPF 过滤器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2 准备 BPF 过滤器</span></span></h4><div class="notion-text notion-block-29438ec39d1981a28882e4f9ac436cf9">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/net/core/filter.c#1320">net/core/filter.c:1320</a></div><div class="notion-text notion-block-29438ec39d1981cd9f61e8f28423ad6f"><b>检查经典 BPF 指令</b>:</div><div class="notion-text notion-block-29438ec39d198196a8abc0be0f6da867">这一步验证：
- 指令长度不超过 <code class="notion-inline-code">BPF_MAXINSNS</code>
- 没有越界跳转
- 内存访问合法
- 不使用除零操作</div><div class="notion-text notion-block-29438ec39d19815888a3c6c2de2269d6"><b>执行 seccomp 特定转换</b>:</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d19814f8594c6317acd6139" data-id="29438ec39d19814f8594c6317acd6139"><span><div id="29438ec39d19814f8594c6317acd6139" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19814f8594c6317acd6139" title="4.3 Seccomp 特定检查"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.3 Seccomp 特定检查</span></span></h4><div class="notion-text notion-block-29438ec39d198189b194f23bcedb9bed">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#268">kernel/seccomp.c:268</a></div><div class="notion-text notion-block-29438ec39d198102b0bdc6a5af9fb12c">该函数对 seccomp BPF 程序进行特殊处理：</div><div class="notion-text notion-block-29438ec39d19814b8ab7c99cb3893792"><b>重定向数据加载指令</b>:</div><div class="notion-text notion-block-29438ec39d1981388c41d3c3931c4bfa">将 <code class="notion-inline-code">BPF_LD</code> 改为 <code class="notion-inline-code">BPF_LDX</code> 以确保从 <code class="notion-inline-code">seccomp_data</code> 结构加载数据，而不是网络包数据。</div><div class="notion-text notion-block-29438ec39d198186876ce8948f235f1b"><b>替换长度加载</b>:</div><div class="notion-text notion-block-29438ec39d198126a967e7d7b0429a01"><b>允许的指令白名单</b>:
只允许安全的 ALU、跳转、内存操作和返回指令，拒绝其他所有指令。</div><div class="notion-text notion-block-29438ec39d1981ceb655ec5c5444cd2f"><b>JIT 编译</b>:</div><div class="notion-text notion-block-29438ec39d198184825ed1d4757e59ae">如果架构支持，将 BPF 程序编译为原生机器码以提高性能。</div><div class="notion-text notion-block-29438ec39d198164bfbeea5838fca908"><b>解释器迁移</b>:</div><div class="notion-text notion-block-29438ec39d1981329029f7bebc99ce3f">如果无法 JIT 编译，将经典 BPF (cBPF) 转换为扩展 BPF (eBPF) 供解释器使用。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19818d9444f2ae82f25ddf" data-id="29438ec39d19818d9444f2ae82f25ddf"><span><div id="29438ec39d19818d9444f2ae82f25ddf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19818d9444f2ae82f25ddf" title="5. 附加过滤器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 附加过滤器</span></span></h3><div class="notion-text notion-block-29438ec39d198150b6a9ed4442e9e689">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#857">kernel/seccomp.c:857</a></div><div class="notion-text notion-block-29438ec39d1981fca3cad4a63542fb0a"><b>验证过滤器总长度</b>:</div><div class="notion-text notion-block-29438ec39d198199b421cda7c40c0e6e">限制：<code class="notion-inline-code">MAX_INSNS_PER_PATH = (1 &lt;&lt; 18) / sizeof(struct sock_filter) = 256KB</code></div><div class="notion-text notion-block-29438ec39d1981e79dbad93fd1cc1638"><b>链接过滤器</b>:</div><div class="notion-text notion-block-29438ec39d198186a749e96cd34e7ae8">过滤器以链表形式组织，新过滤器总是添加到链表头部。</div><div class="notion-text notion-block-29438ec39d1981a2aeb3f9f97e97129f"><b>线程同步（如果需要）</b>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19817faa1cfcc6f36c0dc9" data-id="29438ec39d19817faa1cfcc6f36c0dc9"><span><div id="29438ec39d19817faa1cfcc6f36c0dc9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19817faa1cfcc6f36c0dc9" title="6. 设置 Seccomp 模式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6. 设置 Seccomp 模式</span></span></h3><div class="notion-text notion-block-29438ec39d1981dfbd86c7b6a7363485">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#437">kernel/seccomp.c:437</a></div><div class="notion-text notion-block-29438ec39d19816d93b4e9e68cd7c4dc"><b>设置模式</b>:</div><div class="notion-text notion-block-29438ec39d1981d5a562f3fd98918e38"><b>内存屏障</b>:</div><div class="notion-text notion-block-29438ec39d19811fb30ac0e24ff4b5c1"><b>启用推测执行缓解</b>:</div><div class="notion-text notion-block-29438ec39d19819d8b4ad75394e5ee01"><b>设置 TIF_SECCOMP 标志</b>:</div><div class="notion-text notion-block-29438ec39d19813e8068da26518b9eb9">此标志导致内核在每次系统调用时检查 seccomp 过滤器。</div><hr class="notion-hr notion-block-29438ec39d1981ceb384d23a28b4ade1"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d19817389ddf82af7a53d3d" data-id="29438ec39d19817389ddf82af7a53d3d"><span><div id="29438ec39d19817389ddf82af7a53d3d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19817389ddf82af7a53d3d" title="验证执行流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">验证执行流程</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981b09d2ed60dbbb9fe72" data-id="29438ec39d1981b09d2ed60dbbb9fe72"><span><div id="29438ec39d1981b09d2ed60dbbb9fe72" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981b09d2ed60dbbb9fe72" title="1. 系统调用拦截"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 系统调用拦截</span></span></h3><div class="notion-text notion-block-29438ec39d198180bd4bfbbc9c602753">当进程执行系统调用时，如果设置了 <code class="notion-inline-code">TIF_SECCOMP</code> 标志，内核会在系统调用处理前调用 seccomp 检查。</div><div class="notion-text notion-block-29438ec39d1981c6afaac023ae877557"><b>架构相关入口</b>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981d18f13d9cc21395471" data-id="29438ec39d1981d18f13d9cc21395471"><span><div id="29438ec39d1981d18f13d9cc21395471" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981d18f13d9cc21395471" title="2. Seccomp 检查入口"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. Seccomp 检查入口</span></span></h3><div class="notion-text notion-block-29438ec39d19813796cdf129a63481d4">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1296">kernel/seccomp.c:1296</a></div><div class="notion-text notion-block-29438ec39d1981d99c4bdb78522e4236"><b>检查暂停标志</b>:</div><div class="notion-text notion-block-29438ec39d1981ba9de2edcabb4f120b"><b>获取系统调用号</b>:</div><div class="notion-text notion-block-29438ec39d19818eadead94283ba8496"><b>根据模式分发</b>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198113b918f06d2bdbedba" data-id="29438ec39d198113b918f06d2bdbedba"><span><div id="29438ec39d198113b918f06d2bdbedba" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198113b918f06d2bdbedba" title="3. 过滤器执行"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 过滤器执行</span></span></h3><div class="notion-text notion-block-29438ec39d198136b03fdd3e766a0185">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1158">kernel/seccomp.c:1158</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198143bed2cb6493b1372d" data-id="29438ec39d198143bed2cb6493b1372d"><span><div id="29438ec39d198143bed2cb6493b1372d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198143bed2cb6493b1372d" title="3.1 填充 seccomp_data"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 填充 seccomp_data</span></span></h4><div class="notion-text notion-block-29438ec39d19819ab974caefbfe51bc1">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#234">kernel/seccomp.c:234</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198178b7f4fce22392b78f" data-id="29438ec39d198178b7f4fce22392b78f"><span><div id="29438ec39d198178b7f4fce22392b78f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198178b7f4fce22392b78f" title="3.2 运行过滤器链"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.2 运行过滤器链</span></span></h4><div class="notion-text notion-block-29438ec39d198168abb0d8fc132ba9fb">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#394">kernel/seccomp.c:394</a></div><div class="notion-text notion-block-29438ec39d1981deba8be34e02b4cc09"><b>获取过滤器链</b>:</div><div class="notion-text notion-block-29438ec39d198164a319e060979478fb"><b>检查缓存</b>:</div><div class="notion-text notion-block-29438ec39d1981408203efe67aef2ac3">系统调用缓存优化：如果某个系统调用对所有过滤器都返回 ALLOW，将其缓存以避免重复执行 BPF 程序。</div><div class="notion-text notion-block-29438ec39d198157ade4edf825bcfcb8"><b>遍历过滤器链</b>:</div><div class="notion-text notion-block-29438ec39d1981acab6ad2620a074b74"><b>优先级规则</b>：
- 数值越小，优先级越高（更严格）
- <code class="notion-inline-code">SECCOMP_RET_KILL_PROCESS</code> &lt; <code class="notion-inline-code">SECCOMP_RET_KILL_THREAD</code> &lt; <code class="notion-inline-code">SECCOMP_RET_TRAP</code> &lt; … &lt; <code class="notion-inline-code">SECCOMP_RET_ALLOW</code></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981f4a5fbc3964f9a172d" data-id="29438ec39d1981f4a5fbc3964f9a172d"><span><div id="29438ec39d1981f4a5fbc3964f9a172d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981f4a5fbc3964f9a172d" title="3.3 BPF 程序执行"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.3 BPF 程序执行</span></span></h4><div class="notion-text notion-block-29438ec39d19815a9ecdc74448f607f3">BPF 程序通过以下方式之一执行：</div><ol start="1" class="notion-list notion-list-numbered notion-block-29438ec39d198158bb5ee2e401e0bbfa" style="list-style-type:decimal"><li><b>JIT 编译的原生代码</b>（如果 <code class="notion-inline-code">fp-&gt;jited == true</code>）</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29438ec39d1981099079eb778dd151ea" style="list-style-type:decimal"><li><b>eBPF 解释器</b>（如果未 JIT 编译）</li></ol><div class="notion-text notion-block-29438ec39d19819487a6c125a3e422f6">BPF 程序接收 <code class="notion-inline-code">seccomp_data</code> 结构作为输入，返回一个 32 位动作值。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198136bb77d16b1c58c3e7" data-id="29438ec39d198136bb77d16b1c58c3e7"><span><div id="29438ec39d198136bb77d16b1c58c3e7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198136bb77d16b1c58c3e7" title="4. 动作处理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 动作处理</span></span></h3><div class="notion-text notion-block-29438ec39d1981bf81a0c2b99d6d5426">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1181">kernel/seccomp.c:1181</a></div><div class="notion-text notion-block-29438ec39d198182a1d5fe0b16c6eafa">根据过滤器返回值执行相应动作：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d19816fbd8efcebb8fef204" data-id="29438ec39d19816fbd8efcebb8fef204"><span><div id="29438ec39d19816fbd8efcebb8fef204" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19816fbd8efcebb8fef204" title="4.1 SECCOMP_RET_ERRNO"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1 SECCOMP_RET_ERRNO</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198107844fcef1724d3db4" data-id="29438ec39d198107844fcef1724d3db4"><span><div id="29438ec39d198107844fcef1724d3db4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198107844fcef1724d3db4" title="4.2 SECCOMP_RET_TRAP"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2 SECCOMP_RET_TRAP</span></span></h4><div class="notion-text notion-block-29438ec39d1981149516c20065938178">发送的信号信息：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d19814db587c7803651003d" data-id="29438ec39d19814db587c7803651003d"><span><div id="29438ec39d19814db587c7803651003d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19814db587c7803651003d" title="4.3 SECCOMP_RET_TRACE"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.3 SECCOMP_RET_TRACE</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d198174ab09eff43460b581" data-id="29438ec39d198174ab09eff43460b581"><span><div id="29438ec39d198174ab09eff43460b581" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198174ab09eff43460b581" title="4.4 SECCOMP_RET_USER_NOTIF"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.4 SECCOMP_RET_USER_NOTIF</span></span></h4><div class="notion-text notion-block-29438ec39d198116b990c028fffe4e33">用户态通知机制：
1. 将系统调用信息发送给用户态监督进程
2. 阻塞当前进程等待响应
3. 根据用户态响应决定如何处理系统调用</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981e6a6cad9ea2632bc8a" data-id="29438ec39d1981e6a6cad9ea2632bc8a"><span><div id="29438ec39d1981e6a6cad9ea2632bc8a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981e6a6cad9ea2632bc8a" title="4.5 SECCOMP_RET_LOG"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.5 SECCOMP_RET_LOG</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981c2b364cd2079c1ceb4" data-id="29438ec39d1981c2b364cd2079c1ceb4"><span><div id="29438ec39d1981c2b364cd2079c1ceb4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981c2b364cd2079c1ceb4" title="4.6 SECCOMP_RET_ALLOW"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.6 SECCOMP_RET_ALLOW</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29438ec39d1981eead78f550b3424cba" data-id="29438ec39d1981eead78f550b3424cba"><span><div id="29438ec39d1981eead78f550b3424cba" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981eead78f550b3424cba" title="4.7 SECCOMP_RET_KILL_THREAD / SECCOMP_RET_KILL_PROCESS"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.7 SECCOMP_RET_KILL_THREAD / SECCOMP_RET_KILL_PROCESS</span></span></h4><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198138b60ec3757808b3f4" data-id="29438ec39d198138b60ec3757808b3f4"><span><div id="29438ec39d198138b60ec3757808b3f4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198138b60ec3757808b3f4" title="5. 日志记录"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 日志记录</span></span></h3><div class="notion-text notion-block-29438ec39d198197aeb8f266dcf37ac1">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#964">kernel/seccomp.c:964</a></div><div class="notion-text notion-block-29438ec39d1981b0a392ff7e3bc47c85">根据 <code class="notion-inline-code">/proc/sys/kernel/seccomp/actions_logged</code> 配置决定是否记录：</div><div class="notion-text notion-block-29438ec39d1981548ce5fcf3775567e6">审计日志包含：
- 系统调用号
- 信号（如果有）
- Seccomp 动作
- 进程 PID、UID 等</div><hr class="notion-hr notion-block-29438ec39d1981c2adc4d2fcae3d7ed6"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d1981bf8025ce27d2c018a9" data-id="29438ec39d1981bf8025ce27d2c018a9"><span><div id="29438ec39d1981bf8025ce27d2c018a9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981bf8025ce27d2c018a9" title="关键数据结构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">关键数据结构</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981a1bb1beef458d31813" data-id="29438ec39d1981a1bb1beef458d31813"><span><div id="29438ec39d1981a1bb1beef458d31813" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981a1bb1beef458d31813" title="1. seccomp_filter"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. seccomp_filter</span></span></h3><div class="notion-text notion-block-29438ec39d1981e88322d30e72e44dd5">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#215">kernel/seccomp.c:215</a></div><div class="notion-text notion-block-29438ec39d1981248ff2cff1563ea22f"><b>生命周期</b>:
- <code class="notion-inline-code">refs</code>: 包括直接任务、依赖过滤器、用户通知监听器
- <code class="notion-inline-code">users</code>: 只包括直接关联的任务
- 当 <code class="notion-inline-code">users</code> 到达 0 时，不能再有新任务关联
- 当 <code class="notion-inline-code">refs</code> 到达 0 时，释放过滤器</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198135a5cdc8bcf2768cf4" data-id="29438ec39d198135a5cdc8bcf2768cf4"><span><div id="29438ec39d198135a5cdc8bcf2768cf4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198135a5cdc8bcf2768cf4" title="2. seccomp_data"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. seccomp_data</span></span></h3><div class="notion-text notion-block-29438ec39d1981c8bfb7d7fbfb288ee4">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/include/uapi/linux/seccomp.h">include/uapi/linux/seccomp.h</a></div><div class="notion-text notion-block-29438ec39d198100b1aeec5fac230b41">这是传递给 BPF 程序的数据结构，大小为 64 字节。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19816d883fc90b2a75c926" data-id="29438ec39d19816d883fc90b2a75c926"><span><div id="29438ec39d19816d883fc90b2a75c926" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19816d883fc90b2a75c926" title="3. task_struct.seccomp"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. task_struct.seccomp</span></span></h3><div class="notion-text notion-block-29438ec39d1981f78d42d5131e45116b">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/include/linux/sched.h">include/linux/sched.h</a></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981f787b9c384e7a56731" data-id="29438ec39d1981f787b9c384e7a56731"><span><div id="29438ec39d1981f787b9c384e7a56731" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981f787b9c384e7a56731" title="4. action_cache"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. action_cache</span></span></h3><div class="notion-text notion-block-29438ec39d19819b93d5e7bca4a64836">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#161">kernel/seccomp.c:161</a></div><div class="notion-text notion-block-29438ec39d19815d9bb3e2b1ac189a21"><b>缓存构建</b>（源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#825">kernel/seccomp.c:825</a>）:</div><div class="notion-text notion-block-29438ec39d1981bcbd2bf6caef9aab2c">对每个系统调用号：
1. 用固定的 <code class="notion-inline-code">nr</code> 和 <code class="notion-inline-code">arch</code> 模拟执行 BPF 程序
2. 如果返回 <code class="notion-inline-code">SECCOMP_RET_ALLOW</code>，在位图中设置对应位
3. 继承前一个过滤器的缓存（新过滤器只能更严格）</div><div class="notion-text notion-block-29438ec39d198145882bd69f36c54b1d"><b>缓存使用</b>:</div><hr class="notion-hr notion-block-29438ec39d19817cba12e50c1f4efc52"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d19815a8072f129e09530ba" data-id="29438ec39d19815a8072f129e09530ba"><span><div id="29438ec39d19815a8072f129e09530ba" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19815a8072f129e09530ba" title="BPF 程序处理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">BPF 程序处理</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198136a72ef6f0387e18f2" data-id="29438ec39d198136a72ef6f0387e18f2"><span><div id="29438ec39d198136a72ef6f0387e18f2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198136a72ef6f0387e18f2" title="1. cBPF 到 eBPF 转换"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. cBPF 到 eBPF 转换</span></span></h3><div class="notion-text notion-block-29438ec39d198178bb1cd6654f033263">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/net/core/filter.c#565">net/core/filter.c:565</a></div><div class="notion-text notion-block-29438ec39d1981b79756ecb296359f84">转换过程：
1. <b>第一遍</b>：计算转换后长度
2. <b>第二遍</b>：实际转换指令并计算跳转偏移
3. <b>第三遍</b>（如需要）：调整跳转偏移</div><div class="notion-text notion-block-29438ec39d1981a6860ddacbd5d1af3e"><b>指令映射示例</b>:</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198107a372fb3440539dfb" data-id="29438ec39d198107a372fb3440539dfb"><span><div id="29438ec39d198107a372fb3440539dfb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198107a372fb3440539dfb" title="2. JIT 编译"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. JIT 编译</span></span></h3><div class="notion-text notion-block-29438ec39d19817badd5d1749c2b6406"><b>启用条件</b>:
- 内核配置 <code class="notion-inline-code">CONFIG_BPF_JIT=y</code>
- 架构支持（x86_64, ARM64, etc.）
- <code class="notion-inline-code">/proc/sys/net/core/bpf_jit_enable</code> 设置</div><div class="notion-text notion-block-29438ec39d1981c799b5d80bb54aa2d3"><b>优势</b>:
- 原生机器码执行，性能提升 2-4 倍
- 减少指令分发开销</div><div class="notion-text notion-block-29438ec39d198112b334ccde044727c4"><b>缺点</b>:
- 增加内核攻击面
- 消耗更多内存</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981fbaf6bd40e67d4cb6c" data-id="29438ec39d1981fbaf6bd40e67d4cb6c"><span><div id="29438ec39d1981fbaf6bd40e67d4cb6c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981fbaf6bd40e67d4cb6c" title="3. 解释器执行"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 解释器执行</span></span></h3><div class="notion-text notion-block-29438ec39d198124b4f9d587ef027ef2">如果无法 JIT 编译，使用 eBPF 解释器：</div><hr class="notion-hr notion-block-29438ec39d198106ba7bfd2316be6ce1"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29438ec39d1981faa3c3da1bfd016cf8" data-id="29438ec39d1981faa3c3da1bfd016cf8"><span><div id="29438ec39d1981faa3c3da1bfd016cf8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981faa3c3da1bfd016cf8" title="安全机制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安全机制</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19819c9aa9ca5cb8982b17" data-id="29438ec39d19819c9aa9ca5cb8982b17"><span><div id="29438ec39d19819c9aa9ca5cb8982b17" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19819c9aa9ca5cb8982b17" title="1. 验证器检查"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 验证器检查</span></span></h3><div class="notion-text notion-block-29438ec39d19813a9dabc2bd61ce78df"><b>基本检查</b> (<code class="notion-inline-code">bpf_check_basics_ok</code>):
- 程序不为空
- 最后一条指令是 RET
- 没有无效指令</div><div class="notion-text notion-block-29438ec39d198147a887cedbd01cac7c"><b>经典 BPF 检查</b> (<code class="notion-inline-code">bpf_check_classic</code>):
- 没有越界跳转
- 没有后向跳转（防止循环）
- 内存访问合法
- 除数不为零检查</div><div class="notion-text notion-block-29438ec39d198111ac3acecb6fb40af5"><b>Seccomp 特定检查</b> (<code class="notion-inline-code">seccomp_check_filter</code>):
- 只允许白名单中的指令
- 数据访问限制为 <code class="notion-inline-code">seccomp_data</code> 结构
- 强制 4 字节对齐访问</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198163ae30feb9eaa0a6a8" data-id="29438ec39d198163ae30feb9eaa0a6a8"><span><div id="29438ec39d198163ae30feb9eaa0a6a8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198163ae30feb9eaa0a6a8" title="2. 长度限制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 长度限制</span></span></h3><div class="notion-text notion-block-29438ec39d1981108776f613059dc17b">限制总指令数为 256KB，防止：
- DoS 攻击（过长的执行时间）
- 内存耗尽</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d19815ebf20c6e4e9c0a364" data-id="29438ec39d19815ebf20c6e4e9c0a364"><span><div id="29438ec39d19815ebf20c6e4e9c0a364" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d19815ebf20c6e4e9c0a364" title="3. 权限要求"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 权限要求</span></span></h3><div class="notion-text notion-block-29438ec39d198195a130f86d11447a9f">安装 seccomp 过滤器需要：</div><div class="notion-text notion-block-29438ec39d1981a4ab4bd6577799281a"><code class="notion-inline-code"><b>no_new_privs</b></code><b> 标志</b>:
- 通过 <code class="notion-inline-code">prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)</code> 设置
- 禁止进程及其子进程获得新权限
- 防止特权提升攻击</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981e7b97cdeb37acf45b7" data-id="29438ec39d1981e7b97cdeb37acf45b7"><span><div id="29438ec39d1981e7b97cdeb37acf45b7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981e7b97cdeb37acf45b7" title="4. 单向门机制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 单向门机制</span></span></h3><div class="notion-text notion-block-29438ec39d19818fa629df48644d64fa">一旦设置 seccomp 模式，无法更改或移除，只能添加更严格的过滤器。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d1981e7a7efff80c419ad91" data-id="29438ec39d1981e7a7efff80c419ad91"><span><div id="29438ec39d1981e7a7efff80c419ad91" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d1981e7a7efff80c419ad91" title="5. 内存屏障"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 内存屏障</span></span></h3><div class="notion-text notion-block-29438ec39d1981b1b289db45efdb0dc9">确保多核系统中的内存一致性。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29438ec39d198104885fd5dfda847f85" data-id="29438ec39d198104885fd5dfda847f85"><span><div id="29438ec39d198104885fd5dfda847f85" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29438ec39d198104885fd5dfda847f85" title="6. 推测执行缓解"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6. 推测执行缓解</span></span></h3><div class="notion-text notion-block-29438ec39d1981a295a4d18687d33107">默认启用推测执行缓解（如 SSBD），防止 Spectre 类攻击。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29538ec39d19809da4e2d7df3a7f4c4a" data-id="29538ec39d19809da4e2d7df3a7f4c4a"><span><div id="29538ec39d19809da4e2d7df3a7f4c4a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19809da4e2d7df3a7f4c4a" title="深入 Seccomp User Notification 机制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">深入 Seccomp User Notification 机制</span></span></h2><div class="notion-text notion-block-29538ec39d198091a281ceae0e0a5e61">Seccomp 用户态通知 (User Notification) 允许用户空间进程拦截和处理被 seccomp 过滤的系统调用。与传统的 <code class="notion-inline-code">SECCOMP_RET_ERRNO</code> 或 <code class="notion-inline-code">SECCOMP_RET_KILL</code> 不同，<code class="notion-inline-code">SECCOMP_RET_USER_NOTIF</code> 可以将系统调用决策权委托给用户空间的监督进程。被过滤的系统调用会阻塞，等待用户空间监督进程的决策，并将系统调用号、参数、架构等信息传递给用户空间。监督进程可以返回错误码、返回值，或允许系统调用继续执行，也支持通过 <code class="notion-inline-code">SECCOMP_IOCTL_NOTIF_ADDFD</code> 向被监督进程注入文件描述符。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29538ec39d1980e5b434d3ea017dd2f3" data-id="29538ec39d1980e5b434d3ea017dd2f3"><span><div id="29538ec39d1980e5b434d3ea017dd2f3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980e5b434d3ea017dd2f3" title="整体架构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">整体架构</span></span></h3><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-29538ec39d198063bdced35e66b85906"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A054efce2-a59c-4467-854f-8a2706b53d91%3Aimage.png?table=block&amp;id=29538ec3-9d19-8063-bdce-d35e66b85906&amp;t=29538ec3-9d19-8063-bdce-d35e66b85906" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-29538ec39d1980e7b02efcf111a2afdc">关键数据结构：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29538ec39d1980d19cb1d3c0b7a7fa2b" data-id="29538ec39d1980d19cb1d3c0b7a7fa2b"><span><div id="29538ec39d1980d19cb1d3c0b7a7fa2b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980d19cb1d3c0b7a7fa2b" title="核心数据结构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">核心数据结构</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198022b5e8c1abedc0f8c6" data-id="29538ec39d198022b5e8c1abedc0f8c6"><span><div id="29538ec39d198022b5e8c1abedc0f8c6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198022b5e8c1abedc0f8c6" title="1. 内核通知对象 (seccomp_knotif)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>1. 内核通知对象 (seccomp_knotif)</b></span></span></h4><div class="notion-text notion-block-29538ec39d19803cadaae3f475db6176">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#64">kernel/seccomp.c:64</a></div><div class="notion-text notion-block-29538ec39d1980b9b1c1d9b6bf3d59c7"><b>状态机转换</b>：</div><ul class="notion-list notion-list-disc notion-block-29538ec39d1980d7b706ec379bb0a507"><li><b>INIT</b>: 通知已创建，等待监督进程读取</li></ul><ul class="notion-list notion-list-disc notion-block-29538ec39d198032b049d04c3427f973"><li><b>SENT</b>: 监督进程已读取，等待响应</li></ul><ul class="notion-list notion-list-disc notion-block-29538ec39d19802bae26eeb3d77c698d"><li><b>REPLIED</b>: 监督进程已响应，可以唤醒被监督进程</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198020aa5bcac9022792cf" data-id="29538ec39d198020aa5bcac9022792cf"><span><div id="29538ec39d198020aa5bcac9022792cf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198020aa5bcac9022792cf" title="2. 通知容器 (struct notification)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 通知容器 (struct notification)</span></span></h4><div class="notion-text notion-block-29538ec39d19802fa32bd96a84938537">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#143">kernel/seccomp.c:143</a></div><div class="notion-text notion-block-29538ec39d19804694ccd6c6fe265456"><b>设计要点</b>：</div><ul class="notion-list notion-list-disc notion-block-29538ec39d19807bbe58fdde990d2041"><li>大多数 seccomp 过滤器不使用通知，因此单独分配此结构以节省内存</li></ul><ul class="notion-list notion-list-disc notion-block-29538ec39d198006819be9f7706288f8"><li><code class="notion-inline-code">request</code> 信号量：初始值为 0，每个新通知 <code class="notion-inline-code">up()</code>，读取时 <code class="notion-inline-code">down()</code></li></ul><ul class="notion-list notion-list-disc notion-block-29538ec39d198010b0f6e364b50b45d6"><li><code class="notion-inline-code">next_id</code>：随机初始化防止 ID 预测攻击</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19801da8f5f8ae360d7f9a" data-id="29538ec39d19801da8f5f8ae360d7f9a"><span><div id="29538ec39d19801da8f5f8ae360d7f9a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19801da8f5f8ae360d7f9a" title="3. FD 注入对象 (seccomp_kaddfd)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. FD 注入对象 (seccomp_kaddfd)</span></span></h4><div class="notion-text notion-block-29538ec39d1980859509d80caa2962a2">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#120">kernel/seccomp.c:120</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198034b70ed7e70b0bfc3b" data-id="29538ec39d198034b70ed7e70b0bfc3b"><span><div id="29538ec39d198034b70ed7e70b0bfc3b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198034b70ed7e70b0bfc3b" title="4. 用户空间接口结构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 用户空间接口结构</span></span></h4><div class="notion-text notion-block-29538ec39d1980e18d36e0681797fba9">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/include/uapi/linux/seccomp.h">include/uapi/linux/seccomp.h</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198046b960f8065e09b33e" data-id="29538ec39d198046b960f8065e09b33e"><span><div id="29538ec39d198046b960f8065e09b33e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198046b960f8065e09b33e" title="seccomp_notif (通知请求)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">seccomp_notif (通知请求)</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19802c9686db196617b366" data-id="29538ec39d19802c9686db196617b366"><span><div id="29538ec39d19802c9686db196617b366" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19802c9686db196617b366" title="seccomp_notif_resp (通知响应)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">seccomp_notif_resp (通知响应)</span></span></h4><div class="notion-text notion-block-29538ec39d198020bee4d2f103ea4257"><b>标志位</b>：</div><ul class="notion-list notion-list-disc notion-block-29538ec39d1980ad9e2ee48c18150ab3"><li><code class="notion-inline-code">SECCOMP_USER_NOTIF_FLAG_CONTINUE</code> (0x1)：允许系统调用继续执行（有 TOCTOU 风险）</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980b68594e9c66ac8847e" data-id="29538ec39d1980b68594e9c66ac8847e"><span><div id="29538ec39d1980b68594e9c66ac8847e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980b68594e9c66ac8847e" title="seccomp_notif_addfd (FD 注入请求)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">seccomp_notif_addfd (FD 注入请求)</span></span></h4><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29538ec39d1980e1aa3ec88f429a58be" data-id="29538ec39d1980e1aa3ec88f429a58be"><span><div id="29538ec39d1980e1aa3ec88f429a58be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980e1aa3ec88f429a58be" title="完整工作流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">完整工作流程</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19800e9b34dc7fcf0a7620" data-id="29538ec39d19800e9b34dc7fcf0a7620"><span><div id="29538ec39d19800e9b34dc7fcf0a7620" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19800e9b34dc7fcf0a7620" title="阶段 1：Listener FD 创建"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 1：Listener FD 创建</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980fe8d3cec92630555b0" data-id="29538ec39d1980fe8d3cec92630555b0"><span><div id="29538ec39d1980fe8d3cec92630555b0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980fe8d3cec92630555b0" title="1.1 安装带 NEW_LISTENER 标志的过滤器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.1 安装带 NEW_LISTENER 标志的过滤器</span></span></h4><div class="notion-text notion-block-29538ec39d19807e8d84ee63425acdab">用户空间代码：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980758dd9df4e7f491b28" data-id="29538ec39d1980758dd9df4e7f491b28"><span><div id="29538ec39d1980758dd9df4e7f491b28" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980758dd9df4e7f491b28" title="1.2 内核处理流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.2 内核处理流程</span></span></h4><div class="notion-text notion-block-29538ec39d1980fe8e02f713f6ec605d">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1787">kernel/seccomp.c:1787</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980959815fb9a7dd49f11" data-id="29538ec39d1980959815fb9a7dd49f11"><span><div id="29538ec39d1980959815fb9a7dd49f11" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980959815fb9a7dd49f11" title="1.3 init_listener 函数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1.3 init_listener 函数</span></span></h4><div class="notion-text notion-block-29538ec39d1980449a0cc4a8e3ee83c3">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1721">kernel/seccomp.c:1721</a></div><div class="notion-text notion-block-29538ec39d1980d4bac9e8b02fad4fcc"><b>seccomp_notify_ops</b> 文件操作：</div><div class="notion-text notion-block-29538ec39d198022a3c8ec798f1dd575">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1714">kernel/seccomp.c:1714</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19807eb147e13aab0037ea" data-id="29538ec39d19807eb147e13aab0037ea"><span><div id="29538ec39d19807eb147e13aab0037ea" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19807eb147e13aab0037ea" title="阶段 2：系统调用拦截与通知"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 2：系统调用拦截与通知</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198093a4d7e842e700b548" data-id="29538ec39d198093a4d7e842e700b548"><span><div id="29538ec39d198093a4d7e842e700b548" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198093a4d7e842e700b548" title="2.1 触发 SECCOMP_RET_USER_NOTIF"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 触发 SECCOMP_RET_USER_NOTIF</span></span></h4><div class="notion-text notion-block-29538ec39d198016ad1bec3a47d8a11a">被监督进程执行系统调用 → 匹配 BPF 过滤器 → 返回 <code class="notion-inline-code">SECCOMP_RET_USER_NOTIF</code>：</div><div class="notion-text notion-block-29538ec39d1980bd95b6ea10e010eae2">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1158">kernel/seccomp.c:1158</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19802694c9d749d6ef76e2" data-id="29538ec39d19802694c9d749d6ef76e2"><span><div id="29538ec39d19802694c9d749d6ef76e2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19802694c9d749d6ef76e2" title="2.2 seccomp_do_user_notification 详解"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 seccomp_do_user_notification 详解</span></span></h4><div class="notion-text notion-block-29538ec39d1980cdaea7f2f437122378">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1077">kernel/seccomp.c:1077</a></div><div class="notion-text notion-block-29538ec39d1980acb50de6586d8d305f">这是用户态通知的核心函数，被监督进程的系统调用会在此阻塞。</div><div class="notion-text notion-block-29538ec39d1980d7ba5bf552bbff3e30"><b>关键点</b>：</div><ol start="1" class="notion-list notion-list-numbered notion-block-29538ec39d19808993bcf0fe28ac9020" style="list-style-type:decimal"><li><b>通知对象在栈上</b>：<code class="notion-inline-code">seccomp_knotif n</code> 在被监督进程的内核栈上分配，生命周期与系统调用相同</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29538ec39d1980788e61d08e51e93488" style="list-style-type:decimal"><li><b>数据指针有效性</b>：<code class="notion-inline-code">n.data</code> 指向 <code class="notion-inline-code">__seccomp_filter</code> 的 <code class="notion-inline-code">sd</code>，在整个通知期间有效</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-29538ec39d1980c99d79c0e1403313f5" style="list-style-type:decimal"><li><b>多次唤醒</b>：<code class="notion-inline-code">do-while</code> 循环处理 <code class="notion-inline-code">addfd</code> 请求，每次注入 FD 都会唤醒一次</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-29538ec39d19803b81f1ea471cd903ec" style="list-style-type:decimal"><li><b>信号中断</b>：如果被监督进程收到信号，<code class="notion-inline-code">wait_for_completion_interruptible</code> 返回错误</li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198072b6b0f11dfd9223b8" data-id="29538ec39d198072b6b0f11dfd9223b8"><span><div id="29538ec39d198072b6b0f11dfd9223b8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198072b6b0f11dfd9223b8" title="阶段 3：监督进程读取通知"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 3：监督进程读取通知</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198041a562ff18a8d24abf" data-id="29538ec39d198041a562ff18a8d24abf"><span><div id="29538ec39d198041a562ff18a8d24abf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198041a562ff18a8d24abf" title="3.1 等待通知 (poll/epoll)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 等待通知 (poll/epoll)</span></span></h4><div class="notion-text notion-block-29538ec39d19808eaa64c9c676216b02">监督进程使用 <code class="notion-inline-code">poll</code> 或 <code class="notion-inline-code">epoll</code> 监听 listener fd：</div><div class="notion-text notion-block-29538ec39d1980e4b747ee3d6c25b95a">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1685">kernel/seccomp.c:1685</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980329cedd5e40a3e81c9" data-id="29538ec39d1980329cedd5e40a3e81c9"><span><div id="29538ec39d1980329cedd5e40a3e81c9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980329cedd5e40a3e81c9" title="3.2 读取通知 (ioctl NOTIF_RECV)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.2 读取通知 (ioctl NOTIF_RECV)</span></span></h4><div class="notion-text notion-block-29538ec39d19804eb949d3bd46eb7cd1">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1425">kernel/seccomp.c:1425</a></div><div class="notion-text notion-block-29538ec39d198034a088e9776816d137"><b>状态转换</b>：<code class="notion-inline-code">INIT → SENT</code></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980ad9d87f4c9884b59b9" data-id="29538ec39d1980ad9d87f4c9884b59b9"><span><div id="29538ec39d1980ad9d87f4c9884b59b9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980ad9d87f4c9884b59b9" title="阶段 4：监督进程发送响应"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 4：监督进程发送响应</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980e2b6a2c60fe98ded95" data-id="29538ec39d1980e2b6a2c60fe98ded95"><span><div id="29538ec39d1980e2b6a2c60fe98ded95" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980e2b6a2c60fe98ded95" title="4.1 发送响应 (ioctl NOTIF_SEND)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.1 发送响应 (ioctl NOTIF_SEND)</span></span></h4><div class="notion-text notion-block-29538ec39d19807797fdd42e3e042f87">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1494">kernel/seccomp.c:1494</a></div><div class="notion-text notion-block-29538ec39d19804b9a9fe7ed1f9dc787"><b>状态转换</b>：<code class="notion-inline-code">SENT → REPLIED</code></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19801890dfe965a479a53a" data-id="29538ec39d19801890dfe965a479a53a"><span><div id="29538ec39d19801890dfe965a479a53a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19801890dfe965a479a53a" title="4.2 验证通知有效性 (ioctl NOTIF_ID_VALID)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4.2 验证通知有效性 (ioctl NOTIF_ID_VALID)</span></span></h4><div class="notion-text notion-block-29538ec39d198015994ac96eaa1a9215">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1538">kernel/seccomp.c:1538</a></div><div class="notion-text notion-block-29538ec39d19803fb9b7dee392a13321">监督进程在处理通知前可以验证通知是否仍然有效（被监督进程可能已收到信号退出）：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198052982dc94cc44421df" data-id="29538ec39d198052982dc94cc44421df"><span><div id="29538ec39d198052982dc94cc44421df" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198052982dc94cc44421df" title="阶段 5：FD 注入机制"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 5：FD 注入机制</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19809ebdb6d27113415e31" data-id="29538ec39d19809ebdb6d27113415e31"><span><div id="29538ec39d19809ebdb6d27113415e31" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19809ebdb6d27113415e31" title="5.1 使用场景"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.1 使用场景</span></span></h4><div class="notion-text notion-block-29538ec39d1980d88926e50a13a27318">FD 注入允许监督进程将自己的文件描述符&quot;传递&quot;给被监督进程，典型场景：</div><ul class="notion-list notion-list-disc notion-block-29538ec39d1980d09ed3fe21ad834bbf"><li>容器运行时代理设备访问：容器进程 <code class="notion-inline-code">open(&quot;/dev/fuse&quot;)</code> → 监督进程打开真实设备 → 注入 fd</li></ul><ul class="notion-list notion-list-disc notion-block-29538ec39d1980d992e2e1a37a015338"><li>网络代理：容器进程 <code class="notion-inline-code">socket()</code> → 监督进程创建 socket 并配置 → 注入 fd</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d1980c6996de2c653edbbf2" data-id="29538ec39d1980c6996de2c653edbbf2"><span><div id="29538ec39d1980c6996de2c653edbbf2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980c6996de2c653edbbf2" title="5.2 注入流程 (ioctl NOTIF_ADDFD)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.2 注入流程 (ioctl NOTIF_ADDFD)</span></span></h4><div class="notion-text notion-block-29538ec39d1980958d7ce0477323e99b">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1562">kernel/seccomp.c:1562</a></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d19806cb1ccf73761dfd587" data-id="29538ec39d19806cb1ccf73761dfd587"><span><div id="29538ec39d19806cb1ccf73761dfd587" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d19806cb1ccf73761dfd587" title="5.3 被监督进程处理 addfd"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.3 被监督进程处理 addfd</span></span></h4><div class="notion-text notion-block-29538ec39d198089b885cefafedf75a2">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1066">kernel/seccomp.c:1066</a></div><div class="notion-text notion-block-29538ec39d1980ef8e9bfb3ad9d253a7">在 <code class="notion-inline-code">seccomp_do_user_notification</code> 的循环中调用：</div><div class="notion-text notion-block-29538ec39d198093a5c6c80e68db02a1"><b>双向等待机制</b>：</div><ol start="1" class="notion-list notion-list-numbered notion-block-29538ec39d19805692d2e8b1df763055" style="list-style-type:decimal"><li>监督进程在 <code class="notion-inline-code">seccomp_notify_addfd</code> 中等待 <code class="notion-inline-code">kaddfd.completion</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29538ec39d1980078613ee74efbc4073" style="list-style-type:decimal"><li>被监督进程在 <code class="notion-inline-code">seccomp_do_user_notification</code> 中被唤醒，调用 <code class="notion-inline-code">seccomp_handle_addfd</code> 安装 fd 并 <code class="notion-inline-code">complete()</code></li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198054bed8d63f728d7018" data-id="29538ec39d198054bed8d63f728d7018"><span><div id="29538ec39d198054bed8d63f728d7018" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198054bed8d63f728d7018" title="阶段 6：清理与关闭"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">阶段 6：清理与关闭</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29538ec39d198017b4e2ce4b7ebbeb04" data-id="29538ec39d198017b4e2ce4b7ebbeb04"><span><div id="29538ec39d198017b4e2ce4b7ebbeb04" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d198017b4e2ce4b7ebbeb04" title="6.1 Listener 关闭"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6.1 Listener 关闭</span></span></h4><div class="notion-text notion-block-29538ec39d1980b086a5c220caf4ef34">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1352">kernel/seccomp.c:1352</a></div><div class="notion-text notion-block-29538ec39d1980cab5d8c3f801641843">当监督进程关闭 listener fd 时：</div><div class="notion-text notion-block-29538ec39d19809c86c9eee6e3d93c9a">源码：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/kernel-android12-5.10-lts/xref/kernel/seccomp.c#1366">kernel/seccomp.c:1366</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29538ec39d1980d8b8d0d4268c0d5a61" data-id="29538ec39d1980d8b8d0d4268c0d5a61"><span><div id="29538ec39d1980d8b8d0d4268c0d5a61" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29538ec39d1980d8b8d0d4268c0d5a61" title="Android 平台的 Seccomp 使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Android 平台的 Seccomp 使用</span></span></h2><div class="notion-text notion-block-29538ec39d198061b63ae7b14afaab9d">在 Android 中，Seccomp 是多层安全机制的一部分，搭配 <b>SELinux、命名空间隔离、UID/GID 沙箱、权限模型</b> 等共同构建应用安全边界。</div><div class="notion-text notion-block-29538ec39d198091aaedf6a5e0b24d7c">Android 从 <b>Android 8.0</b> 开始引入了对 App 进程的 <b>Seccomp 过滤器</b>。</div><div class="notion-text notion-block-29538ec39d19805c90b9c51e26c50afc">设计目标是：</div><ol start="1" class="notion-list notion-list-numbered notion-block-29538ec39d1980fb9caffbdcb08c6df5" style="list-style-type:decimal"><li>减少应用可访问的系统调用数量；</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-29538ec39d198041b2b9e0fec0884aeb" style="list-style-type:decimal"><li>阻止利用内核漏洞的攻击面；</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-29538ec39d1980c6b9a4ed5c33d90426" style="list-style-type:decimal"><li>对特权进程（如 zygote 或 system_server）使用更严格的策略。</li></ol><div class="notion-text notion-block-29538ec39d1980ffaeb5dc9bd59e1b05">参考 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/android-12.0.0_r3/xref/bionic/libc/seccomp/seccomp_policy.cpp">bionic/libc/seccom/seccomp_policy.cpp</a> Android 的 Seccomp 机制分为4个类型：</div><table class="notion-simple-table notion-block-29538ec39d1980bc9742cb9be37b0acc"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-29538ec39d1980b2a846c0bed4952e79"><td class="" style="width:120px"><div class="notion-simple-table-cell">进程类型</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">过滤器类型</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">主要作用</div></td></tr><tr class="notion-simple-table-row notion-block-29538ec39d1980679107f225d43d666a"><td class="" style="width:120px"><div class="notion-simple-table-cell">普通 App 进程</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">App filter</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">限定 App 允许的 syscall 集合</div></td></tr><tr class="notion-simple-table-row notion-block-29538ec39d1980b39254ec947d1730e7"><td class="" style="width:120px"><div class="notion-simple-table-cell">App Zygote 进程</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">App Zygote filter</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">更严格，只允许必要的 syscall</div></td></tr><tr class="notion-simple-table-row notion-block-29538ec39d198033b609fb4397d6a60e"><td class="" style="width:120px"><div class="notion-simple-table-cell">System 进程</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">System filter</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">系统进程的特定白名单</div></td></tr><tr class="notion-simple-table-row notion-block-29538ec39d1980d48c8bda4f02ec0d73"><td class="" style="width:120px"><div class="notion-simple-table-cell">UID/GID 改变辅助过滤器</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">SetUid/Gid filter</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">限制 setresuid/setresgid 参数范围</div></td></tr></tbody></table><div class="notion-text notion-block-29538ec39d1980d98d19c24114190f66">在 android 系统中，最终可用的 SYSCALL 是由 SYSCALL - BLOCKLIST + ALLOWLIST 组成的，同时会参考 <code class="notion-inline-code">SECCOMP_PRIORITY.TXT</code>，把高频 syscall 放在 BPF 判断的“快路径”前面，以减少匹配开销。</div><div class="notion-text notion-block-29538ec39d198069a477d486b53a9f97">具体的这些文件也可以在 bionic 源码中找到：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/android-12.0.0_r3/xref/bionic/libc/">bionic/libc/</a></div><div class="notion-text notion-block-29538ec39d19806fa5a6d78f4eae021e">具体的计算逻辑可以参考 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aospxref.com/android-12.0.0_r3/xref/bionic/libc/tools/genseccomp.py">genseccomp.py</a></div><div class="notion-blank notion-block-29538ec39d1980e995e8f4e60d3bdcfd"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[解决爱思助手导致的 Mac 锁屏不熄屏问题]]></title>
            <link>https://xtuly.cn/article/i4-lock-kill</link>
            <guid>https://xtuly.cn/article/i4-lock-kill</guid>
            <pubDate>Tue, 01 Apr 2025 00:00:00 GMT</pubDate>
            <description><![CDATA[使用 Shortery 解决爱思助手导致的 Mac 锁屏不熄屏问题]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-1c838ec39d198068b968c0facb3a56df"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-1c838ec39d1980f2b834d53ee59f34bf">最近发现公司 mac 电脑锁屏之后屏幕又不熄屏了，回想起之前排查过是爱思助手导致的问题，而且之前配置的 Shortery 只退出爱思助手没有生效，于是重新修改了一下脚本：</div><div class="notion-text notion-block-1c838ec39d198027921dd9a4b0cda069">新建一个快捷指令，按照图中的内容操作</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1c838ec39d198022aba6d42fdd6f6d99"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A48f9ce47-9e65-4e0c-9ad8-55e85a66a1c0%3Aimage.png?table=block&amp;id=1c838ec3-9d19-8022-aba6-d42fdd6f6d99&amp;t=1c838ec3-9d19-8022-aba6-d42fdd6f6d99" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-1c838ec39d1980dfadf7c4a0bf9c2aad">打开 Shortery 配置触发器：</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1c838ec39d1980f9b596cea4071d41c6"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A949fad36-f69b-4817-bc29-63a5864c745e%3Aimage.png?table=block&amp;id=1c838ec3-9d19-80f9-b596-cea4071d41c6&amp;t=1c838ec3-9d19-80f9-b596-cea4071d41c6" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-1c838ec39d1980b48fbfe30029acee4f"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[另一个 AOSPXRef - aosp.app]]></title>
            <link>https://xtuly.cn/article/aosp-app</link>
            <guid>https://xtuly.cn/article/aosp-app</guid>
            <pubDate>Thu, 05 Oct 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[自建 AOSPXRef 阅读 Android 源码]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-6d2585cd6a62438db618d6a10f235c04"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-ce10495af2f64dd582f705c9bbba27f1">国内入口：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://aosp.xtuly.cn/">http://aosp.xtuly.cn/</a></div><div class="notion-text notion-block-606137ba109441a59004030a44dad249">国外入口：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://aosp.app/">https://aosp.app/</a></div><div class="notion-text notion-block-25f3c3eaa9f641ffafe5cd8755d6c08a">通知频道：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://t.me/aospapp">https://t.me/aospapp</a></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b321bfd3d7b24e008a0a3454ed5a3ff6" data-id="b321bfd3d7b24e008a0a3454ed5a3ff6"><span><div id="b321bfd3d7b24e008a0a3454ed5a3ff6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b321bfd3d7b24e008a0a3454ed5a3ff6" title="源码同步"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">源码同步</span></span></h2><div class="notion-text notion-block-85d5d224e1c749dc9bfafafc7489c452">校园网联合镜像站：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://mirrors.cernet.edu.cn/list/AOSP">https://mirrors.cernet.edu.cn/list/AOSP</a></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2d60d0415f43490e818768f65cc2190c" data-id="2d60d0415f43490e818768f65cc2190c"><span><div id="2d60d0415f43490e818768f65cc2190c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d60d0415f43490e818768f65cc2190c" title="安装工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装工具</span></span></h3><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-8d72eff0408c4437bb934db09dc23085" data-id="8d72eff0408c4437bb934db09dc23085"><span><div id="8d72eff0408c4437bb934db09dc23085" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8d72eff0408c4437bb934db09dc23085" title="下载初始化包"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">下载初始化包</span></span></h3><div class="notion-text notion-block-edf52bc5dd5448de90636d3371267304">首先检查md5是否一样，如果不一样不能使用那个源</div><div class="notion-text notion-block-afd5585688f047b4bd0004921f546905">使用每月更新的初始化包</div><div class="notion-text notion-block-7451b47f74964731bd2ad222acac97a6">使用 aria2 多来源下载初始化包</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e56aa35562364ae4acdead6e525187e8" data-id="e56aa35562364ae4acdead6e525187e8"><span><div id="e56aa35562364ae4acdead6e525187e8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e56aa35562364ae4acdead6e525187e8" title="校验文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">校验文件</span></span></h3><div class="notion-text notion-block-a55b3488ff924ab68a3fceb4f56e8b1f">MD5不一样也别着急，只要能解压就行，使用<code class="notion-inline-code">repo sync</code> 同步之后，报错的删除掉再重新同步即可！</div><div class="notion-text notion-block-97954d87932f4aecbe67a8eb26caae63">md5校验</div><div class="notion-text notion-block-0ac50903d5a8480dac03ffc4f80f71ae">压缩包测试</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-533f500a3cdd47359daefd813630f9b7" data-id="533f500a3cdd47359daefd813630f9b7"><span><div id="533f500a3cdd47359daefd813630f9b7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#533f500a3cdd47359daefd813630f9b7" title="同步源码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">同步源码</span></span></h3><div class="notion-text notion-block-3af7034b75c44c5394657d40f7daf9b0">先解压缩</div><div class="notion-text notion-block-85c7a43f73ab4515a2c16edf1d72f7ec">然后同步每个版本的源码</div><div class="notion-text notion-block-5204a49d8f054159ab0e2a33d7399b92">精简源码</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6ff70de1a5a64257a9416b2c36517c62" data-id="6ff70de1a5a64257a9416b2c36517c62"><span><div id="6ff70de1a5a64257a9416b2c36517c62" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6ff70de1a5a64257a9416b2c36517c62" title="部署"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">部署</span></span></h2><div class="notion-text notion-block-8cbff20ccc4846e5a2c6736e111fcb15">先 clone 仓库</div><div class="notion-text notion-block-745bacb9c4ad41c68a912aacc840b5eb">编辑 versions.txt，修改为你拉取下来的源码和对应的api level</div><div class="notion-text notion-block-1faebc87921e4fa785139bb5f3e39214">然后执行 python3 gen.py 生成 openresty 配置 和 docker compose 配置</div><div class="notion-text notion-block-4207deffe80f4a6a932942c94f360beb">修改 init.sh 里面的 for 条件，睡眠时间</div><div class="notion-text notion-block-c2a431cdbca141f8adac39bcf9b6414a">第一次启动容器的时候需要执行 init.sh 逐个启动各个版本的 opengrok 实例，索引比较耗费系统资源。</div><div class="notion-blank notion-block-9015846c37074530854d162115ffee45"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 IDA Python 修改基本块的背景颜色]]></title>
            <link>https://xtuly.cn/article/ida-python-modify-block-color</link>
            <guid>https://xtuly.cn/article/ida-python-modify-block-color</guid>
            <pubDate>Fri, 22 Sep 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[使用 IDA Python 修改基本块的背景颜色]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-0ad320113f3549389c839199d742c33f"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-7896e5d4b91e4a24808b459f8e5fb2e1">bb 为基本块的地址</div><div class="notion-blank notion-block-37c7d8c2cad5413287d0c872fb207bb8"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WireShark+OpenWrt 抓包]]></title>
            <link>https://xtuly.cn/article/wireshark-openwrt-capture</link>
            <guid>https://xtuly.cn/article/wireshark-openwrt-capture</guid>
            <pubDate>Mon, 28 Nov 2022 00:00:00 GMT</pubDate>
            <description><![CDATA[使用MacOS上的Wireshark抓经过OpenWrt路由的所有数据包]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-5f8aa5bcc00945b4a13924ac09fc930f"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-235a56428b3446faa1aa3f9cff286ed3" data-id="235a56428b3446faa1aa3f9cff286ed3"><span><div id="235a56428b3446faa1aa3f9cff286ed3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#235a56428b3446faa1aa3f9cff286ed3" title="路由器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">路由器</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-42aaa080d2e44fb284a6ee7d5df39d0e" data-id="42aaa080d2e44fb284a6ee7d5df39d0e"><span><div id="42aaa080d2e44fb284a6ee7d5df39d0e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#42aaa080d2e44fb284a6ee7d5df39d0e" title="配置免密登陆"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置免密登陆</span></span></h3><div class="notion-text notion-block-38008db96d894a45a048ffd788a770f9">将公钥写入 <code class="notion-inline-code">/etc/dropbear/authorized_keys</code> 文件</div><blockquote class="notion-quote notion-block-d895c9d5310842bfb482d2214b7434ec"><div>文件权限644</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-402d8eda8dd74a5cac432f93b3edb0b4" data-id="402d8eda8dd74a5cac432f93b3edb0b4"><span><div id="402d8eda8dd74a5cac432f93b3edb0b4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#402d8eda8dd74a5cac432f93b3edb0b4" title="安装tcpdump"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装tcpdump</span></span></h3><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-69b68b4311694526a24fc0ef9df5f1c6" data-id="69b68b4311694526a24fc0ef9df5f1c6"><span><div id="69b68b4311694526a24fc0ef9df5f1c6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#69b68b4311694526a24fc0ef9df5f1c6" title="开始抓包"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">开始抓包</span></span></h2><div class="notion-text notion-block-f265ba6297894661a13faa24bdc9de01">先安装wireshark，然后执行下面的指令即可</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-25e804e5b85d4cfdbd97e04b131afb0e" data-id="25e804e5b85d4cfdbd97e04b131afb0e"><span><div id="25e804e5b85d4cfdbd97e04b131afb0e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#25e804e5b85d4cfdbd97e04b131afb0e" title="android"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">android</span></span></h2><div class="notion-blank notion-block-52f108b29e544f04b3931d931e02b56b"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[从 frida-server 中提取 frida-agent]]></title>
            <link>https://xtuly.cn/article/extract-frida-agent-from-frida-server</link>
            <guid>https://xtuly.cn/article/extract-frida-agent-from-frida-server</guid>
            <pubDate>Wed, 13 Sep 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[从 frida-server 中提取 frida-agent]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-f1f746e288e949c2a25bde7225599551"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6757e30d28444afa96da8915e4570263" data-id="6757e30d28444afa96da8915e4570263"><span><div id="6757e30d28444afa96da8915e4570263" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6757e30d28444afa96da8915e4570263" title="提取方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">提取方法</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-1a8a44da29784326add513d3c073f6c3" style="list-style-type:decimal"><li>使用IDA打开 frida-server</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-406a7f0afe6647fbba74a78992fa5b70" style="list-style-type:decimal"><li>搜索 “frida-agent”</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5960126fbf84414e90087dfb1ee7e7aa" style="list-style-type:decimal"><li>定位到图中所示的地方</li><ol class="notion-list notion-list-numbered notion-block-5960126fbf84414e90087dfb1ee7e7aa" style="list-style-type:lower-alpha"><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6f251b0df809436197a69cf686690fbf"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9c2c12bd-649d-4577-9157-0eadf0b4c5ba%2F4354267e-7b12-48ec-b24f-369532af22f4%2FUntitled.png?table=block&amp;id=6f251b0d-f809-4361-97a6-9cf686690fbf&amp;t=6f251b0d-f809-4361-97a6-9cf686690fbf&amp;width=1770&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><div class="notion-blank notion-block-55af1562432643a0a01baca56b6c8761"> </div><div class="notion-text notion-block-2f37bd099e1d4cc883398ceccf8a1474">自动化 dump 脚本</div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>