root@uubb-ThinkCentre-M930s-N000:/# uname -a Linux uubb-ThinkCentre-M930s-N000 5.4.0-150-generic #167~18.04.1-Ubuntu SMP Wed May 2400:51:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux root@uubb-ThinkCentre-M930s-N000:/# nproc 16
env ARCH=X86_64 make deconfig 或者 make deconfig // 根据机器默认生成 上面两个都生成不了,最终执行 make x86_64_deconfig
修改配置信息 make memuconfig
1 2 3 4 5 6
# Debugging Kernel hacking ---> Compile-time checks and compiler options ---> Compile the kernel with debug info ---> yes Kernel hacking ---> Compile-time checks and compiler options ---> Provide GDB scripts for kernel debugging ---> yes General setup ---> Configure standard kernel features ---> yes General setup ---> Configure standard kernel features ---> Load all symbols for debugging/ksymoops ---> yes General setup ---> Configure standard kernel features ---> Include all symbols in kallsyms ---> yes
其他可选配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Only if64 bits is selected Binary Emulations ---> IA32 a.out support ---> yes Binary Emulations ---> IA32 ABI for 64-bit mode ---> yes
# Make sure the following options are enabled: General setup ---> Initial RAM filesystem and RAM disk (initramfs/initrd) support ---> yes General setup ---> Configure standard kernel features ---> Multiple users, groups and capabilities support ---> yes General setup ---> Configure standard kernel features ---> Sysfs syscall support ---> yes Device Drivers ---> Generic Driver Options ---> Maintain a devtmpfs filesystem to mount at /dev ---> yes Device Drivers ---> Generic Driver Options ---> Automount devtmpfs at /dev, after the kernel mounted the rootfs ---> yes Device Drivers ---> Character devices ---> Enable TTY ---> yes Device Drivers ---> Character devices ---> Serial drivers --->8250/16550and compatible serial support ---> yes Device Drivers ---> Character devices ---> Serial drivers ---> Console on 8250/16550 and compatible serial port ---> yes File systems ---> Pseudo filesystems ---> /proc file system support ---> yes File systems ---> Pseudo filesystems --->sysfs file system support ---> yes
如果想要在此内核上测试漏洞或内容,需要禁用以下策略:
1 2 3 4 5 6 7 8
# Allocations at NULL to allow nullptr de-reference Memory Management options ---> Low address space to protect from user allocation ---> 0 # SMAP disabled Processor type and features ---> Supervisor Mode Access Prevention ---> no # KASL, can be disabled by setting nokaslr in the bootloader cmdline Processor type and features ---> Build a relocatable kernel ---> no # Canary disabled General architecture-dependent options ---> Stack Protector buffer overflow detection ---> no
uubb@uubb-ThinkCentre-M930s-N000 ~/k/linux-5.10> sudo chroot debootstrap root@uubb-ThinkCentre-M930s-N000:/# ls bin dev home lib media opt root sbin sys usr vmlinuz boot etc initrd.img lib64 mnt proc run srv tmp var root@uubb-ThinkCentre-M930s-N000:/# passwd root Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@uubb-ThinkCentre-M930s-N000:/# root@uubb-ThinkCentre-M930s-N000:/# root@uubb-ThinkCentre-M930s-N000:/# root@uubb-ThinkCentre-M930s-N000:/# /usr/sbin/adduser user perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "zh_CN:zh", LC_ALL = (unset), LANG = "zh_CN.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). Adding user `user' ... Adding new group `user' (1000) ... Adding new user `user' (1000) with group `user' ... Creating home directory `/home/user' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for user Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
root@uubb-ThinkCentre-M930s-N000:/etc# cat << EOF | sudo tee "debootstrap/etc/fstab" > /dev/sda / ext4 errors=remount-ro,acl 0 1 > EOF tee: debootstrap/etc/fstab: No such file or directory root@uubb-ThinkCentre-M930s-N000:/etc# cat fstab # UNCONFIGURED FSTAB FOR BASE SYSTEM root@uubb-ThinkCentre-M930s-N000:/etc# echo "/dev/sda / ext4 errors=remount-ro,acl 0 1" >> fstab root@uubb-ThinkCentre-M930s-N000:/etc# cat fstab # UNCONFIGURED FSTAB FOR BASE SYSTEM /dev/sda / ext4 errors=remount-ro,acl 0 1
然后将debootstrap 目录创建为qcow2 镜像,这可时候要知道你的主机是否支持虚拟化,因为我在服务器上搭建的时候,不支持 uubb@uubb-ThinkCentre-M930s-N000 ~/k/linux-5.10> kvm-ok INFO: /dev/kvm exists KVM acceleration can be used
uubb@uubb-ThinkCentre-M930s-N000 ~/k/linux-5.10> uubb@uubb-ThinkCentre-M930s-N000 ~/k/linux-5.10> gdb vmlinux GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type"show copying" and "show warranty"for details. This GDB was configured as"x86_64-linux-gnu". Type"show configuration"for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. Forhelp, type"help". Type"apropos word" to searchfor commands related to "word"... Reading symbols from vmlinux...done. warning: File"/home/uubb/kernel_Linux/linux-5.10/scripts/gdb/vmlinux-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". To enable execution of this file add add-auto-load-safe-path /home/uubb/kernel_Linux/linux-5.10/scripts/gdb/vmlinux-gdb.py line to your configuration file"/home/uubb/.gdbinit". To completely disable this security protection add set auto-load safe-path / line to your configuration file"/home/uubb/.gdbinit". Formore information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the shell: ---Type <return> to continue, or q <return> to quit--- info "(gdb)Auto-loading safe path" (gdb) target remote localhost:1234 Remote debugging using localhost:1234 0x000000000000fff0 in exception_stacks () (gdb) (gdb) (gdb) b start_kernel Breakpoint 1 at 0xffffffff82b1dadb: file init/main.c, line 849. (gdb) c Continuing.