| | 940 | |
| | 941 | = 09/30 = |
| | 942 | == install VMware tools to custom kernel == |
| | 943 | * install.sh |
| | 944 | {{{#!sh |
| | 945 | #! /bin/sh -ex |
| | 946 | |
| | 947 | VERSION=`cat /mnt/hgfs/linux-*/include/config/kernel.release` |
| | 948 | echo Install Linux Kernel version ${VERSION} |
| | 949 | |
| | 950 | cd /mnt/hgfs/linux-*/ |
| | 951 | make install |
| | 952 | make modules_install |
| | 953 | |
| | 954 | mkinitramfs -o /boot/initrd.img-${VERSION} ${VERSION} |
| | 955 | update-grub |
| | 956 | |
| | 957 | echo Install Kernel Headers to /lib/modules/${VERSION}/build |
| | 958 | |
| | 959 | mv /lib/modules/${VERSION}/build /lib/modules/${VERSION}/build-`date '+%Y%m%d'` |
| | 960 | |
| | 961 | cd /mnt/hgfs/ |
| | 962 | find linux-* -type f | egrep -v '.o$' | egrep -v 'vmlinu' | tar c --files-from - | tar x -C /lib/modules/${VERSION}/ |
| | 963 | mv /lib/modules/${VERSION}/linux-* /lib/modules/${VERSION}/build |
| | 964 | |
| | 965 | uname -a |
| | 966 | }}} |
| | 967 | |
| | 968 | * s0711489@ubuntu-lucid64:~$ sudo /mnt/hgfs/tools/install.sh |
| | 969 | {{{ |
| | 970 | + cat /mnt/hgfs/linux-2.6.35.14/include/config/kernel.release |
| | 971 | + VERSION=2.6.35.14 |
| | 972 | + echo Install Linux Kernel version 2.6.35.14 |
| | 973 | Install Linux Kernel version 2.6.35.14 |
| | 974 | + cd /mnt/hgfs/linux-2.6.35.14/ |
| | 975 | + make install |
| | 976 | sh /mnt/hgfs/linux-2.6.35.14/arch/x86/boot/install.sh 2.6.35.14 arch/x86/boot/bzImage \ |
| | 977 | System.map "/boot" |
| | 978 | + make modules_install |
| | 979 | INSTALL arch/x86/kernel/test_nx.ko |
| | 980 | INSTALL drivers/scsi/scsi_wait_scan.ko |
| | 981 | INSTALL net/netfilter/xt_mark.ko |
| | 982 | DEPMOD 2.6.35.14 |
| | 983 | + mkinitramfs -o /boot/initrd.img-2.6.35.14 2.6.35.14 |
| | 984 | + update-grub |
| | 985 | Generating grub.cfg ... |
| | 986 | Found linux image: /boot/vmlinuz-2.6.35.14 |
| | 987 | Found initrd image: /boot/initrd.img-2.6.35.14 |
| | 988 | Found linux image: /boot/vmlinuz-2.6.32-33-generic |
| | 989 | Found initrd image: /boot/initrd.img-2.6.32-33-generic |
| | 990 | Found memtest86+ image: /boot/memtest86+.bin |
| | 991 | done |
| | 992 | + echo Install Kernel Headers to /lib/modules/2.6.35.14/build |
| | 993 | Install Kernel Headers to /lib/modules/2.6.35.14/build |
| | 994 | + date +%Y%m%d |
| | 995 | + mv /lib/modules/2.6.35.14/build /lib/modules/2.6.35.14/build-20110930 |
| | 996 | + cd /mnt/hgfs/ |
| | 997 | + egrep -v .o$ |
| | 998 | + egrep -v vmlinu |
| | 999 | + tar c --files-from - |
| | 1000 | + tar x -C /lib/modules/2.6.35.14/ |
| | 1001 | + find linux-2.6.35.14 -type f |
| | 1002 | + mv /lib/modules/2.6.35.14/linux-2.6.35.14 /lib/modules/2.6.35.14/build |
| | 1003 | + uname -a |
| | 1004 | Linux ubuntu-lucid64 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:07:13 UTC 2011 x86_64 GNU/Linux |
| | 1005 | }}} |
| | 1006 | * s0711489@ubuntu-lucid64:~$ sudo reboot |
| | 1007 | |
| | 1008 | * s0711489@ubuntu-lucid64:~$ uname -a |
| | 1009 | * s0711489@ubuntu-lucid64:~$ sudo vmware-config-tools.pl --default |
| | 1010 | |
| | 1011 | == step execution with GDB == |
| | 1012 | * s0711489@ubuntu-lucid64:~/coursework/KernelHack/02$ cat > getpid.c |
| | 1013 | {{{#!cc |
| | 1014 | #include <sys/types.h> |
| | 1015 | #include <syscall.h> |
| | 1016 | #include <stdio.h> |
| | 1017 | |
| | 1018 | int main (void) { |
| | 1019 | printf ("getpid() -> %d\n", getpid()); |
| | 1020 | } |
| | 1021 | }}} |
| | 1022 | |
| | 1023 | * s0711489@ubuntu-lucid64:~/coursework/KernelHack/02$ cc getpid.c -o getpid |
| | 1024 | * s0711489@ubuntu-lucid64:~/coursework/KernelHack/02$ strace -f -o getpid.log ./getpid |
| | 1025 | {{{ |
| | 1026 | getpid() -> 2007 |
| | 1027 | }}} |
| | 1028 | |
| | 1029 | * windell57:x86_64 s0711489$ gdb |
| | 1030 | {{{ |
| | 1031 | (gdb) file vmlinux |
| | 1032 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/x86_64/vmlinux...(no debugging symbols found)...done. |
| | 1033 | (gdb) target remote localhost:8864 |
| | 1034 | }}} |
| | 1035 | {{{ |
| | 1036 | (gdb) help step |
| | 1037 | Step program until it reaches a different source line. |
| | 1038 | Argument N means do this N times (or till program stops for another reason). |
| | 1039 | (gdb) help next |
| | 1040 | Step program, proceeding through subroutine calls. |
| | 1041 | Like the "step" command as long as subroutine calls do not happen; |
| | 1042 | when they do, the call is treated as one instruction. |
| | 1043 | Argument N means do this N times (or till program stops for another reason). |
| | 1044 | }}} |
| | 1045 | * 初めのうちはnextを使っていたため、サブルーチンコールがスキップされてしまい、うまく実行コードを見ることが出来なかった。 |
| | 1046 | |
| | 1047 | * windell57:02 s0711489$ cat > gdb.step.sh |
| | 1048 | {{{#!sh |
| | 1049 | echo 'file vmlinux |
| | 1050 | target remote localhost:8864' |
| | 1051 | yes s |
| | 1052 | }}} |
| | 1053 | |
| | 1054 | * s0711489@ubuntu-lucid64:~/coursework/KernelHack/02$ while true; do ./getpid ;done |
| | 1055 | {{{ |
| | 1056 | getpid() -> 1816 |
| | 1057 | getpid() -> 1817 |
| | 1058 | |
| | 1059 | (snip) |
| | 1060 | |
| | 1061 | getpid() -> 2846 |
| | 1062 | getpid() -> 2847 |
| | 1063 | getpid() -> 2848 |
| | 1064 | Killed by signal 15. |
| | 1065 | }}} |
| | 1066 | |
| | 1067 | * windell57:x86_64 s0711489$ sh ../../02/gdb.step.sh | gdb > gdb.txt |
| | 1068 | |
| | 1069 | * stepコマンドだけでは、実行されるコードが膨大すぎて、目当てのgetpidシステムコールまで到達出来なかった |