Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(win-isa-guard): APX-Register in den Operanden als Datenfehldekodierung einstufen

purplee0e63045ef21
diff --git a/scripts/__fixtures__/win-isa/apx-decode-artifact.disasm.txt b/scripts/__fixtures__/win-isa/apx-decode-artifact.disasm.txt
new file mode 100644
index 00000000..afa9375d
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/apx-decode-artifact.disasm.txt
@@ -0,0 +1,28 @@
+Dump of file fixture: R7, the APX decode artifact (lu-301/bau/isa-guard-apx.md).
+Two hits, on purpose, because the rule has to be proved in both directions.
+
+Hit 1 is the exact line sidecar-windows.yml run 35640770023 (job 106469248703,
+release/3.0.1-prep) printed for mtmd.dll, address and operand text reproduced
+character for character from lu-301/bau/isa-guard-ci-auszug.txt. It addresses
+memory through r25, an Intel APX extended general purpose register that MSVC
+does not emit for x64, so these bytes are a jump table or constant pool inside
+.text that dumpbin swept over as if it were code. It must come out
+DECODE_ARTIFACT_APX. The owner in the map below is $LN4275 in clip.obj,
+likewise as reported: a compiler-generated local label, which is what MSVC
+attaches to a data block in .text and never to a function.
+
+Hit 2 is the counter-test and must stay UNPROTECTED: a real AVX-512 EVEX
+instruction with zmm registers, a k-mask and the {z} zeroing suffix, sitting
+in an own-code function with no isa-flag check in front of it, but addressed
+through the ordinary rax-r15 register file. The rule keys on the APX
+registers alone and on nothing else about AVX-512 spelling, so this one is
+not excused, and the module still fails.
+
+The byte columns are reconstructed, not copied: the CI log kept only the
+guard's own verdict lines, never the raw disassembly around these addresses.
+Only the leading opcode byte is load-bearing for the guard (0x62 = EVEX, R1),
+and it is correct in both rows.
+
+ 0000000180097301: 62 51 04 CC 56 39 vorps zmm25{k4}{z},zmm15,zmmword ptr [r25]
+ 0000000180097410: 62 F1 6C C9 56 0C 24 vorps zmm1{k1}{z},zmm2,zmmword ptr [rsp]
+ 0000000180097417: C3 ret
diff --git a/scripts/__fixtures__/win-isa/apx-decode-artifact.map.txt b/scripts/__fixtures__/win-isa/apx-decode-artifact.map.txt
new file mode 100644
index 00000000..ed33502c
--- /dev/null
+++ b/scripts/__fixtures__/win-isa/apx-decode-artifact.map.txt
@@ -0,0 +1,6 @@
+ Static symbols
+
+ 0001:00000000 $LN4275 0000000180097300 f clip.obj
+ 0001:00000110 clip_own_avx512_kernel 0000000180097410 f clip.obj
+ 0001:00000210 clip_own_avx512_kernel_end 0000000180097510 f clip.obj
+ 0003:00000010 __isa_available 0000000180099898 MSVCRT:cpu_disp.obj
diff --git a/scripts/win-isa-guard.mjs b/scripts/win-isa-guard.mjs
index ad07ab30..055ce783 100644
--- a/scripts/win-isa-guard.mjs
+++ b/scripts/win-isa-guard.mjs
@@ -40,6 +40,13 @@
// object condition, let an unrelated own-code symbol that merely
// contains "memcmp" in a mangled name through as ALLOWED_CRT; fixed
// by requiring both conditions together.)
+// - The decoded operands name an Intel APX extended general purpose
+// register (r16-r31, as base, index or plain operand):
+// DECODE_ARTIFACT_APX, i.e. these bytes are data the disassembler
+// swept over as if they were code, not an instruction the compiler
+// emitted (R7, see hasApxRegisterOperand below). Printed per hit and
+// counted in its own summary line, never silently dropped, and it
+// does NOT count as unprotected.
// - Anything else ("own code": ggml-*.obj, llama-*.obj, common.obj,
// server-*.obj, ggml-vulkan.obj) is ALLOWED only if, within the
// owning function's address range, there is a read of
@@ -161,6 +168,74 @@ export function findVexEvexHits(lines) {
return lines.filter(isVexEvexHit);
}
+// R7 (lu-301/bau/isa-guard-apx.md): an Intel APX register in the decoded
+// operands means the disassembler decoded DATA, not code.
+//
+// R1's opcode-byte rule is exact about what 0xC4/0xC5/0x62 mean IF the byte
+// really starts an instruction. dumpbin and objdump cannot know that: both
+// sweep .text linearly, so a jump table, a switch table or a constant pool
+// that MSVC placed in .text is decoded as if it were code, and any data byte
+// that happens to be 0x62 opens an EVEX decode which then eats whatever
+// follows it. That residual data-misdecode class is what the opcode-byte
+// rule shrank (verr/verw/vmread became structurally impossible) but could
+// not remove.
+//
+// The cheap, structural way to tell such a misdecode apart from real code
+// here is the register file. r16-r31 exist only with Intel APX. MSVC for x64
+// does not emit APX: no /arch switch selects it, and neither toolset this
+// guard has met does so (14.44 on the box, 14.51 on the CI runner). On top
+// of that, this project's own objects are compiled at the x64 baseline, with
+// the AVX kernels confined to the ggml-cpu-* tier DLLs, so an own-code
+// instruction addressing memory through r25 is not something the compiler
+// could have produced at all. It comes out of a disassembler walking bytes
+// that were never instructions.
+//
+// What triggered this rule (sidecar-windows.yml run 35640770023, job
+// 106469248703, release/3.0.1-prep, log excerpt in
+// lu-301/bau/isa-guard-ci-auszug.txt), two hits with the same signature:
+//
+// 0000000180097301: vorps zmm25{k4}{z},zmm15,zmmword ptr [r25]
+// fn=$LN4275 obj=clip.obj (mtmd.dll)
+// 00000001800dcadc: vpshufb xmm16,xmm30,xmmword ptr [r25]
+// fn=$LN191 obj=server-context:server-tools.obj
+// (llama-server-impl.dll)
+//
+// Three signals converge on both: the owner is a $LN local label, which is
+// what MSVC attaches to jump tables and data blocks inside .text and never
+// to a function; the operands are AVX-512 (zmm, a k-mask, {z}) in modules
+// built without /arch:AVX512; and the base register is an APX EGPR. The same
+// two modules on the box, built with linker 14.44, showed 24 and 72 hits and
+// zero unprotected (review-k1-avx.md, "Zusatzbefund"). The runner's newer
+// toolset ships a dumpbin that knows APX and therefore spells those same
+// data bytes as an APX instruction where the older one did not.
+//
+// THE COST, NAMED, not hidden: if a future MSVC does start emitting APX code
+// for x64, a genuinely unguarded APX instruction would be classified as an
+// artifact here instead of going RED. That is bounded, not open ended: a new
+// linker Major.Minor already fails the build through the toolset pin in
+// verify-sidecar-isa.sh (WINDOWS_REVIEWED_LINKER_VERSIONS) until it has been
+// reviewed by hand, and this rule is one of the things such a review has to
+// re-check.
+//
+// The rule is kept as narrow as the evidence: ONLY the extended general
+// purpose registers count. zmm16-zmm31, the k-mask registers, the {z}
+// zeroing suffix and every other AVX-512 spelling are NOT evidence of a
+// misdecode, because MSVC does emit those under /arch:AVX512, so a real
+// unguarded AVX-512 instruction addressed through the ordinary rax-r15
+// registers still comes out UNPROTECTED (second hit in the fixture
+// scripts/__fixtures__/win-isa/apx-decode-artifact.*). There is deliberately
+// no allowlist by file name either: the decision reads the decoded operands
+// only, so clip.obj and mtmd.dll get no special treatment whatsoever.
+//
+// Word boundaries on both sides keep this off unrelated spellings: "cr16"
+// and "dr16" do not match (the boundary fails before the r), and the
+// optional d/w/b suffix covers r16d/r16w/r16b as well as AT&T's %r25.
+const APX_EGPR_OPERAND = /\br(?:1[6-9]|2[0-9]|3[01])[dwb]?\b/i;
+
+export function hasApxRegisterOperand(line) {
+ return APX_EGPR_OPERAND.test(line.text);
+}
+
// .map row: "<seg:off> <name> <VA 16 hex> [f] [i] <Lib:Object>". The
// Lib:Object field is always the trailing whitespace-delimited token: no
// object/library name in a linker map contains a space, decorated (mangled)
@@ -444,6 +519,20 @@ export function evaluateModule({ moduleName, disasmText, mapText }) {
}
ownedHits += 1;
const { owner, functionStart, functionEnd } = found;
+ // R7 sits AFTER ownership resolution and BEFORE the allowlist: after,
+ // so the map control (hits that resolve to no owner at all, R4) stays
+ // exactly as strict as it was and an artifact cannot be used to make an
+ // unusable map look fine; before, because "these bytes are not an
+ // instruction" comes logically ahead of "is this instruction guarded".
+ if (hasApxRegisterOperand(hit)) {
+ verdicts.push({
+ hit,
+ owner,
+ verdict: 'DECODE_ARTIFACT_APX',
+ reason: 'operands name an Intel APX register r16-r31, which MSVC does not emit for x64 (no /arch switch selects APX, and neither reviewed toolset emits it); these bytes are data the linear-sweep disassembler decoded as if they were code (a jump table, switch table or constant pool inside .text), not a compiled instruction. Not counted as unprotected. If a future MSVC toolset really starts emitting APX code, re-check this rule during the toolset review that WINDOWS_REVIEWED_LINKER_VERSIONS in verify-sidecar-isa.sh forces anyway',
+ });
+ continue;
+ }
if (isAllowlisted(owner)) {
verdicts.push({ hit, owner, verdict: 'ALLOWED_CRT' });
continue;
@@ -463,6 +552,7 @@ export function evaluateModule({ moduleName, disasmText, mapText }) {
symbolCount: symbols.length,
hitCount: hits.length,
ownedHitCount: ownedHits,
+ decodeArtifactCount: verdicts.filter((v) => v.verdict === 'DECODE_ARTIFACT_APX').length,
verdicts,
unprotected: verdicts.filter((v) => v.verdict === 'UNPROTECTED' || v.verdict === 'UNKNOWN_OWNER'),
};
@@ -527,6 +617,14 @@ function main(argv) {
for (const v of result.verdicts) {
process.stdout.write(`[win-isa-guard] ${formatVerdict(v)}\n`);
}
+ // R7: an artifact is a hit this guard decided NOT to judge, so it gets its
+ // own counted line rather than disappearing between the per-hit rows. A
+ // module that suddenly reports many of these is telling you the
+ // disassembler is sweeping over a lot of data, which is worth a look even
+ // though it is not a K1 regression.
+ if (result.decodeArtifactCount > 0) {
+ process.stdout.write(`[win-isa-guard] NOTE: ${result.moduleName}: ${result.decodeArtifactCount} hit(s) classified DECODE_ARTIFACT_APX (Intel APX register r16-r31 in the operands, i.e. data decoded as code) and therefore not judged as protected or unprotected; see hasApxRegisterOperand in win-isa-guard.mjs and lu-301/bau/isa-guard-apx.md\n`);
+ }
if (result.lineCount < minLines) {
process.stderr.write(`[win-isa-guard] FAIL: ${result.moduleName}: only ${result.lineCount} disassembled instruction line(s) were parsed out of the dumpbin/objdump output (need >= ${minLines}); this almost always means the parser did not recognise the disassembler's output format at all (wrong flags, an encoding surprise, a tool/output-format change) rather than a genuinely tiny binary, and a hitCount of 0 from a parser this broken is not proof of anything (review-waechter-windows.md N2)\n`);
diff --git a/scripts/win-isa-guard.test.mjs b/scripts/win-isa-guard.test.mjs
index f2c601ec..076868dc 100644
--- a/scripts/win-isa-guard.test.mjs
+++ b/scripts/win-isa-guard.test.mjs
@@ -16,6 +16,7 @@ import {
isVexEvexHit,
findOwner,
isAllowlisted,
+ hasApxRegisterOperand,
checkDominance,
evaluateModule,
} from './win-isa-guard.mjs';
@@ -186,6 +187,134 @@ test('fixture: fake-address-as-constant-own-code (Opus pattern F) MUST come out
assert.equal(result.verdicts[0].verdict, 'UNPROTECTED');
});
+test('R7: hasApxRegisterOperand matches r16-r31 in any operand position and nothing else', () => {
+ const apx = parseDisasmLines([
+ ' 0000000180097301: 62 51 04 CC 56 39 vorps zmm25{k4}{z},zmm15,zmmword ptr [r25]',
+ ' 00000001800DCADC: 62 02 05 00 00 08 vpshufb xmm16,xmm30,xmmword ptr [r25]',
+ ' 0000000180000010: 62 00 00 00 00 00 vmovups ymm0,ymmword ptr [rax+r31*8]',
+ ' 0000000180000020: 62 00 00 00 00 00 vmovd xmm0,r16d',
+ ' 0000000180000030: 62 00 00 00 00 00 vmovd xmm0,r31b',
+ ].join('\n'));
+ assert.equal(apx.length, 5);
+ for (const line of apx) {
+ assert.equal(hasApxRegisterOperand(line), true, `expected an APX register in: ${line.text}`);
+ }
+
+ const notApx = parseDisasmLines([
+ // Every AVX-512 spelling on its own is NOT evidence of a misdecode:
+ // MSVC does emit zmm, k-masks and {z} under /arch:AVX512.
+ ' 0000000180000040: 62 F1 6C C9 56 0C vorps zmm1{k1}{z},zmm2,zmmword ptr [rsp]',
+ ' 0000000180000050: 62 02 05 00 00 08 vpshufb xmm16,xmm30,xmmword ptr [rcx]',
+ // The legacy register file, including the r8-r15 names the regex must
+ // not over-reach into, and control/debug registers whose spelling ends
+ // in digits that would match without the leading word boundary.
+ ' 0000000180000060: C5 F9 6E D8 vmovd xmm3,eax',
+ ' 0000000180000070: C4 C2 71 46 C2 vpsravd xmm0,xmm1,xmm10',
+ ' 0000000180000080: C5 FA 6F 04 CF vmovdqu xmm0,xmmword ptr [rdi+r9*8]',
+ ' 0000000180000090: 0F 20 C1 mov rcx,cr16',
+ ' 00000001800000A0: 0F 21 C1 mov rcx,dr16',
+ ].join('\n'));
+ assert.equal(notApx.length, 7);
+ for (const line of notApx) {
+ assert.equal(hasApxRegisterOperand(line), false, `did not expect an APX register in: ${line.text}`);
+ }
+});
+
+test('R7 fixture: the CI line from mtmd.dll is DECODE_ARTIFACT_APX, a real zmm hit without APX registers stays UNPROTECTED', () => {
+ // Positive and negative in one module, on purpose: the whole point of R7
+ // is that it excuses the APX misdecode and NOTHING else, so the fixture
+ // has to show a genuine, unguarded AVX-512 instruction in the same
+ // own-code object still going red, and the module still failing.
+ const { disasmText, mapText } = loadFixture('apx-decode-artifact');
+ const result = evaluateModule({ moduleName: 'apx-decode-artifact', disasmText, mapText });
+ assert.equal(result.hitCount, 2);
+ assert.equal(result.ownedHitCount, 2, 'the artifact is still resolved to an owner, so the R4 map control stays as strict as before');
+ assert.equal(result.decodeArtifactCount, 1);
+
+ const [artifact, real] = result.verdicts;
+ assert.equal(artifact.verdict, 'DECODE_ARTIFACT_APX');
+ assert.equal(artifact.hit.addr, 0x180097301);
+ assert.equal(artifact.owner.name, '$LN4275');
+ assert.equal(artifact.owner.obj, 'clip.obj');
+ assert.match(artifact.hit.text, /zmmword ptr \[r25\]/);
+
+ assert.equal(real.verdict, 'UNPROTECTED');
+ assert.equal(real.owner.name, 'clip_own_avx512_kernel');
+ assert.equal(result.unprotected.length, 1, 'only the real hit is unprotected; the artifact must not be counted');
+ assert.equal(result.unprotected[0], real);
+});
+
+test('R7: no allowlist by file name, the decision reads the operands only', () => {
+ // The same two clip.obj hits under a different module and object name
+ // must get exactly the same verdicts: nothing in R7 keys on clip.obj or
+ // mtmd.dll, which is what keeps this from being an allowlist in disguise.
+ const { disasmText } = loadFixture('apx-decode-artifact');
+ const mapText = [
+ ' Static symbols',
+ '',
+ ' 0001:00000000 some_other_label 0000000180097300 f ggml-cpu.obj',
+ ' 0001:00000110 some_other_kernel 0000000180097410 f ggml-cpu.obj',
+ ' 0001:00000210 some_other_kernel_end 0000000180097510 f ggml-cpu.obj',
+ ' 0003:00000010 __isa_available 0000000180099898 MSVCRT:cpu_disp.obj',
+ ].join('\n');
+ const result = evaluateModule({ moduleName: 'renamed', disasmText, mapText });
+ assert.equal(result.verdicts[0].verdict, 'DECODE_ARTIFACT_APX');
+ assert.equal(result.verdicts[1].verdict, 'UNPROTECTED');
+});
+
+test('R7: the artifact is reported, not swallowed, and the CLI still exits 1 on the real hit next to it', () => {
+ const script = join(HERE, 'win-isa-guard.mjs');
+ const result = spawnSync(process.execPath, [
+ script, 'check', '--module', 'apx-decode-artifact', '--min-lines', '0',
+ '--disasm', join(FIXTURES, 'apx-decode-artifact.disasm.txt'),
+ '--map', join(FIXTURES, 'apx-decode-artifact.map.txt'),
+ ], { encoding: 'utf8' });
+ assert.equal(result.status, 1, `expected exit 1 (the second, real hit), got ${result.status}. stdout:\n${result.stdout}\nstderr:\n${result.stderr}`);
+ assert.match(result.stdout, /\[DECODE_ARTIFACT_APX\]/, 'the artifact appears as its own verdict class in the per-hit report');
+ assert.match(result.stdout, /NOTE: apx-decode-artifact: 1 hit\(s\) classified DECODE_ARTIFACT_APX/, 'and again as a counted summary line');
+ assert.match(result.stderr, /has 1 unprotected VEX\/EVEX instruction\(s\)/);
+});
+
+test('R7: a module whose ONLY hit is the APX artifact comes out green, with the artifact still on the record', () => {
+ // This is the mtmd.dll case as it will look on the next CI run: the one
+ // hit that made the release red is the misdecode, so the module passes,
+ // but the line and the count stay in the log.
+ const script = join(HERE, 'win-isa-guard.mjs');
+ const disasmOnlyArtifact = join(FIXTURES, '.tmp-apx-only.disasm.txt');
+ const mapOnlyArtifact = join(FIXTURES, '.tmp-apx-only.map.txt');
+ writeFileSync(disasmOnlyArtifact, [
+ ' 0000000180097301: 62 51 04 CC 56 39 vorps zmm25{k4}{z},zmm15,zmmword ptr [r25]',
+ ' 0000000180097307: C3 ret',
+ '',
+ ].join('\n'));
+ writeFileSync(mapOnlyArtifact, readFileSync(join(FIXTURES, 'apx-decode-artifact.map.txt'), 'utf8'));
+ try {
+ const result = spawnSync(process.execPath, [
+ script, 'check', '--module', 'mtmd.dll', '--min-lines', '0',
+ '--disasm', disasmOnlyArtifact, '--map', mapOnlyArtifact,
+ ], { encoding: 'utf8' });
+ assert.equal(result.status, 0, `expected exit 0, got ${result.status}. stdout:\n${result.stdout}\nstderr:\n${result.stderr}`);
+ assert.match(result.stdout, /\[DECODE_ARTIFACT_APX\]/);
+ assert.match(result.stdout, /NOTE: mtmd\.dll: 1 hit\(s\) classified DECODE_ARTIFACT_APX/);
+ assert.match(result.stdout, /OK: mtmd\.dll, no unprotected VEX\/EVEX in own code/);
+ } finally {
+ rmSync(disasmOnlyArtifact, { force: true });
+ rmSync(mapOnlyArtifact, { force: true });
+ }
+});
+
+test('R7 does not loosen the other fixtures: the red probe and both fake-green shapes stay red', () => {
+ // A guard rule that excuses a class of hit is exactly the kind of change
+ // that can quietly take the existing probes with it, so they are asserted
+ // again from here rather than only in their own tests above.
+ for (const name of ['unprotected-own-code', 'fake-unrelated-jump-own-code', 'fake-address-as-constant-own-code']) {
+ const { disasmText, mapText } = loadFixture(name);
+ const result = evaluateModule({ moduleName: name, disasmText, mapText });
+ assert.equal(result.decodeArtifactCount, 0, `${name} must not be touched by R7`);
+ assert.equal(result.unprotected.length, 1, `${name} must still be RED`);
+ }
+});
+
test('checkDominance: no isa symbol in the map at all is NOT protected', () => {
const lines = parseDisasmLines([
' 0000000180027F83: C4 C2 71 46 C2 vpsravd xmm0,xmm1,xmm10',