資科工所
0786030
陳柏宇
 正常模式
 恢復模式 – Recovery Mode
 韌體更新模式 – DFU Mode
2
 Boot ROM
 LLB (Low Level Bootloader)
 iBoot
 Kernel
 iOS launchd
3
4
5
Application Processor
Boot ROM
Apple Public Key Low-Level
Bootloader
(LLB)
iBoot Kernel iOS
 iOS 啟動過程中,均會驗證每個元件是否經過 Apple 加密簽名
 Boot ROM 包含 Apple Root CA Public Key
 除了 Boot ROM 沒有加密以外,其他元件都有加密
 iBoot
 LLB
 Kernel
 Filesystem
 Baseband
6
 如果啟動失敗則切換到 DFU Mode
 A5 之前有漏洞,可繞過簽名檢查安裝客製化的 LLB
 使用 A5 的裝置
 Apple iPad 2
 Apple iPhone 4S
 Apple Apple TV 第三代
 Apple iPod touch 5
 Apple iPad mini
7
 受影響的處理器 S5L8720 / S5L8920
 當時 LLB 從 NOR 載入到 RAM 時沒有進行簽名檢查以及長度檢查
 在恢復模式更新 LLB 也沒有進行檢查
 Boot Rom 放在 0x0 ~ 0x100000,搬移到 0x20000000 ~ 0x20100000
 SRAM 映射到 0x22000000 ~ 0x22100000 以及 0x84000000 ~
0x84100000
 SRAM ~ SRAM+0x24000 用來存放 LLB
 SRAM+0x24000 用來存放 Boot ROM 需要用到的 variables、heap 和
stack
 因此 LLB 只要長度大於 0x24000 byte 就可以產生溢位,覆蓋 Boot
Rom 的簽名檢查
8
 S5L8720 – iPod Touch 2G
 0x220240D4 - SHA1 accelerator register table
 0x22024200 - Block Device List
 0x220250A0 - Permissions Flags
 0x220254E0 - Interrupt Table
 0x2202C000 - Page table
9
 負責載入 iBoot,若載入失敗,進入到 DFU Mode
 格式為加密的 IMG3 / IMG4 檔案
 Firmware/all_flash.xxxlp.production/LLB.xxx.RELEASE.img3
 Firmware/all_flash/LLB.d42.RELEASE.im4p
10
 iBSS (iBoot Single Stage)
 負責底層初始化以及準備載入 iBEC
 iOS 10 之後改名為 iBootStage1
 iBEC (iBoot Epoch Change)
 負責 iTunes 通過 USB 升級 iOS 的過程
 iOS 10 之後改名為 iBootStage2
11
 主要的 Loader
 負責載入 OS Kernel
 在 iOS5 時,iBoot 會被載入到 0x5FF00000 執行
 內建 HFS+ / APFS Driver,可直接存取 iOS 檔案系統,並支援多
執行緒
 main
 顯示啟動的蘋果 logo
 根據 auto-boot 和 boot-command(fsboot) 進行啟動環境的設定
 uart reader
 Debug 測試用
12
 fsboot()
 掛載檔案系統
 定位kernel
 準備裝置
 若啟動失敗,則進入恢復模式
 idleoff
 idle超過一定時間則關閉設備
 poweoff
 電量不足時關閉設備
 usb-req
 處理iTunes的USB連接
 usb-high-current / usb-no-current
 處理USB充電
 command
 啟動shell
13
14
15
16
 基於 iOS 9.3 的 iBoot 原始碼,在 2018 年 2 月被洩露到 github 上
 包含以下裝置的 iBoot 原始碼
 iBoot for A5 targets (s5l8940x, s5l8942x, s5l8945x, s5l8947x) and
s5l8747x (used in Haywire)
 iBoot for A6 targets (both s5l8950x and s5l8955x)
 iBoot for A7 (s5l8960x), A8 (t7000, t7001), A9 (s8000, s8003, s8001),
S1 (s7002) and S1P/S2 (t8002)
18
 /apps # SecureROM, iBoot, EmbeddedIOP
 /arch # Platform architecture-specific code
 /docs
 /drivers # apple, nand, nor, power, usb, etc
 /include # Header and libs
 /lib # Support library
 /makefiles
 /platform # SoC-specific code, drivers, startup code, etc
 /sys # Core OS services.
 /target # Target-specific code, fpga, sim, etc
19
20
 main.c 主要函式
 _main
 boot_selected
 lookup_image_in_bdev
 load_selected_image
 boot_loaded_image
21
22
23
 arm_invalidate_dcache()
 arm_invalidate_icache()
 aux_cr = arm_read_aux_cr();
 arm_write_aux_cr(aux_cr);
 cr = arm_read_cr();
 arm_write_cr(cr);
 arm_mmu_init(resume);
24
25
 Initialise the heap.
 security_init(false);
 sys_setup_default_environment();
 task_init();
26
 platform_setup_default_en
vironment()
 target_setup_default_envir
onment()
27
 platform_setup_default_environment()
 env_set("boot-device", "nvme_nand0", 0);
 target_setup_default_environment()
 env_set("boot-args", " debug=0x14e serial=3 amfi=3 amfi_get_out_of_my_way=1
cs_enforcement_disable=1 fips_mode=0", 0);
 env_set("display-color-space","RGB888", 0);
 env_set("display-timing", "fpga-wsvga", 0);
 env_set("ramdisk-delay", "60000000", 0); /* This tells PurpleRestore to slow down;
rdar://6345846 */
 env_set("idle-off", "false", 0);
 env_set("bootdelay", "3", 0);
 env_set("debug-uarts", "3", 0);
28
 platform_enable_boot_interface(true, boot_device, boot_arg);
 security_init(true);
29
30
31
32
33
 do_ll_init();
 sys_init();
 platform_early_init();
 platform_init_mainmem(resume);
 platform_init();
 check_enter_dfu();
 find_boot_images();
 boot_iboot();
 security_init(false);
 main_dfu();
34
 platform_power_init();
 miu_init(); /* CIF, SCU, remap setup */
 clocks_init();
 interrupt_init();
 timer_init(0);
 boot_set_stage(kPowerNVRAMiBootStageProductStart);
35
 platform_enable_error_handler();
 spi_init();
 pci_init();
 apcie_set_s3e_mode(true);
 nvme_init(0, apcie_get_port_bridge(0), 0);
 target_init(); //flash_nor_init(SPI_NOR0);
36
37
38
 bootfile = (char *)malloc(FS_MAXPATHLEN);
 err = mount_bootfs();
 err = load_kernelcache_file(bootfile,
IMAGE_TYPE_KERNELCACHE, &entry, &boot_args);
 boot_darwin((void *)entry, (void *)boot_args);
39
iOS Bootloader

iOS Bootloader

  • 1.
  • 2.
     正常模式  恢復模式– Recovery Mode  韌體更新模式 – DFU Mode 2
  • 3.
     Boot ROM LLB (Low Level Bootloader)  iBoot  Kernel  iOS launchd 3
  • 4.
  • 5.
    5 Application Processor Boot ROM ApplePublic Key Low-Level Bootloader (LLB) iBoot Kernel iOS
  • 6.
     iOS 啟動過程中,均會驗證每個元件是否經過Apple 加密簽名  Boot ROM 包含 Apple Root CA Public Key  除了 Boot ROM 沒有加密以外,其他元件都有加密  iBoot  LLB  Kernel  Filesystem  Baseband 6
  • 7.
     如果啟動失敗則切換到 DFUMode  A5 之前有漏洞,可繞過簽名檢查安裝客製化的 LLB  使用 A5 的裝置  Apple iPad 2  Apple iPhone 4S  Apple Apple TV 第三代  Apple iPod touch 5  Apple iPad mini 7
  • 8.
     受影響的處理器 S5L8720/ S5L8920  當時 LLB 從 NOR 載入到 RAM 時沒有進行簽名檢查以及長度檢查  在恢復模式更新 LLB 也沒有進行檢查  Boot Rom 放在 0x0 ~ 0x100000,搬移到 0x20000000 ~ 0x20100000  SRAM 映射到 0x22000000 ~ 0x22100000 以及 0x84000000 ~ 0x84100000  SRAM ~ SRAM+0x24000 用來存放 LLB  SRAM+0x24000 用來存放 Boot ROM 需要用到的 variables、heap 和 stack  因此 LLB 只要長度大於 0x24000 byte 就可以產生溢位,覆蓋 Boot Rom 的簽名檢查 8
  • 9.
     S5L8720 –iPod Touch 2G  0x220240D4 - SHA1 accelerator register table  0x22024200 - Block Device List  0x220250A0 - Permissions Flags  0x220254E0 - Interrupt Table  0x2202C000 - Page table 9
  • 10.
     負責載入 iBoot,若載入失敗,進入到DFU Mode  格式為加密的 IMG3 / IMG4 檔案  Firmware/all_flash.xxxlp.production/LLB.xxx.RELEASE.img3  Firmware/all_flash/LLB.d42.RELEASE.im4p 10
  • 11.
     iBSS (iBootSingle Stage)  負責底層初始化以及準備載入 iBEC  iOS 10 之後改名為 iBootStage1  iBEC (iBoot Epoch Change)  負責 iTunes 通過 USB 升級 iOS 的過程  iOS 10 之後改名為 iBootStage2 11
  • 12.
     主要的 Loader 負責載入 OS Kernel  在 iOS5 時,iBoot 會被載入到 0x5FF00000 執行  內建 HFS+ / APFS Driver,可直接存取 iOS 檔案系統,並支援多 執行緒  main  顯示啟動的蘋果 logo  根據 auto-boot 和 boot-command(fsboot) 進行啟動環境的設定  uart reader  Debug 測試用 12
  • 13.
     fsboot()  掛載檔案系統 定位kernel  準備裝置  若啟動失敗,則進入恢復模式  idleoff  idle超過一定時間則關閉設備  poweoff  電量不足時關閉設備  usb-req  處理iTunes的USB連接  usb-high-current / usb-no-current  處理USB充電  command  啟動shell 13
  • 14.
  • 15.
  • 16.
  • 18.
     基於 iOS9.3 的 iBoot 原始碼,在 2018 年 2 月被洩露到 github 上  包含以下裝置的 iBoot 原始碼  iBoot for A5 targets (s5l8940x, s5l8942x, s5l8945x, s5l8947x) and s5l8747x (used in Haywire)  iBoot for A6 targets (both s5l8950x and s5l8955x)  iBoot for A7 (s5l8960x), A8 (t7000, t7001), A9 (s8000, s8003, s8001), S1 (s7002) and S1P/S2 (t8002) 18
  • 19.
     /apps #SecureROM, iBoot, EmbeddedIOP  /arch # Platform architecture-specific code  /docs  /drivers # apple, nand, nor, power, usb, etc  /include # Header and libs  /lib # Support library  /makefiles  /platform # SoC-specific code, drivers, startup code, etc  /sys # Core OS services.  /target # Target-specific code, fpga, sim, etc 19
  • 20.
  • 21.
     main.c 主要函式 _main  boot_selected  lookup_image_in_bdev  load_selected_image  boot_loaded_image 21
  • 22.
  • 23.
  • 24.
     arm_invalidate_dcache()  arm_invalidate_icache() aux_cr = arm_read_aux_cr();  arm_write_aux_cr(aux_cr);  cr = arm_read_cr();  arm_write_cr(cr);  arm_mmu_init(resume); 24
  • 25.
  • 26.
     Initialise theheap.  security_init(false);  sys_setup_default_environment();  task_init(); 26
  • 27.
  • 28.
     platform_setup_default_environment()  env_set("boot-device","nvme_nand0", 0);  target_setup_default_environment()  env_set("boot-args", " debug=0x14e serial=3 amfi=3 amfi_get_out_of_my_way=1 cs_enforcement_disable=1 fips_mode=0", 0);  env_set("display-color-space","RGB888", 0);  env_set("display-timing", "fpga-wsvga", 0);  env_set("ramdisk-delay", "60000000", 0); /* This tells PurpleRestore to slow down; rdar://6345846 */  env_set("idle-off", "false", 0);  env_set("bootdelay", "3", 0);  env_set("debug-uarts", "3", 0); 28
  • 29.
     platform_enable_boot_interface(true, boot_device,boot_arg);  security_init(true); 29
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
     do_ll_init();  sys_init(); platform_early_init();  platform_init_mainmem(resume);  platform_init();  check_enter_dfu();  find_boot_images();  boot_iboot();  security_init(false);  main_dfu(); 34
  • 35.
     platform_power_init();  miu_init();/* CIF, SCU, remap setup */  clocks_init();  interrupt_init();  timer_init(0);  boot_set_stage(kPowerNVRAMiBootStageProductStart); 35
  • 36.
     platform_enable_error_handler();  spi_init(); pci_init();  apcie_set_s3e_mode(true);  nvme_init(0, apcie_get_port_bridge(0), 0);  target_init(); //flash_nor_init(SPI_NOR0); 36
  • 37.
  • 38.
  • 39.
     bootfile =(char *)malloc(FS_MAXPATHLEN);  err = mount_bootfs();  err = load_kernelcache_file(bootfile, IMAGE_TYPE_KERNELCACHE, &entry, &boot_args);  boot_darwin((void *)entry, (void *)boot_args); 39