gdp-wired 0.55.1 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -186,6 +186,54 @@ laws from the clause's text, reads each over the code's names and prints the com
186
186
  `[unreviewed: drafted by ...]` until a person signs it (`[reviewed-by: <name>, <date>]`); `check --require-review`
187
187
  refuses a law cited unreviewed (`research/regulated/DESIGN.md`, `research/regulated/DRAFTING.md`).
188
188
 
189
+ For C files, opt-in Stage 1 memory and undefined-behavior safety checking (`// gdp: safety`, `--safety`, or
190
+ `extractC(file, {safety: true})`) proves absence of a first array/table-bounds, signed-overflow, or division/remainder
191
+ fault over the covered C subset, naming the exact functions covered (`coveredFunctions`) and compiler/target/standard/macro
192
+ configuration (`macroConfig`), re-checking every proof in the kernel (`verifyCSafetyProof`), and replaying every
193
+ `broken` obligation under Clang ASan/UBSan (`matchedSite`). It relies on four explicit premises (returned on every
194
+ result and documented in [docs/FRONTENDS.md](docs/FRONTENDS.md#opt-in-c-safety-stage-1)): (1) Clang resolved from a
195
+ fixed safe `PATH` to a verified native executable (custom `clang` options, scripts, wrapper binaries, external `.cfg`
196
+ files, and compiler flags outside `-I`/`-D`/`-U`/`-std=`/`-O*`/`-W*` are refused) running in a closed-world allowlisted
197
+ environment (`PATH`, `LC_ALL=C`, `TMPDIR` only) with 8/16/32-bit two's-complement ABI, covered scalar/table/fixed-array
198
+ types, and the reported target triple, compiler & absolute path, `libc` version (e.g. `glibc 2.39`), SHA-256 digest and
199
+ path list of every included user file (`userFilesSha256`/`userFiles`) and every included system header
200
+ (`systemHeadersSha256`/`systemHeaders`), C standard (`__STDC_VERSION__`/`std`),
201
+ `-I`/`-D` flags, and `NDEBUG`/`__OPTIMIZE__`/`DEBUG` status (same-UID concurrent processes are trusted and outside the
202
+ threat model, as a same-UID attacker could equally modify `gdp-wired` or Clang directly);
203
+ (2) sequential execution on one live zero-initialized receiver (or single-declaration file-local `static` globals) with
204
+ non-aliasing receiver and scalar out-parameters, no concurrency, and no external mutation from other translation units;
205
+ (3) mechanically checked translation-unit closure across all non-system files classified strictly by resolved path
206
+ under Clang's built-in search directories (never linemarker flag `3`, requiring both spelling and expansion locations to
207
+ be system files; **caveat**: headers under Clang's default search list — including `/usr/local/include` on Linux and
208
+ Homebrew directories such as `/opt/homebrew/include` on macOS — are trusted as system headers, with every included
209
+ system header's path and snapshot SHA-256 reported in `macroConfig`; the full include closure of both user files and
210
+ system headers is discovered by Clang `-E -H` on the original tree, resolved component-wise without collapsing `..`
211
+ before symlinks, verified via `O_NONBLOCK`/`O_NOFOLLOW` `fstat` as regular files — refusing case-insensitive
212
+ `/proc`/`/dev`/`/sys`, non-regular files/FIFOs, `-I` directories overlapping system directories, user-visible includes
213
+ resolving into system directories, absolute includes, and user includes outside the root/`-I` boundary — snapshotted
214
+ once into a private temp tree locked read-only (`0500` dirs, `0400` files) with `-nostdinc` and mapped `-I`/`-isystem`
215
+ dirs, cross-checked via Clang `-H` on every snapshot pass — preprocessor, AST, expanded tokens, alt-path/cwd/mtime/`SOURCE_DATE_EPOCH`
216
+ differentials, and build-mode alternates (which snapshot any extra variant system headers under `-nostdinc` and never
217
+ fall back to live system dirs) — for exact include-list and order equality, walked at the end to refuse any modified,
218
+ removed, or added files/dirs in the snapshot, digested from those snapshot bytes for both user and system files, and
219
+ re-hashed on disk at the end to refuse concurrent writers (modified or added files in the snapshot plus modified
220
+ original user/system files; same-UID concurrent processes remain outside the threat model); user-defined or `-D` macros expanded inside system
221
+ headers are refused; user files are audited from Clang's `-Xclang -dump-raw-tokens` (byte-contiguous from byte 0/BOM to
222
+ EOF with raw NUL bytes refused), `-Xclang -dump-tokens`, and `-E -H -dD`, refusing all 9 trigraphs and non-C23 digit-quote sequences outright,
223
+ allowing only user-defined or `-D` macros in `#if`/`#ifdef`/`#ifndef`/`#elif`/`defined()` and only `#pragma once`,
224
+ refusing predefined or undefined-elsewhere macros, `__has_*`, `_Pragma`, token pasting `##`, `<scratch space>`
225
+ expansions, invocation-dependent macros `__FILE__`/`__BASE_FILE__`/`__FILE_NAME__`/`__TIMESTAMP__`/`__DATE__`/`__TIME__`/
226
+ `__COUNTER__`/`__LINE__`/`__INCLUDE_LEVEL__`, `SourceLocExpr`/`PredefinedExpr`, and any `__builtin_*` identifier,
227
+ backed by differential checks
228
+ comparing both preprocessed tokens and folded AST facts (array sizes, constants, types) across alternate path/filename
229
+ length, file mtime, `SOURCE_DATE_EPOCH` days, distinct empty working directories with `stdin=/dev/null`, and `NDEBUG`/`-O0`/`-O2`/`-Os`/`-fsanitize=address,undefined`/`DEBUG`; every non-system
230
+ function body must be a selected method or inlined file-local `static` helper, or is refused as `unchecked` and named;
231
+ symbol aliases/weak/file-scope `__asm__`/attributed or post-definition function declarations, non-system globals with
232
+ pointers/fn-ptrs or function-referencing initializers, bodyless prototypes taking the entry type or pointers, and `fails`
233
+ returns after state writes are also refused; known limit: C safety refuses files including `<string.h>` in this release
234
+ due to glibc `__REDIRECT_NTH` macro expansion); and (4) first-fault monitor scope with site-matched ASan/UBSan replay
235
+ (abstract stutter on fault is a monitor convention, not native rollback).
236
+
189
237
  ## Where it fits
190
238
 
191
239
  <img src="https://raw.githubusercontent.com/monotykamary/gdp-wired/main/static/venn.svg" alt="What Lean, Bend and gdp-wired each cover, and where they overlap" width="640" />
@@ -1,4 +1,5 @@
1
1
  import type { GoPkg } from '../extract-go.js';
2
+ import { Refusal } from '../extract-read.js';
2
3
  type CN = {
3
4
  id?: string;
4
5
  kind: string;
@@ -7,6 +8,7 @@ type CN = {
7
8
  type?: {
8
9
  qualType: string;
9
10
  desugaredQualType?: string;
11
+ typeAliasDeclId?: string;
10
12
  };
11
13
  value?: string;
12
14
  opcode?: string;
@@ -22,6 +24,7 @@ type CN = {
22
24
  };
23
25
  };
24
26
  referencedMemberDecl?: string;
27
+ previousDecl?: string;
25
28
  storageClass?: string;
26
29
  isImplicit?: boolean;
27
30
  completeDefinition?: boolean;
@@ -31,6 +34,10 @@ type CN = {
31
34
  qualType: string;
32
35
  desugaredQualType?: string;
33
36
  };
37
+ computeResultType?: {
38
+ qualType: string;
39
+ desugaredQualType?: string;
40
+ };
34
41
  init?: string;
35
42
  decl?: {
36
43
  id: string;
@@ -44,6 +51,13 @@ type CN = {
44
51
  $at?: At;
45
52
  $b?: At;
46
53
  $e?: At;
54
+ $files?: Set<string>;
55
+ $macroExpansions?: {
56
+ spell: string;
57
+ spellLine: number;
58
+ expand: string;
59
+ expandLine: number;
60
+ }[];
47
61
  [k: string]: unknown;
48
62
  };
49
63
  type L = {
@@ -52,6 +66,8 @@ type L = {
52
66
  line?: number;
53
67
  col?: number;
54
68
  tokLen?: number;
69
+ presumedFile?: string;
70
+ presumedLine?: number;
55
71
  spellingLoc?: L;
56
72
  expansionLoc?: L;
57
73
  includedFrom?: unknown;
@@ -63,16 +79,53 @@ type At = {
63
79
  off: number;
64
80
  tok: number;
65
81
  };
82
+ export type CSafetyMacroConfig = {
83
+ target: string;
84
+ compiler?: string;
85
+ compilerPath?: string;
86
+ libc?: string;
87
+ userFilesSha256?: string;
88
+ userFiles?: readonly {
89
+ path: string;
90
+ sha256: string;
91
+ }[];
92
+ systemHeadersSha256?: string;
93
+ systemHeaders?: readonly {
94
+ path: string;
95
+ sha256: string;
96
+ }[];
97
+ std: string;
98
+ stdcVersion: string;
99
+ envScrubbed: boolean;
100
+ includeDirs: readonly string[];
101
+ flags: readonly string[];
102
+ defines: readonly string[];
103
+ ndebugDefined: boolean;
104
+ optimizeDefined: boolean;
105
+ debugDefined: boolean;
106
+ };
107
+ export type CSafetyClangMeta = {
108
+ systemFiles: Set<string>;
109
+ userFiles: Set<string>;
110
+ macroConfig: CSafetyMacroConfig;
111
+ snapshotBytes?: ReadonlyMap<string, Uint8Array>;
112
+ verifySnapshotUnchanged?: () => void;
113
+ };
66
114
  export type CTarget = {
67
115
  int: number;
68
116
  long: number;
69
117
  short: number;
70
118
  llong: number;
71
119
  charUnsigned: boolean;
120
+ charBits?: number;
121
+ safetyMeta?: CSafetyClangMeta;
72
122
  };
73
123
  export type CRead = {
74
124
  pkg: GoPkg;
75
125
  methods: string[];
126
+ helpers?: string[];
127
+ macroConfig?: CSafetyMacroConfig;
128
+ verifySnapshotUnchanged?: () => void;
76
129
  entry: string;
77
130
  cname: string;
78
131
  consts: Record<string, number>;
@@ -83,12 +136,31 @@ export type CRead = {
83
136
  externs: string[];
84
137
  };
85
138
  };
139
+ export declare class SafetyUncoveredRefusal extends Refusal {
140
+ readonly coveredFunctions: readonly string[];
141
+ readonly uncheckedFunctions: readonly string[];
142
+ readonly macroConfig?: CSafetyMacroConfig;
143
+ constructor(where: string, what: string, coveredFunctions: readonly string[], uncheckedFunctions: readonly string[], macroConfig?: CSafetyMacroConfig);
144
+ }
145
+ export declare const isSpecialVirtualPath: (p: string) => boolean;
86
146
  export declare const node: <T>(id: string) => T;
87
- export declare function clangDump(file: string, flags: string[], clang?: string, cpp?: boolean, filter?: string): {
147
+ export declare const SAFE_CLANG_DIRS: readonly ["/usr/bin", "/bin", "/usr/local/bin", "/opt/swift/usr/bin", "/opt/homebrew/bin", "/Library/Developer/CommandLineTools/usr/bin"];
148
+ export declare const SAFE_CLANG_PATH: string;
149
+ export declare function scrubbedClangEnv(extra?: Record<string, string>): Record<string, string>;
150
+ export declare function verifyClangBinary(clangPath: string, file: string): {
151
+ bin: string;
152
+ cc1Real: string;
153
+ };
154
+ export declare function resolveSafetyClang(requestedClang: string, file: string): {
155
+ bin: string;
156
+ cc1Real: string;
157
+ };
158
+ export declare function cleanupCSafetySnapshots(): void;
159
+ export declare function clangDump(file: string, flags: string[], clang?: string, cpp?: boolean, filter?: string, safety?: boolean, root?: string): {
88
160
  tu: CN;
89
161
  target: CTarget;
90
162
  };
91
163
  export declare function constantsOf(file: string, flags: string[], clang: string, cpp: boolean, names: string[]): Record<string, number>;
92
164
  export declare function flagsFor(file: string, compileCommands?: string): string[];
93
- export declare function readC(file: string, entry: string, tu: CN, target: CTarget, cpp?: boolean, root?: string, picks?: Record<string, number>, pickNames?: string[], leave?: string[], cut?: string[]): CRead;
165
+ export declare function readC(file: string, entry: string, tu: CN, target: CTarget, cpp?: boolean, root?: string, picks?: Record<string, number>, pickNames?: string[], leave?: string[], cut?: string[], safety?: boolean): CRead;
94
166
  export {};