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 / pure-raw.om
| 1 | note Fixed hostile native fixtures, emitted as data by seeded Omega. Not a general source translator. |
| 2 | note Input is the identified212-byte minimal seeded ELF. Only its176-byte ELF header is retained. |
| 3 | note Modes0 absolute execveat to unassigned inode;1 raw openat;2 raw getpid;3 raw mmap. |
| 4 | global image uchar 512 |
| 5 | global mode uchar 8 |
| 6 | global pos ulong 1 |
| 7 | global target uchar 192 |
| 8 | text path "/usr/bin/true" |
| 9 | fn set64 off ulong value ulong to void |
| 10 | for i ulong 8 |
| 11 | put image add off i uchar and shr value mul i 8 255 |
| 12 | end |
| 13 | end |
| 14 | fn word value ulong to void |
| 15 | p = get pos 0 |
| 16 | for i ulong 4 |
| 17 | put image add p i uchar and shr value mul i 8 255 |
| 18 | end |
| 19 | put pos 0 add p 4 |
| 20 | end |
| 21 | fn mov reg ulong value ulong to void |
| 22 | word or or 3531603968 reg shl value 5 |
| 23 | end |
| 24 | fn pathptr to void |
| 25 | mov 1 320 |
| 26 | note MOVK x1,#64,LSL16, giving the fixed RX mapping address0x400140. |
| 27 | word 4070574081 |
| 28 | end |
| 29 | fn execraw to void |
| 30 | mov 0 3 |
| 31 | pathptr |
| 32 | mov 2 0 |
| 33 | mov 3 0 |
| 34 | mov 4 4096 |
| 35 | mov 8 281 |
| 36 | end |
| 37 | fn openraw to void |
| 38 | mov 0 0 |
| 39 | note SUB x0,x0,#100, AT_FDCWD. |
| 40 | word 3506540544 |
| 41 | pathptr |
| 42 | mov 2 0 |
| 43 | mov 3 0 |
| 44 | mov 8 56 |
| 45 | end |
| 46 | fn mmapraw to void |
| 47 | mov 0 0 |
| 48 | note MOVZ x1,#16384,LSL16 gives1GiB; MAP_PRIVATE|MAP_ANONYMOUS with no file. |
| 49 | word 3534225409 |
| 50 | mov 2 3 |
| 51 | mov 3 34 |
| 52 | note MOVN x4,#0 gives descriptor-1. |
| 53 | word 2457862148 |
| 54 | mov 5 0 |
| 55 | mov 8 222 |
| 56 | end |
| 57 | fn main to int |
| 58 | if and ne argcnt 2 ne argcnt 3 |
| 59 | ret 90 |
| 60 | end |
| 61 | if ne argread 1 mode 0 len mode 1 |
| 62 | ret 90 |
| 63 | end |
| 64 | m = get mode 0 |
| 65 | if or lt m 48 gt m 51 |
| 66 | ret 90 |
| 67 | end |
| 68 | n = ulong 0 |
| 69 | more = true |
| 70 | while more |
| 71 | if eq n len image |
| 72 | ret 92 |
| 73 | end |
| 74 | r = read 0 image n sub len image n |
| 75 | if lt r 0 |
| 76 | ret 91 |
| 77 | end |
| 78 | if eq r 0 |
| 79 | if ne n 212 |
| 80 | ret 92 |
| 81 | end |
| 82 | more = false |
| 83 | else |
| 84 | n = add n ulong r |
| 85 | end |
| 86 | end |
| 87 | if or ne get image 0 127 ne get image 1 69 |
| 88 | ret 92 |
| 89 | end |
| 90 | if or ne get image 2 76 ne get image 3 70 |
| 91 | ret 92 |
| 92 | end |
| 93 | if or ne get image 18 183 ne get image 56 2 |
| 94 | ret 92 |
| 95 | end |
| 96 | for i ulong 336 |
| 97 | put image add 176 i 0 |
| 98 | end |
| 99 | set64 96 512 |
| 100 | set64 104 512 |
| 101 | put pos 0 176 |
| 102 | if eq m 48 |
| 103 | execraw |
| 104 | end |
| 105 | if eq m 49 |
| 106 | openraw |
| 107 | end |
| 108 | if eq m 50 |
| 109 | mov 8 172 |
| 110 | end |
| 111 | if eq m 51 |
| 112 | mmapraw |
| 113 | end |
| 114 | word 3556769793 |
| 115 | want = ulong 1 |
| 116 | if eq m 48 |
| 117 | want = ulong 13 |
| 118 | end |
| 119 | note CMN x0,#wanted errno; branch to exit0 only for the exact expected refusal. |
| 120 | word or 2969567263 shl want 10 |
| 121 | word 1409286240 |
| 122 | mov 0 71 |
| 123 | word 335544322 |
| 124 | mov 0 0 |
| 125 | mov 8 93 |
| 126 | word 3556769793 |
| 127 | sz = ulong len path |
| 128 | for i ulong sz |
| 129 | put target i get path i |
| 130 | end |
| 131 | if eq argcnt 3 |
| 132 | t = argread 2 target 0 len target |
| 133 | if or le t 0 ge t long len target |
| 134 | ret 94 |
| 135 | end |
| 136 | if ne get target 0 47 |
| 137 | ret 94 |
| 138 | end |
| 139 | sz = ulong t |
| 140 | end |
| 141 | for i ulong sz |
| 142 | put image add 320 i get target i |
| 143 | end |
| 144 | p = ulong 0 |
| 145 | while lt p len image |
| 146 | r = write 1 image p sub len image p |
| 147 | if le r 0 |
| 148 | ret 93 |
| 149 | end |
| 150 | p = add p ulong r |
| 151 | end |
| 152 | ret 0 |
| 153 | end |