A BLACK CAT

自 由 到 死

强迫症的 Debug 环境搭建记录

以 GLIBC 为例,搭建二进制与源码调试环境

[TOC]

Build Glibc With Debug Symbol

首先搞清楚系统自带的 libc.so 版本信息,然后构建相同版本的 glibc,我 Gentoo Portage 自带的 glibc 版本为 2.38:

$ /lib64/libc.so.6
GNU C Library (Gentoo 2.38-r8 (patchset 9)) stable release version 2.38.
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 13.2.1 20231216.
libc ABIs: UNIQUE ABSOLUTE
Minimum supported kernel: 3.7.0
For bug reporting instructions, please see:
<https://bugs.gentoo.org/>.

glibc 源码在 https://ftp.gnu.org/gnu/glibc 发行:

$ wget https://ftp.gnu.org/gnu/glibc/glibc-2.38.tar.bz2
$ tar -xvf glibc-2.38.tar.bz2;rm glibc-2.38.tar.bz2
$ cd glibc
$ ../configure --prefix=/home/ihexon/glibc_bin --enable-profile

阅读更多

PTMALLOC 分析

[TOC]

GLIBC 版本:

commit 36f2487f13e3540be9ee0fb51876b1da72176d3f (grafted, HEAD, tag: glibc-2.38)
Author: Andreas K. Hüttel <dilfridge@gentoo.org>
Date:   Mon Jul 31 19:54:16 2023 +0200

    NEWS: Fix typos

    Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>

阅读更多

RTL8821 Linux 驱动安装

首先确定 USB VID

$ lsusb
Bus 001 Device 004: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter
root hub

我说使用的开源驱动:

https://github.com/aircrack-ng/rtl8812au

我的内核版本:

$ uname -a
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

阅读更多

UFI001C 平台折腾记录

Openwrt4UFI Stick Notes

[TOC]

Hardware & SerialConsole

  • MSM8916 Soc 平台
  • 4GB EMMC
  • 512MB DDR 内存

相关 dts 树文件:

msm8916.dtsi
msm8916-ufi.dtsi
msm8916-thwc-ufi001c.dts

我的 UFI BCP 丝印为 UFI003_MB_V02,Serial Console 的触点也有提示,注意使用 FT232 USB UART Board 的时候需要连接 UFI 的 GND 触点,否则 Serial Console 无输出。

无论如何也不要连接 VCC 触点[color=red]

阅读更多

MSM8916 研究记录

[TOC]

MSM8916 研究记录

lk1nd/lk2nd

  • lk2nd: “secondary” bootloader intended for devices where existing firmware cannot be replaced easily (most smartphones and tablets). In this configuration, lk2nd does not replace the stock bootloader. Instead, it is packed into an Android boot image, which is then loaded by the stock bootloader just like the original Android image. The real operating system can be placed in the boot partition with 512 KiB offset or stored in a ext2 file system. It does not have to be Android or even Linux, any kind of kernel can be packed into an Android boot image.

  • lk1st: primary bootloader intended for single-board computers (SBCs) and expert users. In this case, it is the “first” bootloader responsible for loading the main operating system.

所以 lk1nd 为 1 级引导,用于启动整个操作系统。而 lk2nd 不是必须的,lk2nd 提供给我们一个比较友好的 fastboot interface 来维护 emmc 内的各个分区。

阅读更多

_dl_fixup 机制研究记录

搭建 Glibc Debug 调试环境

Build Glibc

$ wget -q -O- https://ftp.gnu.org/gnu/glibc/glibc-2.38.tar.xz | tar -Jxv -C  ./
$ cd glibc-2.38
$ ./configure --enable-debug --prefix=/home/ihexon/glibc_bin
$ make ; make install

glibc 不支持 clang 编译,或者说暂时不支持。因为 glibc 本身使用了大量GCC独占的特性。但开源社区也有尝试用 Clang 构建 Glibc

必须指定安装位置 --prefix=/home/ihexon/glibc_bin,不然 glibc 就安装到 /usr/local/lib 中去了,跨版本升级底层C库这显然会让系统会发生异常。

如果手抖覆盖了系统的 /usr/lib/aarch64-linux-gnu/libc.so.6 库,整个系统就崩了。 [color=red]

阅读更多

RockChip 安全启动的一点猜想

bootROM

所有支持 Secure Boot 的 CPU 都会有一个写死在 CPU 中的 bootROM 程序。CPU 在通电之后执行的第一条指令就在 bootROM 的入口。bootROM 拥有最高的执行权限,也就是 EL3。它将初始化 Secure Boot 安全机制,加载 Secure Boot Key 等密钥、从 eMMC 加载并验证 First Stage Bootloader(FSBL),最后跳转进 FSBL 中。

bootROM 是完全只读的,这个在 CPU 出厂时就被写死了,连 OEM 都无法更改。bootROM 通常会被映射到它专属的一块内存地址中,但是如果你尝试向这块地址写入内容,一般都会出错或者没有任何效果。

有些芯片还会有一个专门的寄存器控制 bootROM 的可见性,bootROM 可以通过这个寄存器禁止别的程序读取它的代码,以阻止攻击者通过逆向 bootROM 寻找漏洞。

阅读更多

ARMv8-A 可信固件乱谈

全部都是个人理解,非常个人的理解,非常不建议阅读,建议立即关闭此页面

ARM TrustZone 是什么

TrustZone 技术与 Cortex-A 处理器紧密集成,并通过 AMBA-AXI 总线和特定的 TrustZone 系统 IP 块在系统中进行扩展。此系统方法意味着可以保护安全内存、加密块、键盘和屏幕等外设,从而可确保它们免遭软件攻击。

阅读更多