Loadable Kernel Module for bullhead

 

 

1. Environment

 

  • bullhead, aka LG Nexus 5X
  • Android Version : 8.1.0 Oreo
  • Kernel Version : 3.10.73-g25966c546824
  • Build Number : OPM5.171019.015

 

 

2. References

 

A. https://github.com/julius-b/android-lkm

B. https://mobile-security.gitbook.io/mobile-security-testing-guide/android-testing-guide/0x05c-reverse-engineering-and-tampering

C. https://zhuanlan.kanxue.com/article-4374.htm

D. http://gooddexamples.blogspot.com/2017/12/how-to-build-kernel-for-nexus5x.html

E. https://dayntimes.tistory.com/1278

F. https://xiphiasilver.net/2019/07/18/android-rooting-from-a-to-z/

G. https://stackoverflow.com/questions/37317906/error-building-android-kernel-multiple-target-patterns

H. https://stackoverflow.com/questions/35691830/arm64-image-to-zimage-or-boot-img

I. https://www.hackerschool.org/Sub_Html/HS_Posting/?uid=41

J. https://stackoverflow.com/questions/20836536/why-do-i-get-a-zero-android-kernel-address

 

 

3. Kernel Source

 

 

 

4. Prebuilt Toolchain

 

당연하게도 컴파일러의 버전에 상당히 영향을 받는다.

 

 

5. Kernel Build

 

make menuconfig의 설정과 관련해서는 오른쪽 주석을 참고하자.1https://zhuanlan.kanxue.com/article-4374.htm
https://xiphiasilver.net/kernel-build-configuration-for-bullhead/

Enable loadable module support를 설정하고, restrict kernel memory permissions as much as possible을 해제한다.

armeabi 아키텍처, 즉 32비트에서는 zImage 파일이 생성된다.2https://stackoverflow.com/questions/35691830/arm64-image-to-zimage-or-boot-img

 

6. Building Tool, mkbootimg

 

2-D를 참고했다.

 

7. Making Boot Image(boot.img)

 

boot.img는 팩토리 이미지(bullhead-opm5.171019.015)에서 추출한 원본 이미지이다.

 

8. Testing Built Kernel

 

정상적으로 부팅된다면, 플래시 메모리에 영구적으로 저장한다.

컴파일된 커널이 정상적으로 부팅되지 않은 것은 mkbootimg가 원인인 경우도 있다고 한다. 3https://dayntimes.tistory.com/1278

이러한 경우의 수를 없애기 위해, 원본 이미지에서 추출한 파일만으로 부트 이미지를 만들어 먼저 시험해 보는 것이 좋다.

 

9. Rooting

 

컴파일된 커널이 정상적으로 부팅되면, 안드로이드 디바이스를 루팅한다.4https://xiphiasilver.net/bullhead-rooting-from-a-to-z/

 

10. LKM Build

 

 

11. Signing Modules

 

커널 빌드할 때 CONFIG_MODULE_SIG 설정을 해제하면, 이 과정은 불필요하다.

 

12. Modules Execution

 

아래와 같은 에러가 발생한다면, make menuconfig에서 LKM Support를 설정하여 다시 컴파일해야 한다.

 

13. Check Running

 

로그는 cat /proc/kmsg로도 확인할 수 있다.