omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / qualification / security673 / exec-parent.om
| 1 | note Disposable integration parent. No private input, network, devices, or external service. |
| 2 | note Modes0 success,1 missing executable,2 isolate high-descriptor leak,3 unavailable-kernel mutant. |
| 3 | note Parent retains its own descriptor table; this is not a sandbox or resource-fencing test. |
| 4 | text secret "synthetic-secret" |
| 5 | text public "public-input" |
| 6 | text answer "public-output" |
| 7 | text name "synthetic-secret.data" |
| 8 | text child "./exec-child" |
| 9 | text absent "./no-such-executable" |
| 10 | global packet uchar 4096 |
| 11 | global bytes uchar 64 |
| 12 | global fds uchar 8 |
| 13 | global status uchar 4 |
| 14 | global mode uchar 1 |
| 15 | fn fdword off ulong to int |
| 16 | x = ulong 0 |
| 17 | for i ulong 4 |
| 18 | x = or x shl ulong get fds add off i mul i 8 |
| 19 | end |
| 20 | ret int x |
| 21 | end |
| 22 | fn addpath missing bool to ulong |
| 23 | put packet 0 1 |
| 24 | if missing |
| 25 | put packet 2 uchar len absent |
| 26 | for i ulong len absent |
| 27 | put packet add i 4 get absent i |
| 28 | end |
| 29 | ret add 4 len absent |
| 30 | end |
| 31 | put packet 2 uchar len child |
| 32 | for i ulong len child |
| 33 | put packet add i 4 get child i |
| 34 | end |
| 35 | ret add 4 len child |
| 36 | end |
| 37 | fn childrun rd int wr int missing bool to int |
| 38 | if ne dupfd rd 0 0 0 |
| 39 | ret 51 |
| 40 | end |
| 41 | if ne dupfd wr 1 0 1 |
| 42 | ret 52 |
| 43 | end |
| 44 | if eq get mode 0 2 |
| 45 | if ne fclose 3 0 |
| 46 | ret 57 |
| 47 | end |
| 48 | end |
| 49 | n = addpath missing |
| 50 | r = execprog packet 0 n |
| 51 | if eq get mode 0 3 |
| 52 | if ne r neg long 38 |
| 53 | ret 58 |
| 54 | end |
| 55 | ret 0 |
| 56 | end |
| 57 | if not missing |
| 58 | ret 53 |
| 59 | end |
| 60 | if ne r neg long 2 |
| 61 | ret 54 |
| 62 | end |
| 63 | if ne read 3 bytes 0 1 neg long 9 |
| 64 | ret 55 |
| 65 | end |
| 66 | if ne read 65537 bytes 0 1 neg long 9 |
| 67 | ret 56 |
| 68 | end |
| 69 | ret 0 |
| 70 | end |
| 71 | fn parent pid long inputfd int outputfd int fd int missing bool to int |
| 72 | if ne fclose inputfd 0 |
| 73 | ret 61 |
| 74 | end |
| 75 | if ne fclose outputfd 0 |
| 76 | ret 62 |
| 77 | end |
| 78 | if ne waitpid int pid status 0 len status 0 pid |
| 79 | ret 63 |
| 80 | end |
| 81 | if ne get status 0 0 |
| 82 | ret 64 |
| 83 | end |
| 84 | if ne get status 1 0 |
| 85 | ret int get status 1 |
| 86 | end |
| 87 | if ne fseek fd 0 0 0 |
| 88 | ret 65 |
| 89 | end |
| 90 | if ne read fd bytes 0 len secret long len secret |
| 91 | ret 66 |
| 92 | end |
| 93 | for i ulong len secret |
| 94 | if ne get bytes i get secret i |
| 95 | ret 67 |
| 96 | end |
| 97 | end |
| 98 | ret 0 |
| 99 | end |
| 100 | fn main to int |
| 101 | if ne read 0 mode 0 1 1 |
| 102 | ret 90 |
| 103 | end |
| 104 | if gt get mode 0 3 |
| 105 | ret 90 |
| 106 | end |
| 107 | missing = eq get mode 0 1 |
| 108 | fd = fopen name 0 len name 194 384 |
| 109 | if lt fd 0 |
| 110 | ret 1 |
| 111 | end |
| 112 | if ne fd 3 |
| 113 | ret 2 |
| 114 | end |
| 115 | if ne write int fd secret 0 len secret long len secret |
| 116 | ret 3 |
| 117 | end |
| 118 | if ne fseek int fd 0 0 0 |
| 119 | ret 4 |
| 120 | end |
| 121 | if ne dupfd int fd 65537 0 65537 |
| 122 | ret 5 |
| 123 | end |
| 124 | if ne pipefds fds 0 len fds 0 0 |
| 125 | ret 6 |
| 126 | end |
| 127 | rd = fdword 0 |
| 128 | wr = fdword 4 |
| 129 | if ne write wr public 0 len public long len public |
| 130 | ret 7 |
| 131 | end |
| 132 | if ne fclose wr 0 |
| 133 | ret 8 |
| 134 | end |
| 135 | if ne pipefds fds 0 len fds 0 0 |
| 136 | ret 9 |
| 137 | end |
| 138 | outread = fdword 0 |
| 139 | outwrite = fdword 4 |
| 140 | pid = fork |
| 141 | if lt pid 0 |
| 142 | ret 10 |
| 143 | end |
| 144 | if eq pid 0 |
| 145 | ret childrun rd outwrite missing |
| 146 | end |
| 147 | rc = parent pid rd outwrite int fd missing |
| 148 | if ne rc 0 |
| 149 | ret rc |
| 150 | end |
| 151 | n = read outread bytes 0 len bytes |
| 152 | if or missing eq get mode 0 3 |
| 153 | if ne n 0 |
| 154 | ret 70 |
| 155 | end |
| 156 | else |
| 157 | if ne n long len answer |
| 158 | ret 71 |
| 159 | end |
| 160 | for i ulong len answer |
| 161 | if ne get bytes i get answer i |
| 162 | ret 72 |
| 163 | end |
| 164 | end |
| 165 | end |
| 166 | if ne fclose outread 0 |
| 167 | ret 73 |
| 168 | end |
| 169 | if ne fclose 65537 0 |
| 170 | ret 74 |
| 171 | end |
| 172 | if ne fclose int fd 0 |
| 173 | ret 75 |
| 174 | end |
| 175 | ret 0 |
| 176 | end |