Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/salvage/10verify.om # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / salvage / 10verify.om` 669 lines ยท 12724 bytes Raw Blame History 1 note Collector: pinned compiler in an empty bwrap namespace, then execpure for the declared example. 2 note No uploaded file is ever executed outside execpure. All command arguments are length-prefixed. 3 text tlwork "work/" 4 text tljlock "collector.lock" 5 text tlccenv "OMEGA_COMPILER=" 6 global glccpath uchar 1024 7 global glccn ulong 1 8 text tlcc "omc" 9 text tlcode "source.om" 10 text tlbin "part.elf" 11 text tlbuilt "compiler.out" 12 text tlin "stdin" 13 text tlout "stdout" 14 text tlerr "stderr" 15 text tlprlim "/usr/bin/prlimit" 16 text tlbw "/usr/bin/bwrap" 17 text tlaas "--as=`268435456`" 18 text tlacpu "--cpu=2" 19 text tlafsz "--fsize=`8388608`" 20 text tladash "--" 21 text tlunsh "--unshare-all" 22 text tldie "--die-with-parent" 23 text tlnew "--new-session" 24 text tlcaps "--cap-drop" 25 text tlall "ALL" 26 text tlbind "--ro-bind" 27 text tlinside "/omc" 28 text tlpol "salvage-example-v1:bwrap-compile:execpure-run:3s-wall:4096-byte-output" 29 global glpk uchar 8192 30 global glpkn ulong 1 31 global glpkc ulong 1 32 global glphase ulong 1 33 global glstatus uchar 4 34 note The scratch root. Inside the server's own process (tests, replay) it is work/. The 35 note collector program sets one outside the store: the sandboxed server can write everything in 36 note the store, and scratch files are compiled and executed, so they must be out of its reach. 37 global glwroot uchar 512 38 global glwrootn ulong 1 39 note slwroot: an absolute path ending in /, no control bytes, no segment starting with a dot 40 fn slwroot d view uchar * to bool 41 if or lt len d 2 gt len d 500 42 ret false 43 end 44 if or ne get d 0 47 ne get d sub len d 1 47 45 ret false 46 end 47 for i ulong len d bound 512 48 c = get d i 49 if or lt c 32 eq c 127 50 ret false 51 end 52 if gt i 0 53 if and eq c 46 eq get d sub i 1 47 54 ret false 55 end 56 end 57 put glwroot i c 58 end 59 put glwrootn 0 len d 60 ret true 61 end 62 fn slwpath name view uchar * to void 63 n = get glwrootn 0 64 if eq n 0 65 slpath tlwork name 66 ret 67 end 68 for i ulong n bound 512 69 put glpath i get glwroot i 70 end 71 for i ulong len name bound 128 72 put glpath add n i get name i 73 end 74 put glpathn 0 add n len name 75 end 76 note slwmk: the scratch folder exists and is a private 0700 directory 77 fn slwmk to bool 78 if eq get glwrootn 0 0 79 ret slmkdir tlwork 80 end 81 r = makedir glwroot 0 get glwrootn 0 448 82 if not or eq r 0 eq r -17 83 ret false 84 end 85 fd = fopen glwroot 0 get glwrootn 0 573440 0 86 if lt fd 0 87 ret false 88 end 89 ok = slprivate int fd 90 x = fclose int fd 91 ret ok 92 end 93 fn slpknew to void 94 put glpkn 0 2 95 put glpkc 0 0 96 end 97 fn slpkadd s view uchar * to void 98 n = get glpkn 0 99 put glpk n uchar and len s 255 100 put glpk add n 1 uchar shr len s 8 101 for i ulong len s bound 1024 102 put glpk add add n 2 i get s i 103 end 104 put glpkn 0 add add n 2 len s 105 put glpkc 0 add get glpkc 0 1 106 put glpk 0 uchar get glpkc 0 107 end 108 fn slpkpath name view uchar * to void 109 p = new uchar 1024 0 110 slwpath name 111 n = slpget p 112 slpkadd view part p 0 n 113 end 114 fn slunlink name view uchar * to void 115 slwpath name 116 r = unlink glpath 0 get glpathn 0 117 end 118 fn slwput name view uchar * data view uchar * to bool 119 p = new uchar 1024 0 120 slunlink name 121 slwpath name 122 n = slpget p 123 ret slwrite view part p 0 n data 557249 124 end 125 fn slwfield name view uchar * fld ulong to bool 126 b = new uchar 16384 0 127 n = slfield fld b 128 ret slwput name view part b 0 n 129 end 130 fn sltohex h view uchar * dst edit uchar * to void 131 for i ulong 32 132 put dst mul i 2 get tlhex ulong shr get h i 4 133 put dst add mul i 2 1 get tlhex ulong and get h i 15 134 end 135 end 136 fn slfilehash path view uchar * dst edit uchar * to bool 137 b = new uchar 65536 0 138 c = new ulong 40 0 139 h = new uchar 32 0 140 fd = fopen path 0 len path 557056 0 141 if lt fd 0 142 ret false 143 end 144 sha256_init c 145 ok = false 146 for i ulong 129 147 r = read int fd b 0 65536 148 if eq r 0 149 ok = true 150 break 151 end 152 if lt r 0 153 break 154 end 155 sha256_update c view part b 0 ulong r 156 end 157 x = fclose int fd 158 if not ok 159 ret false 160 end 161 sha256_final c h 162 sltohex h dst 163 ret true 164 end 165 fn slccconfig to bool 166 b = new uchar 2048 0 167 put glccn 0 0 168 for i ulong ulong envcnt bound 4096 169 n = envread i b 0 2048 170 if gt n long len tlccenv 171 same = true 172 for j ulong len tlccenv 173 if ne get b j get tlccenv j 174 same = false 175 end 176 end 177 if same 178 sz = sub ulong n len tlccenv 179 if gt sz 1024 180 ret false 181 end 182 if ne get b len tlccenv 47 183 ret false 184 end 185 for j ulong sz bound 1024 186 c = get b add len tlccenv j 187 if or lt c 32 eq c 127 188 ret false 189 end 190 put glccpath j c 191 end 192 put glccn 0 sz 193 ret true 194 end 195 end 196 end 197 ret false 198 end 199 fn slpincc to bool 200 b = new uchar 65536 0 201 p = new uchar 1024 0 202 h = new uchar 64 0 203 if not slccconfig 204 ret false 205 end 206 slunlink tlcc 207 slwpath tlcc 208 n = slpget p 209 src = fopen glccpath 0 get glccn 0 557056 0 210 if lt src 0 211 ret false 212 end 213 dst = fopen p 0 n 557249 384 214 if lt dst 0 215 x = fclose int src 216 ret false 217 end 218 ok = false 219 for i ulong 129 220 r = read int src b 0 65536 221 if eq r 0 222 ok = true 223 break 224 end 225 if lt r 0 226 break 227 end 228 w = ulong 0 229 for j ulong 65536 230 if ge w ulong r 231 break 232 end 233 v = write int dst b w sub ulong r w 234 if le v 0 235 break 236 end 237 w = add w ulong v 238 end 239 if ne w ulong r 240 break 241 end 242 end 243 x = fclose int src 244 r = fsync int dst 245 z = fchmod int dst 320 246 x = fclose int dst 247 if not and and ok eq r 0 eq z 0 248 ret false 249 end 250 if not slfilehash view part p 0 n h 251 ret false 252 end 253 ret sleq h tlpin 254 end 255 fn slcompilepk to void 256 slpknew 257 slpkadd tlprlim 258 slpkadd tlaas 259 slpkadd tlacpu 260 slpkadd tlafsz 261 slpkadd tladash 262 slpkadd tlbw 263 slpkadd tlunsh 264 slpkadd tldie 265 slpkadd tlnew 266 slpkadd tlcaps 267 slpkadd tlall 268 slpkadd tlbind 269 slpkpath tlcc 270 slpkadd tlinside 271 slpkadd tladash 272 slpkadd tlinside 273 end 274 fn slchild inf view uchar * outf view uchar * pure bool to void 275 pk = new uchar 8192 0 276 r = setpgid 0 0 277 slwpath inf 278 fd = fopen glpath 0 get glpathn 0 557056 0 279 if lt fd 0 280 exit 121 281 end 282 r = dupfd int fd 0 0 283 x = fclose int fd 284 if lt r 0 285 exit 122 286 end 287 slunlink outf 288 slwpath outf 289 fd = fopen glpath 0 get glpathn 0 557249 384 290 if lt fd 0 291 exit 123 292 end 293 r = dupfd int fd 1 0 294 x = fclose int fd 295 if lt r 0 296 exit 124 297 end 298 slunlink tlerr 299 slwpath tlerr 300 fd = fopen glpath 0 get glpathn 0 557249 384 301 if lt fd 0 302 exit 125 303 end 304 r = dupfd int fd 2 0 305 x = fclose int fd 306 if lt r 0 307 exit 126 308 end 309 n = get glpkn 0 310 for i ulong n bound 8192 311 put pk i get glpk i 312 end 313 if pure 314 r = execpure pk 0 n 315 else 316 r = execprog pk 0 n 317 end 318 if lt r 0 319 exit int neg r 320 end 321 exit 127 322 end 323 fn slrun inf view uchar * outf view uchar * pure bool to bool 324 st = new uchar 4 0 325 pid = fork 326 if lt pid 0 327 ret false 328 end 329 if eq pid 0 330 slchild inf outf pure 331 exit 127 332 end 333 r = setpgid int pid int pid 334 ok = false 335 for i ulong 300 336 r = waitpid int pid st 0 4 1 337 if eq r pid 338 ok = true 339 break 340 end 341 if lt r 0 342 break 343 end 344 r = sleepns `10000000` 345 end 346 if not ok 347 r = killpid int neg pid 9 348 r = killpid int pid 9 349 for i ulong 100 350 r = waitpid int pid st 0 4 1 351 if ne r 0 352 break 353 end 354 r = sleepns `10000000` 355 end 356 ret false 357 end 358 for i ulong 4 359 put glstatus i get st i 360 end 361 for i ulong 4 362 if ne get st i 0 363 ret false 364 end 365 end 366 ret true 367 end 368 note Linux ETXTBSY was observed at this boundary. The outstanding natural writer was not identified. 369 note Copy completed compiler output to a new inode before execution. No compiler process inherited 370 note this inode or its write descriptor. Retrying exec or sleeping would not establish that property. 371 fn slfdwrite fd int data view uchar * to bool 372 n = ulong 0 373 for i ulong 65536 374 if ge n len data 375 ret true 376 end 377 r = write fd data n sub len data n 378 if le r 0 379 ret false 380 end 381 n = add n ulong r 382 end 383 ret eq n len data 384 end 385 fn slseal to bool 386 b = new uchar 65536 0 387 slwpath tlbuilt 388 src = fopen glpath 0 get glpathn 0 557056 0 389 if lt src 0 390 ret false 391 end 392 slunlink tlbin 393 slwpath tlbin 394 dst = fopen glpath 0 get glpathn 0 557249 384 395 if lt dst 0 396 x = fclose int src 397 ret false 398 end 399 ok = false 400 for i ulong 129 401 r = read int src b 0 65536 402 if eq r 0 403 ok = true 404 break 405 end 406 if lt r 0 407 break 408 end 409 if not slfdwrite int dst view part b 0 ulong r 410 break 411 end 412 end 413 x = fclose int src 414 r = fsync int dst 415 mode = fchmod int dst 320 416 x = fclose int dst 417 ret and and ok eq r 0 eq mode 0 418 end 419 fn slcheckex to bool 420 b = new uchar 4097 0 421 e = new uchar 4096 0 422 slwpath tlout 423 n = slpread b 424 en = slfield 8 e 425 if or lt n 0 gt n 4096 426 ret false 427 end 428 if not sleq view part b 0 ulong n view part e 0 en 429 ret false 430 end 431 note Negative control changes the declared expected bytes; it must fail the same exact-byte comparator. 432 if eq en 0 433 put e 0 88 434 ret not sleq view part b 0 ulong n view part e 0 1 435 end 436 put e 0 xor get e 0 1 437 ret not sleq view part b 0 ulong n view part e 0 en 438 end 439 fn slverify to bool 440 put glphase 0 1 441 if ne get glrec 8 2 442 ret false 443 end 444 if not slwmk 445 ret false 446 end 447 if not slpincc 448 ret false 449 end 450 if not slwfield tlcode 5 451 ret false 452 end 453 if not slwfield tlin 7 454 ret false 455 end 456 put glphase 0 2 457 slcompilepk 458 if not slrun tlcode tlbuilt false 459 ret false 460 end 461 if not slseal 462 ret false 463 end 464 put glphase 0 3 465 slpknew 466 slpkpath tlbin 467 if not slrun tlin tlout true 468 ret false 469 end 470 put glphase 0 4 471 ret slcheckex 472 end 473 global glrcpt uchar 353 474 fn slrh fld ulong name view uchar * to bool 475 p = new uchar 1024 0 476 h = new uchar 64 0 477 slwpath name 478 n = slpget p 479 if not slfilehash view part p 0 n h 480 ret false 481 end 482 for i ulong 64 483 put glrcpt add fld i get h i 484 end 485 ret true 486 end 487 fn slreceipt id view uchar * ok bool to bool 488 b = new uchar 353 0 489 h = new uchar 64 0 490 m = new uchar 32 0 491 for i ulong 353 492 put glrcpt i 0 493 end 494 for i ulong 64 495 put glrcpt i get id i 496 put glrcpt add i 193 get tlpin i 497 end 498 put glrcpt 64 2 499 put glrcpt 65 uchar get glphase 0 500 put glrcpt 66 get glstatus 1 501 put glrcpt 67 get glstatus 0 502 if ok 503 if not slrh 65 tlbin 504 ret false 505 end 506 if not slrh 129 tlout 507 ret false 508 end 509 put glrcpt 64 1 510 end 511 slhash tlpol h 512 for i ulong 64 513 put glrcpt add i 257 get h i 514 end 515 for i ulong 321 516 put b i get glrcpt i 517 end 518 slmac view part b 0 321 m 519 for i ulong 32 520 put b add i 321 get m i 521 end 522 slpath tlrece id 523 ret slpatom b 524 end 525 fn slreceiptget id view uchar * to ulong 526 b = new uchar 354 0 527 m = new uchar 32 0 528 h = new uchar 64 0 529 slpath tlrece id 530 n = slpread b 531 if eq n -2 532 ret 0 533 end 534 if ne n 353 535 ret 9 536 end 537 slmac view part b 0 321 m 538 if not sleq view part b 321 32 m 539 ret 9 540 end 541 if not sleq view part b 0 64 id 542 ret 9 543 end 544 if not sleq view part b 193 64 tlpin 545 ret 9 546 end 547 slhash tlpol h 548 if not sleq view part b 257 64 h 549 ret 9 550 end 551 if or lt get b 64 1 gt get b 64 2 552 ret 9 553 end 554 for i ulong 353 555 put glrcpt i get b i 556 end 557 ret ulong get b 64 558 end 559 note ---- the verification job. The server never compiles or runs a submission: the live forged 560 note runs in a namespace with no compiler, no bwrap and nested namespaces disabled. It only queues 561 note one job, the file job holding the 64-character record id. The collector, its own program 562 note (salvage/collector.om) outside that namespace, takes the job, verifies, writes the receipt and 563 note removes the file. One job at a time: while the file exists every other request is "busy". 564 text tljob "job" 565 note sljobpoll: kept for the route. The server holds no child, so there is nothing to reap. 566 fn sljobpoll to void 567 ret 568 end 569 note sljobid: the queued record id into dst. False when no job, or the file is not 64 hex characters. 570 fn sljobid dst edit uchar * to bool 571 p = new uchar 1024 0 572 b = new uchar 64 0 573 slpath tlempty tljob 574 n = slpget p 575 r = slread view part p 0 n b 576 if ne r 64 577 ret false 578 end 579 if not slhex b 580 ret false 581 end 582 for i ulong 64 583 put dst i get b i 584 end 585 ret true 586 end 587 note sljobstart: queue the job. The id is written and synced under job.next, then renamed to 588 note job with RENAME_NOREPLACE: the collector never sees a job file that exists before its 64 589 note bytes are written (it removes a short one as damaged), and a queued job refuses the next one. 590 fn sljobstart id view uchar * to bool 591 p = new uchar 1024 0 592 t = new uchar 1100 0 593 if not slhex id 594 ret false 595 end 596 slpath tlempty tljob 597 n = slpget p 598 for i ulong n bound 1024 599 put t i get p i 600 end 601 for i ulong len tlnext 602 put t add n i get tlnext i 603 end 604 m = add n len tlnext 605 r = unlink t 0 m 606 if not slwrite view part t 0 m id 557249 607 r = unlink t 0 m 608 ret false 609 end 610 if not slrename view part t 0 m view part p 0 n 1 611 r = unlink t 0 m 612 ret false 613 end 614 ret slsync view part p 0 n 615 end 616 note sljobdrop: remove the job file 617 fn sljobdrop to void 618 p = new uchar 1024 0 619 slpath tlempty tljob 620 n = slpget p 621 r = unlink p 0 n 622 end 623 note slcollect: one pass of the collector. 0 nothing queued; 1 the job got its receipt; 2 the job 624 note ended without a saved receipt, or another collector holds the lock. A job file that is not a 625 note record id is removed (2), so a damaged file cannot hold the queue for ever. 626 note The collector lock is held through verification, receipt and cleanup. 627 fn slcollect to ulong 628 id = new uchar 64 0 629 p = new uchar 1024 0 630 b = new uchar 65 0 631 if not sljobid id 632 slpath tlempty tljob 633 n = slpget p 634 r = slread view part p 0 n b 635 if eq r -2 636 ret 0 637 end 638 sljobdrop 639 ret 2 640 end 641 slpath tlempty tljlock 642 lockfd = fopen glpath 0 get glpathn 0 557122 384 643 if lt lockfd 0 644 ret 2 645 end 646 locked = flock int lockfd 6 647 if ne locked 0 648 x = fclose int lockfd 649 ret 2 650 end 651 ok = slload id 652 if ok 653 ok = slverify 654 end 655 saved = slreceipt id ok 656 slunlink tlcc 657 slunlink tlbuilt 658 slunlink tlbin 659 slunlink tlcode 660 slunlink tlin 661 slunlink tlout 662 slunlink tlerr 663 sljobdrop 664 x = fclose int lockfd 665 if not saved 666 ret 2 667 end 668 ret 1 669 end