Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix amfi_ret jump offset computing #6

Open
wants to merge 77 commits into
base: iOS15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5d0ec74
chore: change all #import's to #include's
asdfugil Jun 12, 2023
fa27a13
chore: Use -Wno-strict-prototypes
asdfugil Jun 12, 2023
a156fee
kpf: replace kerninfo and other flags with paleinfo
asdfugil Jun 12, 2023
ed9ab07
kpf: jbinit2 compatibility
asdfugil Jul 7, 2023
c1eb648
kpf: fix mac_mount on iOS 16.4+
kok3shidoll Jun 12, 2023
d834969
kpf: add rootful APFS patches
plooshi Jun 12, 2023
7ae51b5
kpf: shellcode: dyld: change patched dyld path to /cores/dyld
asdfugil Jun 12, 2023
349cc79
Add proc_selfname patch
kok3shidoll Jun 12, 2023
75e9178
feat: checkra1n pride
kok3shidoll Jun 12, 2023
da64c80
chore: fix GitHub Actions
plooshi Jun 12, 2023
4878939
actions: fix sftp authentication
asdfugil Jul 8, 2023
b52ef78
ci: remove DEV_BUILD=1
khcrysalis Jul 17, 2023
0556e90
fixed problem with apfs_vfsop_mount patch not working on ios 17.
kok3shidoll Jul 17, 2023
0a53690
ci: compile newest pongo in actions
khcrysalis Jul 17, 2023
69050ac
ci: move to macos (I hate linux)
khcrysalis Jul 17, 2023
481ce2c
Mark apfs_vfsop_mount as not required on xnu 10002
asdfugil Jul 25, 2023
1b31088
Always run apfs_vfsop_mount on non-test DEV_BUILD's
asdfugil Jul 25, 2023
df604e4
ci: have different artifacts per branch
kok3shidoll Jul 27, 2023
11be43e
kpf-test for linux arm64
asdfugil Jul 27, 2023
6e67b72
vmacho.c should include inttypes.h
asdfugil Jul 27, 2023
d19792c
actions: compile kpf-test.linux
asdfugil Jul 27, 2023
9e757f3
actions: Actually test KPF
asdfugil Jul 27, 2023
ae7d6d6
kpf-test: Make panic work properly on linux
asdfugil Jul 27, 2023
07ce18d
kpf: shellcode: set CS_DEBUGGED
asdfugil Sep 5, 2023
0922d95
Fix APFS mount patch stuff
Siguza Sep 6, 2023
bd39bbe
fix remount root patch
asdfugil Sep 6, 2023
473225d
Fix tvOS 17.x / audioOS 17.x / bridgeOS 8.x KPF
Siguza Oct 10, 2023
73c5fa9
kpf-test: test everything even if some failed
asdfugil Oct 26, 2023
b3ea8a5
ci: switch to zstd compression
asdfugil Oct 26, 2023
a46f5de
kpf-test: exit(6) on linux instead of abort
asdfugil Oct 26, 2023
2e69146
kpf: fix detecting kernel version on some kernels
asdfugil Oct 27, 2023
9fc14fe
kpf: fix apfs_vfsop_mount patch on iOS 15.0b1-15.0b4
asdfugil Oct 29, 2023
7d27b7e
kpf: use strstr for apfs_vfsop_mount
asdfugil Oct 29, 2023
efd954f
Revert "kpf: jbinit2 compatibility"
asdfugil Aug 17, 2023
18e48e2
choose rootful or rootless based on ssv
asdfugil Aug 17, 2023
b8e3bb8
use UINT64_C
asdfugil Aug 17, 2023
d66964d
support LZMA compressed ramdisk
asdfugil Oct 30, 2023
983748a
support LZMA compressed ramdisk
asdfugil Oct 30, 2023
b8fb5fe
md0 on /cores
kok3shidoll Oct 31, 2023
161504e
kpf-test: sed _launchd_execve_hook on linux
asdfugil Oct 31, 2023
d344c9e
just for xnu-7938
kok3shidoll Oct 31, 2023
98e3908
kpf: plooshInit support
asdfugil Nov 1, 2023
e8e363a
kpf: BSD Name based rooting
asdfugil Nov 1, 2023
220159d
usbloader: Compressed module support
asdfugil Nov 1, 2023
11bb55f
kpf: Fix certain app store apps crashing on 17.2+
asdfugil Jan 8, 2024
0b4dc73
kpf: fix thid_should_crash string match on xnu-10063
asdfugil Jan 25, 2024
d3ac571
kpf: fix finding mac_execve on xnu-10063
asdfugil Jan 25, 2024
c16ade5
kpf-test: should panic on missing apfs_vfsop_mount (ios 15-16)
asdfugil Jan 25, 2024
d93a0fb
kpf: apply thid_should_crash correctly on xnu-10063
asdfugil Jan 25, 2024
67910fb
kpf: fix nvram_unlock on xnu-10063 (#179)
asdfugil Jan 28, 2024
609957b
Sigh
Siguza Jan 28, 2024
e37120c
fixed find copyout
kok3shidoll Jan 31, 2024
8f3dd36
kpf: Add patch to disable Protobox on iOS 16+
opa334 Feb 15, 2024
383ea2a
kpf: Add patch to disable Protobox on iOS 16+
asdfugil Feb 16, 2024
5f7c911
actions: Delete /usr/share/dotnet
asdfugil Feb 16, 2024
6fb9cfb
fixed find copyout for real
asdfugil Feb 16, 2024
d25d4b8
kpf: check protobox existence *properly*
asdfugil Feb 18, 2024
6bf3ca8
Fixed APFS Rename for tvOS 15.0+
asdfugil Feb 19, 2024
4255e7f
If we can remount realfs, disable the snapshot too
asdfugil Feb 19, 2024
8ce9b65
Fix thid_should_crash=0 application
asdfugil Mar 5, 2024
e86577d
use lrzip because sgp1 downloads are slow
asdfugil Mar 5, 2024
314c3f7
Fix protobox patch printf
asdfugil Mar 5, 2024
776ced3
use normal zstd
asdfugil Mar 6, 2024
745e5d0
Actually use normal zstd
asdfugil Mar 6, 2024
6f40b0e
Fix 4K md0oncores
asdfugil Mar 23, 2024
c93abf8
Define socnum in kpf-test
asdfugil Mar 23, 2024
e5f001c
Remove testing
asdfugil Mar 23, 2024
e8f3875
fix shellcode patch
asdfugil Mar 23, 2024
bb6b2e7
Handle force-usbdevice
asdfugil Mar 28, 2024
25a0a4d
md0oncores for xnu-7090, xnu-7195
asdfugil Mar 30, 2024
eaa11a8
apply apfs_vfsop_mount on xnu-7195
asdfugil Mar 30, 2024
4203fea
Use the apfs_vfsop_mount string instead of has_tmpfs
asdfugil Mar 31, 2024
a3c128d
Generate development PongoOS in actions
asdfugil Mar 31, 2024
30d5150
Do not mkdir twice
asdfugil Mar 31, 2024
d48308a
Add root on orig-fs patch
asdfugil Apr 5, 2024
603c88d
fix rootful 17.4
asdfugil Apr 7, 2024
96aec00
Fix amfi_ret jump offset computing
PatriceBlin Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 41 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Build KPF & Pongo

on:
# Trigger on all pushes and pull requests
Expand All @@ -10,43 +10,53 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: macos-latest
steps:
- name: Install toolchain
run: |
echo 'deb https://assets.checkra.in/debian /' | sudo tee /etc/apt/sources.list.d/checkra1n.list
sudo apt-key adv --fetch-keys https://assets.checkra.in/debian/archive.key
sudo apt-get update
sudo apt-get install -y ld64 cctools-strip
- name: Voodoo magic
id: voodoo
uses: actions/cache@v2
with:
key: ${{ github.event_name }}-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
push-${{ github.ref }}-
push-
path: |
**
- name: Checkout repository
if: steps.voodoo.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0

- name: Update repository
if: steps.voodoo.outputs.cache-hit == 'true'
run: |
git submodule update --init --recursive
git fetch --all
git reset --hard origin/$(git branch --show-current)
git submodule update --recursive --remote
- name: Compile
run: EMBEDDED_CC='clang-10' EMBEDDED_AR='llvm-ar-10' EMBEDDED_RANLIB='llvm-ranlib-10' make all
- name: Archive
uses: actions/upload-artifact@v2

- name: Compile KPF and Pongo
run: |
make

- name: Prepare upload directory
run: |
mkdir upload
mv build/Pongo.bin upload/
mv build/checkra1n-kpf-pongo upload/

- name: Compile KPF and Pongo Development
run: |
make clean
make DEV_BUILD=1

- name: Prepare upload directory Development
run: |
mv build/Pongo.bin upload/Pongo.bin.development
mv build/checkra1n-kpf-pongo upload/checkra1n-kpf-pongo.development

- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7

- name: Upload artifact
uses: wangyucode/[email protected]
with:
name: PongoOS
path: |
build/checkra1n-kpf-pongo
build/Pongo
build/Pongo.bin
build/PongoConsolidated.bin
host: ${{ secrets.NICKCHAN_FTP_HOST }}
port: ${{ secrets.NICKCHAN_FTP_PORT }}
username: palera1n
password: ${{ secrets.NICKCHAN_FTP_PASS }}
forceUpload: true
dryRun: false
localDir: 'upload'
remoteDir: "/palera1n/artifacts/kpf/${{ steps.branch-name.outputs.ref_branch || github.ref }}"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif

# General options
EMBEDDED_LD_FLAGS ?= -nostdlib -Wl,-dead_strip -Wl,-Z $(EMBEDDED_LDFLAGS)
EMBEDDED_CC_FLAGS ?= --target=arm64-apple-ios12.0 -std=gnu17 -Wall -Wstrict-prototypes -Werror=incompatible-function-pointer-types -flto -ffreestanding -nostdlibinc -fno-blocks -U__nonnull -DTARGET_OS_OSX=0 -DTARGET_OS_MACCATALYST=0 -D_GNU_SOURCE -D__DYNAMIC_REENT__ -DDER_TAG_SIZE=8 -I$(LIB)/include $(EMBEDDED_LD_FLAGS) $(EMBEDDED_CFLAGS)
EMBEDDED_CC_FLAGS ?= --target=arm64-apple-ios12.0 -std=gnu17 -Wall -Wstrict-prototypes -Werror=incompatible-function-pointer-types -flto -ffreestanding -nostdlibinc -fno-blocks -U__nonnull -DTARGET_OS_OSX=0 -DTARGET_OS_MACCATALYST=0 -D_GNU_SOURCE -D__DYNAMIC_REENT__ -DDER_TAG_SIZE=8 -Wno-strict-prototypes -I$(LIB)/include $(EMBEDDED_LD_FLAGS) $(EMBEDDED_CFLAGS)

ifdef DEV_BUILD
EMBEDDED_CC_FLAGS += -DDEV_BUILD
Expand Down
3 changes: 3 additions & 0 deletions checkra1n/kpf-test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/kpf-test.ios
/kpf-test.macos
/kpf-test.linux
shellcode_S_linux.S
xnu_S_linux.S
20 changes: 18 additions & 2 deletions checkra1n/kpf-test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ RA1N := $(ROOT)/checkra1n/kpf
KPF_H := $(wildcard $(RA1N)/*.h) $(wildcard $(INC)/*.h) $(wildcard $(SRC)/kernel/*.h) $(wildcard $(SRC)/drivers/*.h)
KPF_C := main.c $(wildcard $(RA1N)/*.c) $(wildcard $(RA1N)/*.S) $(SRC)/drivers/xnu/xnu.c $(SRC)/drivers/xnu/xnu.S
KPF_LD_FLAGS := -Wl,-fatal_warnings -Wl,-dead_strip $(KPF_LDFLAGS)
KPF_CC_FLAGS := -std=gnu17 -Wall -Wstrict-prototypes -Werror=incompatible-function-pointer-types -O3 -flto -I$(INC) -I$(SRC)/kernel -I$(SRC)/drivers -DCHECKRA1N_VERSION='"x.y.z"' -Diprintf=printf -Dpanic=realpanic \
KPF_CC_FLAGS := -std=gnu17 -Wall -Wno-strict-prototypes -Werror=incompatible-function-pointer-types -O3 -flto -I$(INC) -I$(SRC)/kernel -I$(SRC)/drivers -DCHECKRA1N_VERSION='"x.y.z"' -Diprintf=printf -Dpanic=realpanic \
'-Djit_set_exec(m)=void pthread_jit_write_protect_np(int); pthread_jit_write_protect_np(m)' -DOVERRIDE_CACHEABLE_VIEW=0x800000000ULL -DDEV_BUILD -D_GNU_SOURCE $(KPF_CFLAGS) $(KPF_LD_FLAGS)
KPF_LD_FLAGS_LINUX :=
KPF_CC_FLAGS_LINUX := -std=gnu17 -Wall -Wno-strict-prototypes -O3 -flto -I$(INC) -I$(SRC)/kernel -I$(SRC)/drivers -DCHECKRA1N_VERSION='"x.y.z"' -Diprintf=printf -Dpanic=realpanic \
-DOVERRIDE_CACHEABLE_VIEW=0x800000000ULL '-Djit_set_exec(m)=void pthread_jit_write_protect_np(int);' -DDEV_BUILD -D_GNU_SOURCE -Iinclude $(KPF_CFLAGS) $(KPF_LD_FLAGS_LINUX)

ifeq ($(HOST_OS),Darwin)
IOS_CC ?= xcrun -sdk iphoneos clang --target=arm64-apple-ios7.0
Expand All @@ -26,6 +29,7 @@ else
ifeq ($(HOST_OS),Linux)
# TODO: macOS target
IOS_CC ?= arm64-apple-ios12.0.0-clang -arch arm64
LINUX_CC ?= clang
SIGN ?= ldid -Sent.plist
endif
endif
Expand All @@ -42,5 +46,17 @@ kpf-test.ios: Makefile $(KPF_C) $(KPF_H)
kpf-test.macos: Makefile $(KPF_C) $(KPF_H)
$(MACOS_CC) -o $@ $(KPF_C) $(KPF_CC_FLAGS)

shellcode_S_linux.S: $(RA1N)/shellcode.S Makefile
sed -e 's/_pf_jit/pf_jit/g' -e 's/_dyld_shc/dyld_shc/g' -e 's/_sandbox/sandbox/g' \
-e 's/_fsctl_shc/fsctl_shc/g' -e 's/_kdi_shc/kdi_shc/g' -e 's/_nvram_shc/nvram_shc/g' \
-e 's/_launchd_execve_hook/launchd_execve_hook/g' $< > $@

xnu_S_linux.S: $(SRC)/drivers/xnu/xnu.S Makefile
sed -e 's/_pf_jit/pf_jit/g' $< > $@

kpf-test.linux: Makefile $(KPF_C) $(KPF_H) shellcode_S_linux.S xnu_S_linux.S
$(LINUX_CC) -o $@ main.c -lbsd -g $(wildcard $(RA1N)/*.c) $(SRC)/drivers/xnu/xnu.c shellcode_S_linux.S xnu_S_linux.S $(KPF_CC_FLAGS_LINUX)

clean:
rm -f kpf-test.ios kpf-test.macos
rm -f kpf-test.ios kpf-test.macos kpf-test.linux
rm -f shellcode_S_linux.S xnu_S_linux.S
146 changes: 146 additions & 0 deletions checkra1n/kpf-test/include/mach-o/loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright (c) 1999-2010 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* Mach-O declarations for non-Apple targets */
#ifndef __APPLE__
#ifndef _LOADER_H_
#define _LOADER_H_

#include <stdint.h>
typedef int32_t integer_t;

// <mach/machine.h>
typedef integer_t cpu_type_t;
typedef integer_t cpu_subtype_t;
#define CPU_ARCH_ABI64 0x01000000 /* 64 bit ABI */
#define CPU_TYPE_ARM ((cpu_type_t) 12)
#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
#define ARM_THREAD_STATE64 6

#define _STRUCT_ARM_THREAD_STATE64 struct __darwin_arm_thread_state64
_STRUCT_ARM_THREAD_STATE64
{
uint64_t __x[29]; /* General purpose registers x0-x28 */
uint64_t __fp; /* Frame pointer x29 */
uint64_t __lr; /* Link register x30 */
uint64_t __sp; /* Stack pointer x31 */
uint64_t __pc; /* Program counter */
uint32_t __cpsr; /* Current program status register */
};

// <mach/vm_prot.h>
typedef int vm_prot_t;

// <mach-o/fat.h>
#define FAT_MAGIC 0xcafebabe
#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
struct fat_header {
uint32_t magic; /* FAT_MAGIC */
uint32_t nfat_arch; /* number of structs that follow */
};

struct fat_arch {
cpu_type_t cputype; /* cpu specifier (int) */
cpu_subtype_t cpusubtype; /* machine specifier (int) */
uint32_t offset; /* file offset to this object file */
uint32_t size; /* size of this object file */
uint32_t align; /* alignment as a power of 2 */
};

// Everything below is from <mach-o/loader.h>
#define MH_MAGIC_64 0xfeedfacf
#define SG_NORELOC 0x4
#define LC_REQ_DYLD 0x80000000
#define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */
#define LC_BUILD_VERSION 0x32 /* build for platform min OS version */
#define LC_SEGMENT_64 0x19

#define PLATFORM_MACOS 1
#define PLATFORM_IOS 2
#define PLATFORM_TVOS 3
#define PLATFORM_WATCHOS 4
#define PLATFORM_BRIDGEOS 5
#define PLATFORM_MACCATALYST 6
#define PLATFORM_IOSSIMULATOR 7
#define PLATFORM_TVOSSIMULATOR 8
#define PLATFORM_WATCHOSSIMULATOR 9
#define PLATFORM_DRIVERKIT 10

#define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */

struct mach_header_64 {
uint32_t magic; /* mach magic number identifier */
cpu_type_t cputype; /* cpu specifier */
cpu_subtype_t cpusubtype; /* machine specifier */
uint32_t filetype; /* type of file */
uint32_t ncmds; /* number of load commands */
uint32_t sizeofcmds; /* the size of all the load commands */
uint32_t flags; /* flags */
uint32_t reserved; /* reserved */
};

struct segment_command_64 { /* for 64-bit architectures */
uint32_t cmd; /* LC_SEGMENT_64 */
uint32_t cmdsize; /* includes sizeof section_64 structs */
char segname[16]; /* segment name */
uint64_t vmaddr; /* memory address of this segment */
uint64_t vmsize; /* memory size of this segment */
uint64_t fileoff; /* file offset of this segment */
uint64_t filesize; /* amount to map from the file */
vm_prot_t maxprot; /* maximum VM protection */
vm_prot_t initprot; /* initial VM protection */
uint32_t nsects; /* number of sections in segment */
uint32_t flags; /* flags */
};

struct build_version_command {
uint32_t cmd; /* LC_BUILD_VERSION */
uint32_t cmdsize; /* sizeof(struct build_version_command) plus */
/* ntools * sizeof(struct build_tool_version) */
uint32_t platform; /* platform */
uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
uint32_t ntools; /* number of tool entries following this */
};

struct load_command {
uint32_t cmd; /* type of load command */
uint32_t cmdsize; /* total size of command in bytes */
};

struct section_64 { /* for 64-bit architectures */
char sectname[16]; /* name of this section */
char segname[16]; /* segment this section goes in */
uint64_t addr; /* memory address of this section */
uint64_t size; /* size in bytes of this section */
uint32_t offset; /* file offset of this section */
uint32_t align; /* section alignment (power of 2) */
uint32_t reloff; /* file offset of relocation entries */
uint32_t nreloc; /* number of relocation entries */
uint32_t flags; /* flags (section type and attributes)*/
uint32_t reserved1; /* reserved (for offset or index) */
uint32_t reserved2; /* reserved (for count or sizeof) */
uint32_t reserved3; /* reserved */
};

#endif
#endif
Loading