<?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>Tue, 17 Mar 2026 11:45:25 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 2026, Ylarod</copyright>
        <item>
            <title><![CDATA[一加内核 panic 日志获取方法]]></title>
            <link>https://xtuly.cn/article/oneplus-ace-5-panic-log</link>
            <guid>https://xtuly.cn/article/oneplus-ace-5-panic-log</guid>
            <pubDate>Fri, 27 Feb 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[探索如何获取一加 Ace 5 设备的内核 panic 日志]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-31438ec39d198065bf89cd90cff1c7bc"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-31438ec39d19811d9984eed1078e8386">做安卓内核开发时，kernel panic 是家常便饭。但如果 panic 后拿不到崩溃日志，排查问题就如同盲人摸象——你知道它崩了，却不知道崩在哪里。</div><div class="notion-text notion-block-31438ec39d198120af5ae69c40daf999">在一加 ACE5 上，panic 后 <code class="notion-inline-code">/sys/fs/pstore</code> 始终是空的，无法像常规 Linux 设备那样直接获取上次崩溃的 dmesg。本文记录了我为获取 panic 日志所做的全部尝试：从 ramoops 配置调整，到内核源码级的机制调研，再到最终发现高通 minidump 方案的完整探索过程。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31438ec39d19814bb0defa024fa4c47d" data-id="31438ec39d19814bb0defa024fa4c47d"><span><div id="31438ec39d19814bb0defa024fa4c47d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19814bb0defa024fa4c47d" 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-31438ec39d1981499c36c835c366a282">一切从一个简单的建议开始。有朋友告诉我，通过对 ramoops 驱动执行一次 unbind/bind 操作，可以让 <code class="notion-inline-code">/sys/fs/pstore</code> 下面出现文件：</div><div class="notion-text notion-block-31438ec39d19818d9effec3f426c0275">试了一下，文件确实出现了：</div><div class="notion-text notion-block-31438ec39d198196be5bf3a0c534b5de">但打开一看，内容完全和上一次的崩溃无关——更像是 unbind 那一刻转储的当前 dmesg，而不是 panic 时保存下来的日志。这说明 ramoops 驱动本身是能工作的，但上次 panic 时写入预留内存的数据已经不在了。</div><div class="notion-text notion-block-31438ec39d1981289850d8ebd00dbc73">问题可能出在 ramoops 的配置上——也许预留的内存区域大小不对，或者缓冲区分配有问题。于是我决定尝试修改 ramoops 的配置参数。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31438ec39d1981528e03c71d3f01aeec" data-id="31438ec39d1981528e03c71d3f01aeec"><span><div id="31438ec39d1981528e03c71d3f01aeec" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981528e03c71d3f01aeec" title="对 ramoops 配置的尝试"><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">对 ramoops 配置的尝试</span></span></h2><div class="notion-text notion-block-31438ec39d198168a65de42757978d92">先确认一下当前 pstore 使用的后端：</div><div class="notion-text notion-block-31438ec39d198130a158cdb895169703">返回的是 <code class="notion-inline-code">ramoops</code>，说明 pstore 确实在用 ramoops 作为后端。那问题大概率出在 ramoops 的缓冲区配置上。ramoops 有几个关键参数：<code class="notion-inline-code">record_size</code>（单条 oops/panic 记录大小）、<code class="notion-inline-code">console_size</code>（控制台日志大小）、<code class="notion-inline-code">pmsg_size</code>（用户空间 pmsg 大小）。如果 <code class="notion-inline-code">record_size</code> 为 0，panic 日志就不会被保存。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d19816d9092fe7a8d5977db" data-id="31438ec39d19816d9092fe7a8d5977db"><span><div id="31438ec39d19816d9092fe7a8d5977db" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19816d9092fe7a8d5977db" title="cmdline 修改"><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">cmdline 修改</span></span></h3><div class="notion-text notion-block-31438ec39d1981f7832df816508c54d5">最直接的想法是通过内核命令行参数覆盖 ramoops 配置。安卓的 boot image header 中有 cmdline 字段，可以通过 magiskboot 修改。</div><blockquote class="notion-quote notion-block-31438ec39d1981bfafe7c4a6c300cc99"><div>注意：magiskboot 需要使用 30.7 及以上版本，老版本在解析 <code class="notion-inline-code">-h</code> 参数时有 bug。</div></blockquote><div class="notion-text notion-block-31438ec39d198176a1f4ff13c961f4b9">首先尝试修改 init_boot 分区：</div><div class="notion-text notion-block-31438ec39d1981768602fc4c0e3c8396">在 header 文件中添加 ramoops 参数：</div><div class="notion-text notion-block-31438ec39d1981328143e7caf6ee31ba">刷入重启后，检查 <code class="notion-inline-code">/proc/cmdline</code>——没有任何变化。看来 init_boot 的 cmdline 没有被引导程序采用。</div><div class="notion-text notion-block-31438ec39d1981889d94c36fef3071c6">换一个思路，改 boot 分区：</div><div class="notion-text notion-block-31438ec39d19814a9a6fd161a77fde45">这次刷入重启后，<code class="notion-inline-code">/proc/cmdline</code> 里确实出现了我添加的参数。但检查 ramoops 的实际参数，发现它们完全没有变化。</div><div class="notion-text notion-block-31438ec39d1981fd848ddeaac550277e">阅读内核源码后找到了原因：安卓内核中 ramoops 的模块参数被标记为只读（<code class="notion-inline-code">module_param</code> 使用 <code class="notion-inline-code">0444</code> 权限），cmdline 中的参数只是被内核解析了，但 ramoops 驱动并不从 cmdline 读取配置——<b>它的配置完全来自设备树（Device Tree）</b>。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d19812eaf94d0d27856595c" data-id="31438ec39d19812eaf94d0d27856595c"><span><div id="31438ec39d19812eaf94d0d27856595c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19812eaf94d0d27856595c" title="dtbo 修改"><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">dtbo 修改</span></span></h3><div class="notion-text notion-block-31438ec39d1981b9aa1feeb6ec8f07fd">既然 cmdline 行不通，就得从设备树下手。</div><div class="notion-text notion-block-31438ec39d19819593f3ca9dbecb8d1e">在安卓设备上，设备树通常分为两部分：DTB（基础设备树，编译进 boot image）和 DTBO（Device Tree Blob Overlay，设备树叠加层，位于独立的 dtbo 分区）。DTBO 的设计初衷是让厂商在不修改基础 DTB 的情况下，通过叠加层来定制硬件配置。ramoops 的内存区域配置通常就放在 DTBO 中。</div><div class="notion-text notion-block-31438ec39d19817eb07be88cce4e3dd9">首先从设备中提取 dtbo 分区镜像：</div><div class="notion-text notion-block-31438ec39d1981d4a6c3f95ffdc7ed9a">拉到本地：</div><div class="notion-text notion-block-31438ec39d198145af59e913b818c533">DTBO 镜像是一个打包了多个 DTB overlay 的容器，需要专门的工具来解包。这里使用 mkdtimg：</div><div class="notion-text notion-block-31438ec39d19811488b8fca96ca90818">解包 DTBO 镜像，将每个 overlay 反编译为可读的 DTS（Device Tree Source）格式，然后搜索 ramoops 相关的配置：</div><div class="notion-text notion-block-31438ec39d19813a9308dd989d7f2f27">果然找到了。在其中一个 overlay 的 <code class="notion-inline-code">fragment@31</code> 中，有 ramoops 预留内存区域的配置。原始配置如下：</div><div class="notion-text notion-block-31438ec39d198106a552f8481abc4457">可以看到问题所在：整个预留区域只有 0x240000（2.25MB），其中 pmsg 占了 0x200000（2MB），console 占了 0x40000（256KB），而 <code class="notion-inline-code"><b>record-size</b></code><b> 根本没有定义</b>——这意味着 panic 时的 oops/panic 记录没有分配任何空间。</div><div class="notion-text notion-block-31438ec39d198168900af5f5b0be7cf9">修改后的配置，压缩 pmsg 空间，为 console 和 record 各分配 1MB：</div><div class="notion-text notion-block-31438ec39d1981689c6bc278ab067e81">将修改后的 DTS 重新编译为 DTB，再打包回 DTBO 镜像：</div><div class="notion-text notion-block-31438ec39d1981bba568d44ef5050437">检查新镜像的结构是否正确：</div><div class="notion-text notion-block-31438ec39d1981ffa774c5e8b435589b">确认无误后刷入设备，重启验证参数是否生效：</div><div class="notion-text notion-block-31438ec39d1981f290befe22ff9fa985">参数确实变了！<code class="notion-inline-code">console_size</code> 和 <code class="notion-inline-code">record_size</code> 都变成了预期的值。看起来这次应该能行了。</div><div class="notion-text notion-block-31438ec39d198143953af6db88b7e590">然而，手动触发一次 panic 后重启，<code class="notion-inline-code">/sys/fs/pstore</code> 下面依然空空如也。</div><div class="notion-text notion-block-31438ec39d1981ee9539ccd1a5739cf3">ramoops 参数已经正确，驱动也正常加载，panic 也确实发生了——但日志就是不见了。具体原因尚不明确，可能的方向包括：硬件层面 DRAM 在掉电-上电周期中无法保持内容（<code class="notion-inline-code">mem-type = 0x02</code> 表示使用的是普通 DRAM 而非 NVRAM）、bootloader 在启动早期主动清零了这片预留内存区域、或者 ramoops 驱动在该平台上存在其他未知的兼容性问题。</div><div class="notion-text notion-block-31438ec39d1981b48647f21e10fea314">ramoops 这条路暂时走不通了，需要寻找其他方案。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31438ec39d198183903ed2412d2736b5" data-id="31438ec39d198183903ed2412d2736b5"><span><div id="31438ec39d198183903ed2412d2736b5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d198183903ed2412d2736b5" 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-31438ec39d1981cc9ccee3f0bbc1d7be">既然 ramoops 靠不住，那不如自己动手——写一个内核模块，在 panic 时把日志直接写入 UFS 的某个分区。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d1981b79186e9664e16026f" data-id="31438ec39d1981b79186e9664e16026f"><span><div id="31438ec39d1981b79186e9664e16026f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981b79186e9664e16026f" title="以 mtdoops 为蓝本"><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">以 mtdoops 为蓝本</span></span></h3><div class="notion-text notion-block-31438ec39d198157a99bfd7d0d9461c3">内核中有一个现成的参考实现：mtdoops。它是一个独立的 kmsg dumper，在 panic 时将 printk ring buffer 中的日志写入 MTD 设备。我最初的想法很简单：参考 mtdoops 的源码架构，写一份类似的模块，把目标设备从 MTD 换成 <code class="notion-inline-code">/dev/block/by-name/logdump</code> 分区。</div><div class="notion-text notion-block-31438ec39d19813f841ecd875e0eebdd">不过在动手之前，有一个前提需要验证：<code class="notion-inline-code">logdump</code> 分区的数据在重启后是否真的能保留？如果 bootloader 会在启动时清空这个分区，那不管怎么写都是白费。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d198128ac8ed86b8b45876e" data-id="31438ec39d198128ac8ed86b8b45876e"><span><div id="31438ec39d198128ac8ed86b8b45876e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d198128ac8ed86b8b45876e" 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-31438ec39d198103b4a9d12f41dbd981">挑两个看起来和 dump 相关的分区（<code class="notion-inline-code">logdump</code> 和 <code class="notion-inline-code">rawdump</code>）做个简单测试：</div><div class="notion-text notion-block-31438ec39d19811c83a1c157c4e01cf8">数据完好无损。<code class="notion-inline-code">logdump</code> 和 <code class="notion-inline-code">rawdump</code> 分区在重启后不会被清空，可以作为持久化目标。</div><div class="notion-text notion-block-31438ec39d19813d88d1e92164fac7b8">顺手确认一下存储型号：</div><div class="notion-text notion-block-31438ec39d1981e3b6ebd8b68f36f065">三星 UFS 4.0 闪存，存储介质可靠。前提条件满足了，接下来就是搞定 panic 时的写入逻辑。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d1981a88631fe324fe029f2" data-id="31438ec39d1981a88631fe324fe029f2"><span><div id="31438ec39d1981a88631fe324fe029f2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981a88631fe324fe029f2" title="从 MTD 到 block：撞上了墙"><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">从 MTD 到 block：撞上了墙</span></span></h3><div class="notion-text notion-block-31438ec39d19814ab827c02e726b177d">然而，当我真正深入 mtdoops 的源码时，才意识到事情没那么简单。</div><div class="notion-text notion-block-31438ec39d1981159cdccabc4a9f94fe">mtdoops 之所以能在 panic 时成功写入，是因为它走的是 MTD 子系统的专用接口 <code class="notion-inline-code">mtd_panic_write()</code>。MTD（Memory Technology Device）面向的是 NOR/NAND Flash 这类原始闪存，驱动可以直接以轮询方式操作硬件寄存器完成擦写，不需要中断、不需要调度器，天然适合 panic 上下文。</div><div class="notion-text notion-block-31438ec39d1981a79a04fc3d9efc903a">但一加 ACE5 的存储是 UFS，它挂载在 SCSI/block 子系统下，和 MTD 完全是两个世界。我不能简单地把 mtdoops 的 <code class="notion-inline-code">mtd_panic_write()</code> 替换成 <code class="notion-inline-code">kernel_write()</code> 写 block 设备——<b>panic 发生时中断已禁用、调度器已停止，整个 block I/O 路径根本不可用</b>。</div><div class="notion-text notion-block-31438ec39d19819b8c5fd654a4209e48">换句话说，mtdoops 的架构只能借鉴思路（注册 kmsg dumper → panic 时从 ring buffer 读日志 → 写入持久化存储），但写入这一步在 UFS 上完全行不通。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d198177a831cafe7d4bbd57" data-id="31438ec39d198177a831cafe7d4bbd57"><span><div id="31438ec39d198177a831cafe7d4bbd57" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d198177a831cafe7d4bbd57" title="转向 pstore/blk"><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">转向 pstore/blk</span></span></h3><div class="notion-text notion-block-31438ec39d1981b49743e2239d5e3ca0">既然自己从头写不现实，那内核有没有现成的框架来解决”panic 时写 block 设备”这个问题？</div><div class="notion-text notion-block-31438ec39d1981d083a5cc9c33ba499e">答案是 pstore/blk——pstore 框架的块设备后端。它的设计目标正是把 panic 日志写入通用块设备分区。但深入源码后发现，它的可用性取决于一个关键条件：<b>存储驱动是否实现了 </b><code class="notion-inline-code"><b>panic_write</b></code><b> 回调</b>。</div><div class="notion-text notion-block-31438ec39d1981748fc4e22bf79dd21c">pstore/blk 的 best_effort 模式虽然可以挂载到任意块设备上，但看一下它的写函数实现：</div><div class="notion-text notion-block-31438ec39d19810fb9bfd740660ed4a8">这个函数只注册为普通 <code class="notion-inline-code">write</code>，而<b>不是</b> <code class="notion-inline-code">panic_write</code>。panic 时 pstore/zone 框架的选择逻辑是：</div><div class="notion-text notion-block-31438ec39d1981cf88f0d21bbfce6642">所以 best_effort 模式在 panic 时只会标记”脏”，期望下次正常启动时回写——但 panic 后系统已经重启，RAM 中的脏标记自然也丢了。</div><div class="notion-text notion-block-31438ec39d1981c59e60e935a6394523">要让 pstore/blk 真正在 panic 时落盘，需要存储驱动主动调用 <code class="notion-inline-code">register_pstore_device()</code>，并提供一个能在中断禁用上下文中以轮询方式直接操作硬件的 <code class="notion-inline-code">panic_write</code> 回调。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d19819bb56ee76b463b849b" data-id="31438ec39d19819bb56ee76b463b849b"><span><div id="31438ec39d19819bb56ee76b463b849b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19819bb56ee76b463b849b" title="UFS 驱动有 panic_write 吗？"><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">UFS 驱动有 panic_write 吗？</span></span></h3><div class="notion-text notion-block-31438ec39d19816eafa9dc653521a5f3">这成了关键问题。我让 Claude 帮忙阅读 AOSP android14-6.1 通用内核中 <code class="notion-inline-code">drivers/ufs/</code> 的全部源码，搜索任何与 <code class="notion-inline-code">panic_write</code>、<code class="notion-inline-code">pstore</code>、<code class="notion-inline-code">kmsg_dump</code> 相关的实现。</div><div class="notion-text notion-block-31438ec39d1981a9af1bceea43d7ea29">结果：<b>什么都没有。</b> AOSP 主线的 UFS 驱动完全没有实现 panic 路径下的持久化写入能力。</div><div class="notion-text notion-block-31438ec39d1981979813dfa4e0d35c23">Claude 提了一个思路：AOSP 通用内核的 UFS 驱动比较精简，但高通的下游 vendor 内核（<code class="notion-inline-code">msm-kernel</code>）中的 <code class="notion-inline-code">ufs-qcom.c</code> 可能有类似的同步写入机制。毕竟高通对自家平台的 UFS 控制器最了解，很可能在 vendor 分支里加了 panic 写入的支持。</div><div class="notion-text notion-block-31438ec39d19812ebd56c8838756de25">于是我让 Claude 转而分析一加 ACE5 的官方内核源码（<code class="notion-inline-code">android_kernel_oneplus_sm8650</code>）中的 UFS 驱动。结果依然令人失望：</div><table class="notion-simple-table notion-block-31438ec39d198100ae9ac1b96bb5c47c"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-31438ec39d1981b3a807c24e27b89366"><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-31438ec39d1981e3976eceb7eee59b8b"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">panic_write</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">未找到</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198195a910cde097c71b77"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">pstore_zone</code> / <code class="notion-inline-code">register_pstore_device</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">未找到</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198100803fe66bd565d3f3"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">kmsg_dump</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">未找到</div></td></tr></tbody></table><div class="notion-text notion-block-31438ec39d1981b7a2b1d58c82e62816">vendor 内核的 UFS 驱动里唯一和 panic 相关的代码是 <code class="notion-inline-code">ufs-qcom.c</code> 中注册的 panic notifier：</div><div class="notion-text notion-block-31438ec39d1981dab9ccc0fab6d4600d">这只是把 UFS 寄存器状态打印到 kernel log 用于调试，<b>和把日志写入 UFS 存储是完全不同的两件事</b>。</div><div class="notion-text notion-block-31438ec39d198145b2b7f42096ec0160">到这里，纯内核层面的方案基本全部走入了死胡同。问题的本质很清楚：panic 后 block 层不可用，而 UFS 驱动也没有实现绕过 block 层的轮询写机制。<b>谁能在 panic 时直接操作 UFS 硬件？</b></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31438ec39d19810b8265d7b950157a4a" data-id="31438ec39d19810b8265d7b950157a4a"><span><div id="31438ec39d19810b8265d7b950157a4a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19810b8265d7b950157a4a" title="深入 minidump"><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">深入 minidump</span></span></h2><div class="notion-text notion-block-31438ec39d1981fb96ebe28c4e50988c">纯内核方案走不通，但一加自己肯定有办法拿到 panic 日志。查看设备上加载的内核模块，过滤 dump 相关的：</div><div class="notion-text notion-block-31438ec39d198150917efcffef299fee">其中 <code class="notion-inline-code">minidump</code>、<code class="notion-inline-code">qcom_va_minidump</code>、<code class="notion-inline-code">memory_dump_v2</code> 是高通平台特有的崩溃转储模块。让 Claude 对一加 ACE5 内核源码中这些模块的实现进行调研，得到以下分析结果。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d1981eeaeb8f86652a28c17" data-id="31438ec39d1981eeaeb8f86652a28c17"><span><div id="31438ec39d1981eeaeb8f86652a28c17" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981eeaeb8f86652a28c17" 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-31438ec39d198183a16fd3ccbba6523e">minidump 是<b>高通平台私有的跨层协作方案</b>，涉及 TrustZone（EL3）、ABL（Android Bootloader）、内核驱动三层，不是纯内核机制。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d19817c80dce2666b4a8a5a" data-id="31438ec39d19817c80dce2666b4a8a5a"><span><div id="31438ec39d19817c80dce2666b4a8a5a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19817c80dce2666b4a8a5a" 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></h4><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d19815f912cf5cbdeea3662" data-id="31438ec39d19815f912cf5cbdeea3662"><span><div id="31438ec39d19815f912cf5cbdeea3662" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19815f912cf5cbdeea3662" title="内核侧：正常运行期间构建 minidump table"><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">内核侧：正常运行期间构建 minidump table</span></span></h4><div class="notion-text notion-block-31438ec39d1981c08409e80a1268f12a">内核驱动在<b>正常运行期间</b>（非 panic 时）就通过 API 注册要 dump 的内存区域：</div><div class="notion-text notion-block-31438ec39d1981d48022f310b645d887">典型注册内容包括 <code class="notion-inline-code">KSTACK</code>（内核栈）、<code class="notion-inline-code">KLOGBUF</code>（printk ring buffer）、<code class="notion-inline-code">KPGTBL</code>（内核页表）、各驱动关键结构体等。其中 <code class="notion-inline-code">KLOGBUF</code> 即 printk ring buffer——panic 时所有的 <code class="notion-inline-code">pr_emerg()</code>、<code class="notion-inline-code">dump_stack()</code> 输出都在这里。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d1981abb1fbd21a473b37f2" data-id="31438ec39d1981abb1fbd21a473b37f2"><span><div id="31438ec39d1981abb1fbd21a473b37f2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981abb1fbd21a473b37f2" title="TrustZone 能直接写 UFS 的原因"><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">TrustZone 能直接写 UFS 的原因</span></span></h4><div class="notion-text notion-block-31438ec39d1981bd9bd8d767d8798a6a">TrustZone 运行在 EL3，有对所有硬件的直接访问权，自带精简 UFS 驱动，使用寄存器轮询等待命令完成，完全不依赖 Linux 内核的 UFS 驱动栈和中断机制。这恰好绕开了前面所有纯内核方案的致命瓶颈。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d1981e4ab27de53e435145a" data-id="31438ec39d1981e4ab27de53e435145a"><span><div id="31438ec39d1981e4ab27de53e435145a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981e4ab27de53e435145a" 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></h4><table class="notion-simple-table notion-block-31438ec39d1981cba411f7f84d07099d"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-31438ec39d1981e5a685cb45c5391137"><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-31438ec39d1981f2aca0fced9beb3e73"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">drivers/soc/qcom/msm_minidump.c</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">核心注册接口，<code class="notion-inline-code">md_ops</code> dispatch</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d1981348355dcb6b4b4b663"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">drivers/soc/qcom/minidump_smem.c</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">SMEM 后端实现，管理 SMEM ID 602 中的全局 TOC</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198156ab22fc5b5efa1930"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">drivers/soc/qcom/minidump_log.c</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">HLOS 侧 region 注册（kernel sections、IRQ stack、panic dump 等）</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d19811caae9e63416ba735c"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">drivers/soc/qcom/qcom_va_minidump.c</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">VA minidump 框架，按需收集各子系统数据</div></td></tr></tbody></table><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d1981a98df9e1f2b930e3dd" data-id="31438ec39d1981a98df9e1f2b930e3dd"><span><div id="31438ec39d1981a98df9e1f2b930e3dd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981a98df9e1f2b930e3dd" 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></h4><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d19812f95afd7da039123ff" style="list-style-type:decimal"><li><b>高通下游内核</b>（<code class="notion-inline-code">msm-kernel</code>）中的 <code class="notion-inline-code">drivers/soc/qcom/minidump.c</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-31438ec39d1981128513e9160c3bc071" style="list-style-type:decimal"><li><b>TrustZone 固件</b>（闭源，高通提供的 <code class="notion-inline-code">.mbn</code> 文件）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-31438ec39d19817989f4dbd6647fbcbe" style="list-style-type:decimal"><li><b>ABL 中的 dump 处理代码</b>（高通 UEFI ABL，部分开源）</li></ol><div class="notion-text notion-block-31438ec39d198120891fda44acbca906">三者缺一不可，纯内核层面无法单独实现。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-31438ec39d1981ddafc9d9a5124c20ab" data-id="31438ec39d1981ddafc9d9a5124c20ab"><span><div id="31438ec39d1981ddafc9d9a5124c20ab" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981ddafc9d9a5124c20ab" 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></h4><table class="notion-simple-table notion-block-31438ec39d19811ba9ceefe4362351ee"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-31438ec39d1981b7a5f1dff309c9e7da"><td class="" style="width:120px"><div class="notion-simple-table-cell">对比项</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ramoops（内核方案）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">minidump（高通方案）</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198197806ad8b7f2f41981"><td class="" style="width:120px"><div class="notion-simple-table-cell">谁来写存储</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">panic 核（内存保留）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">TrustZone（EL3 固件）</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d1981cab6f9d2135999d80d"><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">否（TZ 自带轮询 UFS）</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198106bcc0e052e61d4cab"><td class="" style="width:120px"><div class="notion-simple-table-cell">存储介质</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">预留 RAM</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">UFS rawdump 分区</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d19811298e4c171b406839c"><td class="" style="width:120px"><div class="notion-simple-table-cell">数据量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">受 ramoops 分区大小限制</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">可配置，通常更大</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d198134be95e41521e0f92e"><td class="" style="width:120px"><div class="notion-simple-table-cell">可选择性</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">全量 kmsg</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">精细化（按模块注册的关键内存）</div></td></tr><tr class="notion-simple-table-row notion-block-31438ec39d1981e59fd1c1bc12790705"><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">高通私有（TZ 固件 + 下游内核驱动）</div></td></tr></tbody></table><div class="notion-text notion-block-31438ec39d19813196f3c829c37b5f44">至此可以确定：一加实际使用的是高通 minidump 机制，由 TrustZone 在 panic 后直接将内存内容写入 UFS，而非依赖 ramoops。ramoops 在该设备上无法生效的具体原因仍未定论，但这已不影响日志的获取。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-31438ec39d19814e9756fffd1cfdad2e" data-id="31438ec39d19814e9756fffd1cfdad2e"><span><div id="31438ec39d19814e9756fffd1cfdad2e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d19814e9756fffd1cfdad2e" 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-31438ec39d1981b68cbbca28336f05ae">理论到此为止，接下来只需要找到日志的具体存储位置。思路很简单：手动触发一次 panic，重启后从 dmesg 中搜索 minidump 相关的服务日志。</div><div class="notion-text notion-block-31438ec39d1981c4b06ecb2b353d8f01">首先确认上次重启确实是因为 panic：</div><div class="notion-text notion-block-31438ec39d19815da1b8f4a6489e1df1"><code class="notion-inline-code">kernel crash Minidump</code>——说明 minidump 机制确实被触发了。然后搜索 dmesg 中 minidump 相关的日志：</div><div class="notion-text notion-block-31438ec39d1981738094f7c4cb4fcdb0">从日志中可以还原出一加的 minidump 用户空间处理链：</div><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d19817cbf62c316fb474b54" style="list-style-type:decimal"><li><code class="notion-inline-code">minidumpreader</code> 读取 rawdump 分区中的 minidump 数据</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-31438ec39d1981e0bd4ef1678d083011" style="list-style-type:decimal"><li><code class="notion-inline-code">olcpackupminidump</code> 将日志打包</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-31438ec39d1981e78d31ceb1302155a1" style="list-style-type:decimal"><li><code class="notion-inline-code">minidumpraise2olc</code> 上报给 OLC（OnePlus Log Collection）服务</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-31438ec39d1981b1acdbcc9102970257" style="list-style-type:decimal"><li><code class="notion-inline-code">olc_get_minidump_log</code> 提取日志文件</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-31438ec39d19810e85f1d854d2099e59" style="list-style-type:decimal"><li><code class="notion-inline-code">backup_minidumplog</code> 备份到持久化路径</li></ol><div class="notion-text notion-block-31438ec39d19812e9ff3f3b67374811e">其中最关键的一行是那个 <code class="notion-inline-code">mount</code> 命令——它暴露了日志的存储路径：</div><div class="notion-text notion-block-31438ec39d1981469927e9a5f7d25103">三次 panic 的日志都在。文件名格式为 <code class="notion-inline-code">SYSTEM_LAST_KMSG@&lt;hash&gt;@&lt;版本号&gt;@&lt;时间戳&gt;.dat.gz</code>。备份路径也有一份：</div><div class="notion-text notion-block-31438ec39d19818c9225f81659f0aa5a">把文件拉出来、解压、用 <code class="notion-inline-code">strings</code> 提取可读内容——完整的 panic 日志赫然在目。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d1981a29e66cbaa78b8577b" data-id="31438ec39d1981a29e66cbaa78b8577b"><span><div id="31438ec39d1981a29e66cbaa78b8577b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d1981a29e66cbaa78b8577b" 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-31438ec39d19810db91dc47b98ae436b">总结最终可用的 panic 日志提取流程：</div><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d19816e891dc7b217e05115" style="list-style-type:decimal"><li>触发或等待一次 kernel panic，设备会自动重启</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-31438ec39d19817daf64e77aa772e7ce" style="list-style-type:decimal"><li>重启后确认重启原因：</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d1981b58afeccb02c8d0f0c" style="list-style-type:decimal"><li>通过 <code class="notion-inline-code">adb shell</code> 进入 root shell，将日志文件复制到 adb 可访问的路径并修改权限：</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d1981e59a7bdfbf78f7b310" style="list-style-type:decimal"><li>拉取到本地：</li></ol><ol start="1" class="notion-list notion-list-numbered notion-block-31438ec39d1981f68b2ce7a1b58f5f90" style="list-style-type:decimal"><li>解压并提取可读的崩溃日志：</li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-31438ec39d198176b4c4e2661af59ffa" data-id="31438ec39d198176b4c4e2661af59ffa"><span><div id="31438ec39d198176b4c4e2661af59ffa" class="notion-header-anchor"></div><a class="notion-hash-link" href="#31438ec39d198176b4c4e2661af59ffa" 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-31438ec39d19814cb5f9ee930578a1c9">整个探索过程走了不少弯路，但也因此对 Linux 内核的 panic 日志转储体系有了系统性的理解：</div><ul class="notion-list notion-list-disc notion-block-31438ec39d1981bfacd6f74940f1a110"><li><b>ramoops</b>：最通用的方案，将日志写入预留内存，但依赖这片内存跨重启不被清除。在一加 ACE5 上实测修改 dtbo 配置后仍无法生效，具体原因未明</li></ul><ul class="notion-list notion-list-disc notion-block-31438ec39d19817fb307f65de723c8ab"><li><b>mtdoops</b>：架构简洁的 MTD 闪存 dumper，但它的写入接口绑定在 MTD 子系统上，无法用于 UFS 存储</li></ul><ul class="notion-list notion-list-disc notion-block-31438ec39d19810f9c55f0fc50a50804"><li><b>pstore/blk</b>：pstore 的块设备后端，设计上支持通用块设备，但 panic 时 block 层不可用，需要存储驱动实现 <code class="notion-inline-code">panic_write</code> 回调——而 AOSP 主线和一加 vendor 内核的 UFS 驱动均未实现</li></ul><ul class="notion-list notion-list-disc notion-block-31438ec39d198139b0f0c21fc15262d0"><li><b>minidump</b>：高通私有方案，panic 后由 TrustZone 在 EL3 接管控制权，用自带的精简 UFS 驱动直接写入存储——这才是一加实际使用的机制</li></ul><div class="notion-text notion-block-31438ec39d1981468379d1b8a9a7d6d3">对于一加 ACE5（以及其他使用高通平台的一加设备），panic 日志最终存储在 <code class="notion-inline-code">/mnt/vendor/oplusreserve/media/log/minidump/</code> 目录下，以 <code class="notion-inline-code">SYSTEM_LAST_KMSG</code> 为前缀的 gzip 压缩文件中。</div></main></div>]]></content:encoded>
        </item>
        <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>
    </channel>
</rss>