← Back to Pull requests

KZT, fix: Defer static Guest TLS preparation on transient loader views #582

Open
xiangzhai opened this pull request with 98 lines diff across 3 files
View on GitHub
xiangzhai xiangzhai commented on Dec 01, 2026 07:47 UTC
Author

Summary / 变更说明

修复 KZT 模式下并发加载 guest 库时,提前准备静态 TLS 被误判为致命错误的问题。

背景

guest loader 在 r_debug 状态切换过程中,带过滤条件的 TLS 快照可能暂时找不到目标对象,返回 KZT_PUBLIC_LOADER_NOT_FOUND 而不是 BUSY。kzt_collect_guest_tls_object() 将其当作硬错误,kzt_try_bind_before_guest_relro() 随即以 KZT cannot initialize static Guest TLS before RELRO protection; refusing to run constructors 退出。当多个 native 线程并发 dlopen/dlclose guest 库时即可触发(例如 NBL 的 test_concurrent_loader)。

改动

  • target/i386/latx/context/myalign.c

  • - kzt_collect_guest_tls_object():把带过滤快照的 KZT_PUBLIC_LOADER_NOT_FOUND 与 BUSY 一并视为瞬时的 KZT_GUEST_TLS_REFRESH_BUSY,不再返回硬错误。
    - kzt_try_bind_before_guest_relro():遇到 KZT_GUEST_TLS_REFRESH_BUSY 时延后静态 TLS 准备,交由常规的 post-loader refresh 完成;其它真实错误仍保持致命处理。
  • 测试

  • - tests/unit/kzt/check_kzt_tls_preinit_deferral.py:校验 NOT_FOUND 被归类为瞬时状态,且 RELRO 前准备在 BUSY 时延后而非直接退出。
    - tests/unit/meson.build:注册 check-kzt-tls-preinit-deferral 到 lat-pr-fast suite。

    Validation / 验证

  • 新的源码不变量检查通过:

  • - kzt Guest TLS preinit deferral checks: PASS
    - 对修复前的 myalign.c 运行该检查会失败(FAIL: a filtered snapshot may transiently miss the object (NOT_FOUND)),确认能拦截回退。
  • myalign.c 在具备 KZT 的构建上增量编译通过。

  • NBL 的 test_concurrent_loader(8 个 native 线程并发加载/卸载 guest 库)修复前在 RELRO 阶段触发 KZT cannot initialize static Guest TLS before RELRO protection;修复后连续 5 次运行均通过,test_pthread 也不再触发同一错误。

  • 相关回归(test_tls、test_cxa_thread_atexit、test_host_thread_tls、test_attach_churn、test_deep_callback、test_g2h_handoff)均通过。
  • 说明:本地 lat/build64 当前配置为 “No tests defined”,无法直接执行 meson test;整树 ninja 链接因环境中缺少 /usr/lib/libglib-2.0.so.0.8800.2 失败。二者均为既有环境问题,与本次改动无关。

    Checklist / 检查项

  • I have read CONTRIBUTING.md. / 我已阅读 CONTRIBUTING.md。

  • Every commit contains a DCO sign-off (git commit -s). /

  • 每个提交都包含 DCO 签署(git commit -s)。
  • I have included relevant build or test results, or explained why they

  • are not applicable. /
    我已提供相关构建或测试结果,或说明了不适用的原因。

    Diff: 98 lines (+89 / -9) across 3 files Reviewer: None requested Review duration: 4888m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.69) × (1 − Review Confidence (0.66)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.69 · 98 lines diff across 3 files
    0.69
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.56 · 2 substantive comment(s)
    0.56
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    65%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.275
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Sensitive Paths sensitive_paths
    0.069
    Real PR Conversation Timeline
    3 items
    zhaodongru zhaodongru commented on Dec 04, 2026 01:57 UTC
    Contributor

    经测试,在库直通场景下。在宿主回调触发 Guest dlopen() 后,注入 RELRO 前的 TLS 快照缺失,检查静态 TLS 能否正确初始化。注入一次 NOT_FOUND 后,旧版在插件构造函数运行前退出,退出码为 1。新版重试成功,插件完成构造及 TLS 读写,检查值为 73,退出码为 0。另注入 READ_ERROR,新旧版本均按预期拒绝。

    在已覆盖的库直通场景中,原有问题在补丁前可复现、补丁后未再出现,相关回归测试未发现新增问题。

    xiangzhai xiangzhai commented on Dec 04, 2026 02:20 UTC
    Author

    感谢review!

    Reviewers
    None requested
    Assignees
    xiangzhai xiangzhai
    Labels
    risk: low confidence: 65.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68.6% (HIGH) · Higher = larger blast radius
    68.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 65.8% · Lower = rushed or shallow review
    65.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.5% · Safe to merge
    23.5%