Repository navigation
Description
以下为静态代码核对结果,未加载/运行驱动,未做运行时复现;行号基于 main 12c5410c。
1. [高] HWID dispatch hook 在卸载路径没有恢复
KswordARKHwidInstallSlot 会把目标驱动(Disk/partmgr/mountmgr/nvlddmkm/nsiproxy 等)的 MajorFunction[IRP_MJ_DEVICE_CONTROL] 换成 KswordARKHwidDispatchPassthrough,并 ObReferenceObject 目标 DRIVER_OBJECT:
- 安装:
src/features/hwid/hwid_dispatch_ioctl.c:270-280 - 恢复/解引用:
src/features/hwid/hwid_dispatch_ioctl.c:312-322,只在控制 IOCTL 的 remove 路径调用
KswordARKDriverShutdownCore(src/framework/driver_entry.c:545-610)没有对应的 HWID uninitialize。只要启用过任一槽位后停止/卸载驱动,目标驱动的 MajorFunction 仍指向已卸载映像,后续对这些驱动发 IOCTL 会跳入已释放代码(常见 0x50/0x1E/0x7E),同时泄漏最多 5 个 DRIVER_OBJECT 引用。
建议:增加 KswordARKHwidUninitialize(),置 shutting-down 标志,持 g_KswordHwidDispatchLock 遍历槽位恢复 OriginalDispatch 并 ObDereferenceObject,再等待 in-flight passthrough/完成例程退出(EX_RUNDOWN_REF 或计数)后返回;在 KswordARKDriverShutdownCore 中、KswordARKDriverImageUninitialize() 之前调用。
2. [中] HWID passthrough 无锁读取槽位与 profile
KswordARKHwidDispatchPassthrough 直接调用 KswordARKHwidFindSlotNoLock(Device->DriverObject)(hwid_dispatch_ioctl.c:142),没有持有 g_KswordHwidDispatchLock;随后 KswordARKHwidNormalizeProfile(&activeProfile, &g_KswordHwidActiveProfile)(:151)在未同步的情况下复制约 1.2KB 的 profile。控制路径的 enable/disable 用 fast mutex 串行化写,但目标驱动的派遣路径不会拿这个锁。
结果:并发 enable/disable 时可能读到新旧混合的序列号/MAC,或读到即将清空的 OriginalDispatch。
建议:槽位查找与 profile 快照用一个 KSPIN_LOCK 保护(只覆盖复制,不跨原始 dispatch 调用),或用 generation/seqlock 让读者复制后校验;禁用槽位前等待该槽位 in-flight 计数归零。
3. [低] 每次池分配都解析 ExAllocatePool2
src/platform/pool_compat.c:58-59:每次 KswordARKAllocateNonPagedPool 都执行 RtlInitUnicodeString + MmGetSystemRoutineAddress,包括 DISPATCH 级 HWID 完成上下文分配。MmGetSystemRoutineAddress 会遍历模块列表并取锁。
建议:初始化或首次调用时解析一次,用 InterlockedCompareExchangePointer 发布缓存;不可用时缓存 fallback,后续直接走 ExAllocatePoolWithTag。
4. [低] IOCTL registry 每请求线性扫描
src/dispatch/ioctl_registry.c:595-600:225 条注册表从表头线性比较。高频轮询下是可测量的常数开销。
建议:按控制码排序后二分,或利用功能号连续区间做直接索引;构建时做一次排序/校验。
5. [提示] dispatch 入口每请求打印 Info 日志
src/dispatch/ioctl_dispatch.c:142-146 每个 IOCTL 都写一条 RXPF-DIAG dispatch entered Info 日志(注释自称 TEMP DIAG)。高频查询会持续覆盖 64 槽日志环。
建议:移到 debug/verbose 开关后,或在失败/unsupported 路径保留。
Activity
fix(hwid): capture a consistent profile for each matching IRP
fix(hwid): preserve concurrent dispatch changes during removal
fix(driver): preserve upper IRP completion and constrain HWID output …