feat: U4 ciphertext page dump tool
- utrw/debug.c: utrw_debug_dump_page(slot,page,offset) — kernel debug-privileged dump of 64B ciphertext + decrypted plaintext hex to serial (PCKC key derive, no capability path) - selftest demo: dump at offset 128 shows plaintext 'deshab utsm sealed memory selftest' vs unrelated ciphertext; SELFTEST PASS (.build_tmp/qemu_serial_u4dump.log)
This commit is contained in:
@@ -173,7 +173,7 @@ kernel_api 已暴露能力:log, rsdp_address, fb_address/width/height/pitch/bp
|
||||
|
||||
下一阶段优先路线(活跃路线 = `docs/ROADMAP_INSANE.md` 五期填补计划,任务编号 F/U/D/R/E;状态唯一来源 = `docs/STATUS.md`):
|
||||
1. **一期 F 系列收尾**: F2 统一控制台后端(fbcon.h 抽象已落,panic 已用)。(F1 莲花 panic / F3 跨平台 Makefile / F4 boot 分级自检 / F5 skip_firstinit 已完成)
|
||||
2. **二期 U 系列**: @sealed 段标记、密文页 dump、selftest 覆盖率提升(~~UTRW Slow Path 真分支~~ U2 已完成:EPOCH/KEY_MISS 恢复 + MAC_FAILED/POISONED→DRR,selftest PASS)。
|
||||
2. **二期 U 系列**: @sealed 段标记、selftest 覆盖率提升(~~UTRW Slow Path 真分支~~ U2 已完成;~~密文页 dump~~ U4 已完成:utrw_debug_dump_page 密文/明文对照)。
|
||||
3. **三期 D 系列**: DKM 热卸载(引用计数)、裸机器码加载器、按名 API 导出表、彩色日志。
|
||||
4. **四期 R 系列收尾**: segment/system 级回滚验证、PCQ per-cpu 多核。(~~drr_emergency_pool_kb/drr_recovery_log_size 接线~~ R3b 已完成,运行期钳位验证 PASS)
|
||||
5. **五期 E 系列**: 启动莲花动画、假想时光键彩蛋、提交信息规范、风味 ISO。
|
||||
|
||||
@@ -15,4 +15,7 @@ int utsm_write(utsm_capability cap, u64 offset, const void *src, u64 len);
|
||||
int utsm_slow_path(utsm_capability cap, u32 rights, u64 offset, u64 len,
|
||||
int reason, utsm_capability *out_cap);
|
||||
|
||||
/* U4: 密文页 dump(调试特权:串口输出 offset_in_page 起 64B 密文/明文 hex 对照) */
|
||||
int utrw_debug_dump_page(u32 segment_slot, u64 page_index, u64 offset_in_page);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -72,6 +72,15 @@ int utsm_selftest_run(void) {
|
||||
}
|
||||
log_info("[UTSM] selftest read ok");
|
||||
|
||||
/* ==== U4: 密文页 dump —— 串口输出密文/明文 hex 对照 ==== */
|
||||
{
|
||||
int dst = utrw_debug_dump_page(cap.segment_slot, 0, 128);
|
||||
if (dst != UTSM_OK) {
|
||||
log_error("[UTSM] selftest cipher dump failed");
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==== U2: Slow Path 真分支(EPOCH 刷新 / KEY_MISS 重派生 / POISONED 拒绝) ==== */
|
||||
{
|
||||
/* 1) EPOCH 过期:伪造 stale cap(epoch=desc->key_epoch+1),slow path 应
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,88 @@
|
||||
#include <utsm/utrw.h>
|
||||
#include <utsm/segment.h>
|
||||
#include <utsm/pckc.h>
|
||||
#include <utsm/crypto.h>
|
||||
#include <utsm/log.h>
|
||||
|
||||
void *memcpy(void *dst, const void *src, usize len);
|
||||
|
||||
/* ===================================================================
|
||||
* U4: 密文页 dump 工具
|
||||
*
|
||||
* "发疯也要可调试。"
|
||||
* 对指定段页输出 密文 hex + 解密后明文 hex 对照——开发者可直接
|
||||
* 在串口日志核对加密正确性(密文 != 明文、重读一致)。
|
||||
*
|
||||
* 内核调试特权路径:不经过 capability 校验(这正是工具的意义),
|
||||
* 密钥经 PCKC 直接派生。仅调试用,不进任何热路径。
|
||||
* =================================================================== */
|
||||
|
||||
static void hexdump_line(const char *tag, u64 index, const u8 *data, u64 len) {
|
||||
char buf[8 + 2 + 3 * 8 + 1];
|
||||
/* "ssssssss: xx xx xx xx xx xx xx xx" */
|
||||
static const char hexd[] = "0123456789abcdef";
|
||||
for (int i = 0; i < 8; i++) {
|
||||
u8 nib = (u8)((index >> ((7 - i) * 4)) & 0xF);
|
||||
buf[i] = hexd[nib];
|
||||
}
|
||||
buf[8] = ':';
|
||||
for (u64 b = 0; b < 8; b++) {
|
||||
buf[9 + b * 3] = ' ';
|
||||
u8 v = (b < len) ? data[b] : 0;
|
||||
buf[10 + b * 3] = hexd[(v >> 4) & 0xF];
|
||||
buf[11 + b * 3] = hexd[v & 0xF];
|
||||
}
|
||||
buf[9 + 8 * 3] = 0;
|
||||
log_info(tag);
|
||||
log_info(buf);
|
||||
}
|
||||
|
||||
int utrw_debug_dump_page(u32 segment_slot, u64 page_index, u64 offset_in_page) {
|
||||
utsm_segment_desc *desc = utsm_get_segment(segment_slot);
|
||||
if (!desc || desc->state != UTSM_SEG_ACTIVE) {
|
||||
return UTSM_ERR_INVALID;
|
||||
}
|
||||
u64 page_off = page_index * UTSM_PAGE_SIZE;
|
||||
if (page_off + UTSM_PAGE_SIZE > desc->cipher_length ||
|
||||
offset_in_page + 8 > UTSM_PAGE_SIZE) {
|
||||
return UTSM_ERR_BOUNDS;
|
||||
}
|
||||
|
||||
log_info("[UTRW] dump: segment");
|
||||
log_hex64("[UTRW] slot=", segment_slot);
|
||||
log_hex64("[UTRW] page=", page_index);
|
||||
log_hex64("[UTRW] offset=", offset_in_page);
|
||||
|
||||
const u8 *cipher = desc->cipher_base + page_off + offset_in_page;
|
||||
const u64 SHOW = 64; /* 64B(1 cache line)足以核对 */
|
||||
|
||||
/* ---- 密文 hex ---- */
|
||||
for (u64 off = 0; off < SHOW; off += 8) {
|
||||
hexdump_line("[UTRW] cipher=", page_off + offset_in_page + off, cipher + off, 8);
|
||||
}
|
||||
|
||||
/* ---- 明文 hex(内核调试特权解密:PCKC 派生 + line 解密) ---- */
|
||||
utsm_key_material key;
|
||||
int st = utsm_pckc_get_or_derive(segment_slot, desc, &key);
|
||||
if (st != UTSM_OK) {
|
||||
log_warn("[UTRW] dump: key derive failed");
|
||||
return st;
|
||||
}
|
||||
u64 dump_line = (page_off + offset_in_page) / UTSM_CACHE_LINE_SIZE;
|
||||
u8 plain[UTSM_CACHE_LINE_SIZE];
|
||||
{
|
||||
u64 tweak = utsm_make_tweak(desc->tweak_seed, dump_line, desc->key_epoch);
|
||||
utsm_crypt_line(&key, tweak,
|
||||
desc->cipher_base + dump_line * UTSM_CACHE_LINE_SIZE, plain);
|
||||
}
|
||||
u64 in_line = (page_off + offset_in_page) % UTSM_CACHE_LINE_SIZE;
|
||||
for (u64 off = 0; off < SHOW; off += 8) {
|
||||
u64 src = in_line + off;
|
||||
if (src >= UTSM_CACHE_LINE_SIZE) break;
|
||||
hexdump_line("[UTRW] plain= ", page_off + offset_in_page + off,
|
||||
plain + src, 8);
|
||||
}
|
||||
|
||||
log_info("[UTRW] dump done");
|
||||
return UTSM_OK;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
utrw/debug.o: utrw\debug.c include\utsm\utrw.h include\utsm\types.h \
|
||||
include\utsm\status.h include\utsm\capability.h include\utsm\segment.h \
|
||||
include\utsm\uuid.h include\utsm\dirty.h include\utsm\pckc.h \
|
||||
include\utsm\config.h include\utsm\crypto.h include\utsm\log.h
|
||||
include\utsm\utrw.h:
|
||||
include\utsm\types.h:
|
||||
include\utsm\status.h:
|
||||
include\utsm\capability.h:
|
||||
include\utsm\segment.h:
|
||||
include\utsm\uuid.h:
|
||||
include\utsm\dirty.h:
|
||||
include\utsm\pckc.h:
|
||||
include\utsm\config.h:
|
||||
include\utsm\crypto.h:
|
||||
include\utsm\log.h:
|
||||
Binary file not shown.
@@ -95,3 +95,5 @@ pe_dll_search=1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -95,3 +95,5 @@ pe_dll_search=1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ Deshab 最标志性的疯点——给空气上锁。
|
||||
| U1 | UTSM 元数据区(UUID 表) | 每页都有"身份" | ✅ | 封缄段表 + UUID 调谐已就位(`CODE/UTSM/core/segment.c`),可查询页归属 |
|
||||
| U2 | UTRW Fast/Slow Path 真分支 | 快慢路不是画出来的 | ✅ | Fast path ✅;Slow path ✅(EPOCH/KEY_MISS 恢复,MAC_FAILED/POISONED 交 DRR,selftest PASS) |
|
||||
| U3 | `@sealed` 段可选标记 | 用户能选锁不锁 | ⬜ | 链接脚本支持 `__sealed` section;未标记段 0 开销 |
|
||||
| U4 | 密文页 dump 工具 | 发疯也要可调试 | 🔶 | shell 可读内存;专用 dump 命令 + 明文/密文对照待做 |
|
||||
| U4 | 密文页 dump 工具 | 发疯也要可调试 | ✅ | `utrw_debug_dump_page`:串口 64B 密文/明文 hex 对照,selftest 内置演示(QEMU PASS) |
|
||||
| U5 | UTSM selftest 全覆盖 | 把🔶刷成✅ | 🔶 | chacha20 KAT/段表/越界已覆盖,KAT 间歇 FAIL 待修;覆盖率目标 ≥70% |
|
||||
|
||||
二期做完:UTSM 从"设计"变"可开关的特性",疯得有旋钮。
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
| UTRW Fast Path | ✅ | capability→PCKC→line 解密→seqlock | `utrw/read.c` |
|
||||
| UTRW Slow Path(U2) | ✅ | EPOCH 刷新 / KEY_MISS 重派生 / POISONED+MAC_FAILED→DRR / STALE_CAP 拒绝;全分支 selftest PASS | `utrw/slow_path.c` + `.build_tmp/qemu_serial_u2slowpath.log` |
|
||||
| `@sealed` 段标记(U3) | ⬜ | 未实现 | — |
|
||||
| 密文页 dump(U4) | ✅ | `utrw_debug_dump_page(slot,page,offset)`:串口输出 64B 密文/明文 hex 对照(selftest 内置演示) | `.build_tmp/qemu_serial_u4dump.log` |
|
||||
| selftest(U5) | 🔶 | KAT/段表/越界已覆盖;chacha20 KAT 间歇 FAIL 待修 | `test/utsm_selftest.c` |
|
||||
| 真实加密原语 | 🔶 | chacha20/KDF/MAC 已落(Phase 9 早期),PCKC schedule 待接 | `crypto/` |
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
- [x] U1 UTSM 元数据区 / UUID 调谐表
|
||||
- [x] U2 UTRW Slow Path 真分支(EPOCH/KEY_MISS 恢复 + MAC_FAILED/POISONED→DRR;selftest PASS)
|
||||
- [ ] U3 `@sealed` 段可选标记(链接脚本 `__sealed` section)
|
||||
- [ ] U4 密文页 dump 工具(明文/密文对照命令)
|
||||
- [x] U4 密文页 dump 工具(utrw_debug_dump_page:密文/明文 hex 对照,selftest 演示 PASS)
|
||||
- [ ] U5 UTSM selftest 全覆盖(修 chacha20 KAT 间歇 FAIL,覆盖率 ≥70%)
|
||||
|
||||
## 🔌 三期:自由(DKM/用户态)
|
||||
|
||||
Reference in New Issue
Block a user