[OS] Operating System Practice(1): Kernel Build
[OS] Operating System Practice(1): Kernel Build
๐ ์ด์์ฒด์ ์ค์ต ์์ ์ ๋ฆฌ
Build environment
Use virtual machine ubuntu version:
24.04LTS
kernel์ 5.5.13์ ์ค์นํด์ผํจ
Build process
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 1. Update Packages and Install Required Packages
sudo apt update && sudo apt upgrade
sudo apt install build-essential libncurses6 libncurses-dev flex bison \
bc dwarves pahole libudev-dev libpci-dev \
libssl-dev libelf-dev libiberty-dev binutils-dev -y
# 2. Download the desired kernel version and decompress
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.13.tar.xz
tar xvf linux-5.5.13.tar.xz
# 3. Build kernel
cd linux-5.5.13
sudo cp -v /boot/config-$(uname -r) .config
sudo make menuconfig
* 1. Load -> .config
* 2. Save -> .config
* 3. Exit
sudo make -j$(nproc) # <- ์ค๋ฅ ๋ฐ์
sudo make modules_install
sudo make install
sudo reboot
์ฒซ๋ฒ์งธ ์ค๋ฅ
xrealloc ํจ์์์ use-after-free ์ค๋ฅ๊ฐ ๋ฐ์ํจ
์์ธ
- Linux 5.5.13์ ์ต์ gcc์ ํธํ๋์ง ์์ ์ ์์
ํด๊ฒฐ ๋ฐฉ์: gcc์ ๋ฒ์ ์ 10๋ก ๋ฎ์ถ๊ธฐ๋ก ๊ฒฐ์
1
2
3
4
5
6
# gcc 10 version ์ค์น
sudo apt install gcc-10 g++-10
# gcc์ ์ฐ์ ์์ ๋ณ๊ฒฝ
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 1 # <-์ฐ์ ์์๋ฒํธ
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 1
๋๋ฒ์งธ ์ค๋ฅ
objtool์ด
thunk_64.o
๋ฅผ ์ฒ๋ฆฌํ ๋ missing symbol table์ด ๋ฐ์ํจ๋ฐ์ํ๋ ์ด์ :
objtool
์ดsymbol table
์ ํ์ธํ๋ ๊ณผ์ ์์ missing symbol table ๋ฐ์Makefile.build
์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ ํด๋น.o
ํ์ผ์ ์ญ์ ํ๋ ๊ท์น์ด ์ ์ฉ๋จ- ๋ฐ๋ผ์
arch/x86/entry/thunk_64.o
๊ฐ ์ญ์ ๋จ
ํด๊ฒฐ ๋ฐฉ์: CONFIG_STACK_VALIDATION
๋นํ์ฑํ(objtool์ ์ฌ์ฉํ์ฌ ์ฌ์ฉํ์ฌ Stack Validation์ ์ํํ ์ง ๊ฒฐ์ ํ๋ ์ต์
) -> ์ ์ฒด objtool ๊ฒ์ฌ๋ฅผ ์ฐํํ์ง ๋ง๊ณ thunk_64.o
ํ์ผ๋ง ์์ธ ์ฒ๋ฆฌํด์ ์ฐํ
arch/x86/entry/Makefile
์์ thunk_64.o ํ์ผ์ objtool ๊ฒ์ฆ์์ ์ ์ธํ๋๋ก ํธ์ง
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vim arch/x86/entry/Makefile
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for the x86 low level entry code
#
OBJECT_FILES_NON_STANDARD_entry_64_compat.o := y
OBJECT_FILES_NON_STANDARD_thunk_64.o := y # ์ถ๊ฐ
CFLAGS_syscall_64.o += $(call cc-option,-Wno-override-init,)
CFLAGS_syscall_32.o += $(call cc-option,-Wno-override-init,)
obj-y := entry_$(BITS).o thunk_$(BITS).o syscall_$(BITS).o
obj-y += common.o
obj-y += vdso/
obj-y += vsyscall/
obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o syscall_32.o
CFLAGS_REMOVE_thunk_64.o := -fstack-validation # ์ถ๊ฐ
์ดํ sudo make clean
๋ก ์บ์ ์ด๊ธฐํ ํ ๋ค์ ๋น๋
์ธ๋ฒ์งธ ์ค๋ฅ
- build ๊ณผ์ ์์
debian/canonical-certs.pem
ํ์ผ์ด ํ์ํ์ง๋ง ์กด์ฌํ์ง ์์์ ๋ฐ์ํ๋ ์ค๋ฅ - ์ด ํ์ผ์ ๋ณดํต ๋ฐฐํฌํ์์ ์ ๊ณตํ๋ ์ธ์ฆ์์ด์ง๋ง, ์ปค๋ ์์ค์๋ ํฌํจ๋์ง ์๋ ๊ฒฝ์ฐ๊ฐ ๋ง์
ํด๊ฒฐ ๋ฐฉ์: .config
ํ์ผ์์ CONFIG_SYSTEM_TRUSTED_KEYS=""
์ผ๋ก ์์
This post is licensed under CC BY 4.0 by the author.