커널 자체와 커널 모듈에는 어떤 ELF 유형이 있습니까?

커널 자체와 커널 모듈에는 어떤 ELF 유형이 있습니까?

https://linux-audit.com/elf-binaries-on-linux-understanding-and-analytic/ 설명하다

유형 필드는 파일이 어떤 용도로 사용되는지 알려줍니다. 몇 가지 일반적인 파일 형식이 있습니다.

CORE (value 4)
DYN (Shared object file), for libraries (value 3)
EXEC (Executable file), for binaries (value 2)
REL (Relocatable file), before linked into an executable file (value 1)

...

일반적인 오해는 ELF 파일이 바이너리 또는 실행 파일에만 적용된다는 것입니다. 우리는 부분 조각(객체 코드)에 사용할 수 있음을 확인했습니다. 또 다른 예는 공유 라이브러리 또는 코어 덤프(해당 코어 또는 a.out 파일)입니다. ELF 사양은 커널 자체와 Linux의 Linux 커널 모듈에서도 사용됩니다.

커널 자체와 커널 모듈에는 어떤 ELF 유형이 있습니까?

제가 시도해 볼 수 있는 커널 자체 및 커널 모듈용 파일의 예를 들어주실 수 있습니까 file? 우분투 18.04를 사용하고 있습니다.

감사해요.

답변1

스스로 알아낼 수 있습니다:

모듈의 경우 다음을 확인하세요 /lib/modules/$(uname -r)/kernel/.../*.ko.

$ file xfs.ko 
xfs.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=bcb5e287509cedbb0c5ece383e0b97fb99e4781e, not stripped

$ readelf -h xfs.ko 
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          1829088 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         45
  Section header string table index: 44

커널의 경우 간단한 방법은 커널을 컴파일하고 vmlinux를 살펴보는 것입니다.

$ file vmlinux
vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=eaf006a7ccfedbc40a6feddb04088bdb2ef0112f, with debug_info, not stripped

$ readelf -h vmlinux
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x1000000
  Start of program headers:          64 (bytes into file)
  Start of section headers:          171602920 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         5
  Size of section headers:           64 (bytes)
  Number of section headers:         43
  Section header string table index: 42

답변2

대부분의 Linux 배포판에서 커널은 /boot압축 파일로 저장됩니다.bz이미지. 스크립트(Ubuntu 시스템에서 패키지로 제공됨)를 사용하여 extract-vmlinux압축을 풀 수 있습니다. linux-headersUbuntu 16.04에서는 다음 명령을 실행하여 4.4.0 커널의 ELF 유형을 확인할 수 있습니다.

$ sudo /usr/src/linux-headers-4.4.0-127/scripts/extract-vmlinux /boot/vmlinuz-4.4.0-127-generic > /tmp/vmlinux &&
readelf -h /tmp/vmlinux | grep Type

Type:                              EXEC (Executable file)

관련 정보