Changes between Version 11 and Version 12 of Dev/KernelHack/COINS/worklog/201111


Ignore:
Timestamp:
Nov 25, 2011 2:15:56 AM (12 years ago)
Author:
mitty
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Dev/KernelHack/COINS/worklog/201111

    v11 v12  
    24442444Continuing. 
    24452445}}} 
     2446 
     2447 = 11/23 = 
     2448 == instead of char*, use typedef struct DATA == 
     2449 * s0711489@ubuntu-lucid64:~$ sudo insmod stackmod.ko 
     2450{{{ 
     2451Nov 23 01:54:02 ubuntu-lucid64 kernel: [  242.821597] stackmod is loaded 
     2452Nov 23 01:54:02 ubuntu-lucid64 kernel: [  242.821601] stackmod: 128 entry, major is 251, minor is 0 
     2453Nov 23 01:54:02 ubuntu-lucid64 kernel: [  242.821616] stackmod: create /proc/stackmod 
     2454Nov 23 01:54:02 ubuntu-lucid64 kernel: [  242.821618] stackmod is added successfully 
     2455}}} 
     2456 
     2457 * s0711489@ubuntu-lucid64:~$ sudo mknod /dev/stack c 251 0 
     2458 * s0711489@ubuntu-lucid64:~$ sudo chmod 666 /dev/stack 
     2459 
     2460 * s0711489@ubuntu-lucid64:~$ echo hoge > /dev/stack 
     2461{{{ 
     2462Nov 23 01:55:26 ubuntu-lucid64 kernel: [  327.080724] stackmod is opened 
     2463Nov 23 01:55:26 ubuntu-lucid64 kernel: [  327.080773] stackmod is written 
     2464Nov 23 01:55:26 ubuntu-lucid64 kernel: [  327.080784] stackmod is released 
     2465}}} 
     2466 
     2467 * s0711489@ubuntu-lucid64:~$ cat /proc/stackmod 
     2468{{{ 
     2469stack: 1 
     2470}}} 
     2471{{{ 
     2472Nov 23 01:55:44 ubuntu-lucid64 kernel: [  344.897310] /proc/stackmod is read 
     2473Nov 23 01:55:44 ubuntu-lucid64 kernel: [  344.897328] /proc/stackmod is read 
     2474}}} 
     2475 
     2476 * s0711489@ubuntu-lucid64:~$ cat /dev/stack 
     2477{{{ 
     2478cat: /dev/stack: Bad address 
     2479}}} 
     2480{{{ 
     2481Nov 23 01:56:09 ubuntu-lucid64 kernel: [  370.036240] stackmod is opened 
     2482Nov 23 01:56:09 ubuntu-lucid64 kernel: [  370.036253] stackmod is read 
     2483Nov 23 01:56:09 ubuntu-lucid64 kernel: [  370.036346] stackmod: copy_to_user failed 
     2484Nov 23 01:56:09 ubuntu-lucid64 kernel: [  370.036471] stackmod is released 
     2485}}} 
     2486  * buggy 
     2487 
     2488 * s0711489@ubuntu-lucid64:~$ cat /proc/stackmod 
     2489{{{ 
     2490stack: 1 
     2491}}} 
     2492 
     2493 === check what is bug with gdb === 
     2494 * s0711489@ubuntu-lucid64:~$ sudo insmod stackmod.ko entry=4 
     2495 * s0711489@ubuntu-lucid64:~$ sudo mknod /dev/stack c 251 0 
     2496 * s0711489@ubuntu-lucid64:~$ sudo chmod 666 /dev/stack 
     2497 
     2498 * s0711489@ubuntu-lucid64:~$ cat /sys/module/stackmod/sections/.text 
     2499{{{ 
     25000xffffffffa0056000 
     2501}}} 
     2502 * s0711489@ubuntu-lucid64:~$ cat /sys/module/stackmod/sections/.data 
     2503{{{ 
     25040xffffffffa00566b8 
     2505}}} 
     2506 * s0711489@ubuntu-lucid64:~$ cat /sys/module/stackmod/sections/.bss 
     2507{{{ 
     25080xffffffffa00568f0 
     2509}}} 
     2510 
     2511 * gdb 
     2512{{{ 
     2513(gdb) file vmlinux 
     2514Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/x86_64/vmlinux...(no debugging symbols found)...done. 
     2515(gdb) add-symbol-file ../../04/stackmod/stackmod.o 0xffffffffa0056000 -s .data 0xffffffffa00566b8 -s .bss 0xffffffffa00568f0 
     2516add symbol table from file "../../04/stackmod/stackmod.o" at 
     2517        .text_addr = 0xffffffffa0056000 
     2518        .data_addr = 0xffffffffa00566b8 
     2519        .bss_addr = 0xffffffffa00568f0 
     2520(y or n) y 
     2521Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.o...done. 
     2522(gdb) target remote localhost:8864 
     2523Remote debugging using localhost:8864 
     25240xffffffff810097a9 in native_safe_halt () 
     2525    at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/x86_64/arch/x86/include/asm/irqflags.h:49 
     252649              asm volatile("sti; hlt": : :"memory"); 
     2527(gdb) b stackmod_read 
     2528Breakpoint 1 at 0xffffffffa00560b4: file /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c, line 62. 
     2529(gdb) b stackmod_write 
     2530Breakpoint 2 at 0xffffffffa00561e0: file /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c, line 105. 
     2531(gdb) b stackmod_proc_read 
     2532Breakpoint 3 at 0xffffffffa00561a3: file /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c, line 153. 
     2533(gdb) c 
     2534Continuing. 
     2535}}} 
     2536 
     2537 * s0711489@ubuntu-lucid64:~$ cat /proc/stackmod 
     2538{{{ 
     2539stack: 0 
     2540}}} 
     2541{{{ 
     2542Breakpoint 3, stackmod_proc_read (page=0xffff88001d9a9000 "p\227\232\035", 
     2543    start=0xffff88001b95fe90, off=0, count=3072, eof=0xffff88001b95fe9c, 
     2544    data=0x0) 
     2545    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:153 
     2546153     ) { 
     2547(gdb) p stack 
     2548$1 = {data = 0xffff88001b7c7940, depth = 0, errno = 0} 
     2549(gdb) p stack.data 
     2550$2 = (DATA *) 0xffff88001b7c7940 
     2551(gdb) ptype stack.data 
     2552type = struct kernel_module_stack_data { 
     2553    int length; 
     2554    char *content; 
     2555} * 
     2556(gdb) ptype stack.data[0] 
     2557type = struct kernel_module_stack_data { 
     2558    int length; 
     2559    char *content; 
     2560} 
     2561(gdb) p stack.data[0] 
     2562$3 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2563(gdb) p stack.data[1] 
     2564$4 = {length = 0, content = 0x0} 
     2565(gdb) p stack.data[2] 
     2566$5 = {length = 0, 
     2567  content = 0x2e2e02020010e071 <Address 0x2e2e02020010e071 out of bounds>} 
     2568(gdb) c 
     2569Continuing. 
     2570 
     2571Breakpoint 3, stackmod_proc_read (page=0xffff88001d9a9000 "stack: 0\n", 
     2572    start=0xffff88001b95fe90, off=9, count=3072, eof=0xffff88001b95fe9c, 
     2573    data=0x0) 
     2574    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:153 
     2575153     ) { 
     2576(gdb) finish 
     2577Run till exit from #0  stackmod_proc_read ( 
     2578    page=0xffff88001d9a9000 "stack: 0\n", start=0xffff88001b95fe90, off=9, 
     2579    count=3072, eof=0xffff88001b95fe9c, data=0x0) 
     2580    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:153 
     2581__proc_file_read (file=<value optimized out>, buf=0x1420000 "stack: 0\n", 
     2582    nbytes=32768, ppos=0xffff88001b95ff48) at fs/proc/generic.c:125 
     2583125                     if (n == 0)   /* end of file */ 
     2584Could not fetch register "orig_rax"; remote failure reply 'E00' 
     2585(gdb) c 
     2586Continuing. 
     2587}}} 
     2588 
     2589 * s0711489@ubuntu-lucid64:~$ cat /dev/stack 
     2590{{{ 
     2591Nov 23 02:43:46 ubuntu-lucid64 kernel: [ 2449.923317] stackmod is opened 
     2592Nov 23 02:43:46 ubuntu-lucid64 kernel: [ 2514.778526] stackmod is read 
     2593Nov 23 02:43:46 ubuntu-lucid64 kernel: [ 2538.311203] stackmod is released 
     2594}}} 
     2595{{{ 
     2596Breakpoint 1, stackmod_read (filep=0xffff88001b90a240, 
     2597    buf_user=0x189a000 <Address 0x189a000 out of bounds>, size=32768, 
     2598    offset=0xffff88001bb19f48) 
     2599    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:62 
     260062      ) { 
     2601(gdb) p p 
     2602$6 = <value optimized out> 
     2603(gdb) p stack.depth 
     2604$7 = 0 
     2605 
     2606(snip) 
     2607 
     2608(gdb) n 
     260966              printk(KERN_DEBUG MODNAME " is read\n"); 
     2610(gdb) 
     261162      ) { 
     2612(gdb) 
     261366              printk(KERN_DEBUG MODNAME " is read\n"); 
     2614(gdb) 
     261568              if (size == 0) { 
     2616(gdb) 
     261771              if (stack.depth == 0) { 
     2618(gdb) 
     2619101     } 
     2620(gdb) 
     2621vfs_read (file=0xffff88001b90a240, 
     2622    buf=0x189a000 <Address 0x189a000 out of bounds>, 
     2623    count=<value optimized out>, pos=0xffff88001bb19f48) at fs/read_write.c:313 
     2624313                     if (ret > 0) { 
     2625(gdb) c 
     2626Continuing. 
     2627}}} 
     2628 
     2629 * s0711489@ubuntu-lucid64:~$ echo depth=0 > /dev/stack 
     2630{{{ 
     2631Nov 23 02:47:16 ubuntu-lucid64 kernel: [ 2651.841249] stackmod is opened 
     2632Nov 23 02:47:41 ubuntu-lucid64 kernel: [ 2724.502176] stackmod is written 
     2633Nov 23 02:50:07 ubuntu-lucid64 kernel: [ 2916.725803] stackmod is released 
     2634}}} 
     2635{{{ 
     2636Breakpoint 2, stackmod_write (filep=0xffff88001b984240, 
     2637    buf_user=0x126ac08 "depth=0\n /usr/bin/xzdec\nusr/sbin/update-alternatives\n\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337", <incomplete sequence \337>..., size=8, 
     2638    offset=0xffff88001b8dff48) 
     2639    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:105 
     2640105     ) { 
     2641(gdb) p p 
     2642$8 = <value optimized out> 
     2643(gdb) p stack 
     2644$9 = {data = 0xffff88001b7c7940, depth = 0, errno = 0} 
     2645(gdb) p stack.data[0] 
     2646$10 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2647(gdb) n 
     2648108             printk(KERN_DEBUG MODNAME " is written\n"); 
     2649(gdb) 
     2650105     ) { 
     2651(gdb) 
     2652108             printk(KERN_DEBUG MODNAME " is written\n"); 
     2653(gdb) 
     2654110             if (size == 0) { 
     2655(gdb) 
     2656113             if (stack.depth >= entry) { 
     2657(gdb) 
     2658117             if (buf_user == NULL) { 
     2659(gdb) 
     2660122             p.content = (char *) kmalloc(size * sizeof(char), GFP_KERNEL); 
     2661(gdb) 
     2662123             if (p.content == NULL) { 
     2663(gdb) 
     2664122             p.content = (char *) kmalloc(size * sizeof(char), GFP_KERNEL); 
     2665(gdb) 
     2666123             if (p.content == NULL) { 
     2667(gdb) 
     2668129             if (copy_from_user(p.content, buf_user, size) != 0) { 
     2669(gdb) p stack.data[0] 
     2670$11 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2671(gdb) n 
     2672136             stack.depth++; 
     2673(gdb) p stack.data[0] 
     2674$12 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2675(gdb) p stack.data[0].content 
     2676$13 = 0xffff88001b7c7988 "\210y|\033" 
     2677(gdb) p size 
     2678$14 = 0 
     2679(gdb) p buf_user 
     2680$15 = 0x126ac08 "depth=0\n /usr/bin/xzdec\nusr/sbin/update-alternatives\n\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337", <incomplete sequence \337>... 
     2681(gdb) n 
     2682140             return size; 
     2683(gdb) p stack 
     2684$16 = {data = 0xffff88001b7c7940, depth = 1, errno = 0} 
     2685(gdb) p stack.data[0] 
     2686$17 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2687(gdb) c 
     2688Continuing. 
     2689}}} 
     2690 
     2691 * s0711489@ubuntu-lucid64:~$ echo depth=1 > /dev/stack 
     2692{{{ 
     2693Nov 23 02:51:53 ubuntu-lucid64 kernel: [ 2955.599055] stackmod is opened 
     2694Nov 23 02:51:53 ubuntu-lucid64 kernel: [ 2986.156722] stackmod is written 
     2695Nov 23 02:53:51 ubuntu-lucid64 kernel: [ 3139.258180] stackmod is released 
     2696}}} 
     2697{{{ 
     2698Breakpoint 2, stackmod_write (filep=0xffff88001b80e9c0, 
     2699    buf_user=0x126ac08 "depth=1\n /usr/bin/xzdec\nusr/sbin/update-alternatives\n\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337", <incomplete sequence \337>..., size=8, 
     2700    offset=0xffff88001b8dff48) 
     2701    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:105 
     2702105     ) { 
     2703(gdb) p size 
     2704$18 = 8 
     2705(gdb) n 
     2706108             printk(KERN_DEBUG MODNAME " is written\n"); 
     2707(gdb) 
     2708105     ) { 
     2709(gdb) 
     2710108             printk(KERN_DEBUG MODNAME " is written\n"); 
     2711(gdb) 
     2712110             if (size == 0) { 
     2713(gdb) 
     2714113             if (stack.depth >= entry) { 
     2715(gdb) 
     2716117             if (buf_user == NULL) { 
     2717(gdb) 
     2718122             p.content = (char *) kmalloc(size * sizeof(char), GFP_KERNEL); 
     2719(gdb) l 
     2720117             if (buf_user == NULL) { 
     2721118                     return -EINVAL; 
     2722119             } 
     2723120 
     2724121             p = stack.data[stack.depth]; 
     2725122             p.content = (char *) kmalloc(size * sizeof(char), GFP_KERNEL); 
     2726123             if (p.content == NULL) { 
     2727124                     printk(KERN_WARNING MODNAME ": (char *) kmalloc failed\n"); 
     2728125                     return -ENOMEM; 
     2729126             } 
     2730(gdb) n 
     2731123             if (p.content == NULL) { 
     2732(gdb) p p.content 
     2733$19 = 0x0 
     2734(gdb) n 
     2735122             p.content = (char *) kmalloc(size * sizeof(char), GFP_KERNEL); 
     2736(gdb) 
     2737123             if (p.content == NULL) { 
     2738(gdb) p p.content 
     2739$20 = 0x0 
     2740(gdb) n 
     2741129             if (copy_from_user(p.content, buf_user, size) != 0) { 
     2742(gdb) 
     2743136             stack.depth++; 
     2744(gdb) p p.content 
     2745$21 = 0x0 
     2746(gdb) p size 
     2747$22 = 0 
     2748(gdb) p p 
     2749$23 = <value optimized out> 
     2750(gdb) p stack.data 
     2751$24 = (DATA *) 0xffff88001b7c7940 
     2752(gdb) p stack 
     2753$25 = {data = 0xffff88001b7c7940, depth = 1, errno = 0} 
     2754(gdb) p stack[1] 
     2755Structure has no component named operator[]. 
     2756(gdb) p stack.data[1] 
     2757$26 = {length = 0, content = 0x0} 
     2758(gdb) n 
     2759140             return size; 
     2760(gdb) p size 
     2761$27 = 0 
     2762(gdb) finish 
     2763Run till exit from #0  stackmod_write (filep=<value optimized out>, 
     2764    buf_user=0x126ac08 "depth=1\n /usr/bin/xzdec\nusr/sbin/update-alternatives\n\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337", <incomplete sequence \337>..., size=0, 
     2765    offset=0xffff88001b8dff48) 
     2766    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:140 
     27670xffffffff810df5a3 in vfs_write (file=0xffff88001b80e9c0, 
     2768    buf=0x126ac08 "depth=1\n /usr/bin/xzdec\nusr/sbin/update-alternatives\n\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337\337", <incomplete sequence \337>..., 
     2769    count=<value optimized out>, pos=0xffff88001b8dff48) at fs/read_write.c:366 
     2770366                             ret = file->f_op->write(file, buf, count, pos); 
     2771Could not fetch register "orig_rax"; remote failure reply 'E00' 
     2772(gdb) c 
     2773Continuing. 
     2774}}} 
     2775 
     2776 * s0711489@ubuntu-lucid64:~$ cat /proc/stackmod 
     2777{{{ 
     2778stack: 2 
     2779}}} 
     2780{{{ 
     2781Breakpoint 3, stackmod_proc_read (page=0xffff88001d9a9000 "stack: 0\n", 
     2782    start=0xffff88001b8ade90, off=0, count=3072, eof=0xffff88001b8ade9c, 
     2783    data=0x0) 
     2784    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:153 
     2785153     ) { 
     2786(gdb) p stack 
     2787$28 = {data = 0xffff88001b7c7940, depth = 2, errno = 0} 
     2788(gdb) p stack.data[0] 
     2789$29 = {length = 461142784, content = 0xffff88001b7c7988 "\210y|\033"} 
     2790(gdb) p stack.data[1] 
     2791$30 = {length = 0, content = 0x0} 
     2792(gdb) p stack.data[2] 
     2793$31 = {length = 0, 
     2794  content = 0x2e2e02020010e071 <Address 0x2e2e02020010e071 out of bounds>} 
     2795(gdb) ptype stack 
     2796type = struct kernel_module_stack { 
     2797    DATA *data; 
     2798    int depth; 
     2799    int errno; 
     2800} 
     2801(gdb) ptype stack.data 
     2802type = struct kernel_module_stack_data { 
     2803    int length; 
     2804    char *content; 
     2805} * 
     2806(gdb) ptype stack.data[0] 
     2807type = struct kernel_module_stack_data { 
     2808    int length; 
     2809    char *content; 
     2810} 
     2811(gdb) ptype stack.data[0].content 
     2812type = char * 
     2813(gdb) c 
     2814Continuing. 
     2815 
     2816Breakpoint 3, stackmod_proc_read (page=0xffff88001d9a9000 "stack: 2\n", 
     2817    start=0xffff88001b8ade90, off=9, count=3072, eof=0xffff88001b8ade9c, 
     2818    data=0x0) 
     2819    at /home/ugrad/07/s0711489/coursework/KernelHack/04/stackmod/stackmod.c:153 
     2820153     ) { 
     2821(gdb) c 
     2822Continuing. 
     2823}}}