| 78 | |
| 79 | = 11/08 = |
| 80 | * new_debug() が正常に動作したりしなかったりする |
| 81 | * 結論 -> staticで確保していなかったのが良くない |
| 82 | |
| 83 | == char message[!__LOG_BUF_LEN]; == |
| 84 | * windell46:i386 s0711489$ ./build |
| 85 | {{{ |
| 86 | press enter key to make with i386 kernel |
| 87 | |
| 88 | Kernel: arch/x86/boot/bzImage is ready (#6) |
| 89 | }}} |
| 90 | * windell46:i386 s0711489$ make modules |
| 91 | |
| 92 | * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh |
| 93 | |
| 94 | * s0711489@ubuntu-lucid:~$ sudo reboot |
| 95 | {{{ |
| 96 | Linux ubuntu-lucid 2.6.35.14 #6 SMP Tue Nov 8 17:26:43 JST 2011 i686 GNU/Linux |
| 97 | }}} |
| 98 | * windell46:~ s0711489$ scp -r .subversion/ 172.16.237.130:~ |
| 99 | |
| 100 | * s0711489@ubuntu-lucid:~$ svn co https://XXXXXXXXXXXX/trunk/coursework/KernelHack/03/ |
| 101 | {{{ |
| 102 | Checked out revision 1387. |
| 103 | }}} |
| 104 | |
| 105 | * s0711489@ubuntu-lucid:~/03$ gcc -I /lib/modules/2.6.35.14/build/arch/x86/include/ new_debug-sys.c |
| 106 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 107 | {{{ |
| 108 | new_debug with argv[i]: Bad address |
| 109 | }}} |
| 110 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 |
| 111 | {{{ |
| 112 | new_debug with argv[i]: Bad address |
| 113 | new_debug with argv[i]: Bad address |
| 114 | }}} |
| 115 | |
| 116 | === gdb === |
| 117 | * viola06:i386 s0711489$ gdb |
| 118 | {{{ |
| 119 | |
| 120 | (gdb) file vmlinux |
| 121 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 122 | (gdb) b sys_new_debug |
| 123 | Breakpoint 1 at 0xc101d89f: file arch/x86/kernel/new_debug.c, line 9. |
| 124 | (gdb) target remote windell46:8832 |
| 125 | Remote debugging using windell46:8832 |
| 126 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 127 | 49 asm volatile("sti; hlt": : :"memory"); |
| 128 | (gdb) c |
| 129 | Continuing. |
| 130 | }}} |
| 131 | |
| 132 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 |
| 133 | {{{ |
| 134 | Breakpoint 1, sys_new_debug (message_user=0xbfc6499e "1", tp_user=0xbfc63804) at arch/x86/kernel/new_debug.c:9 |
| 135 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 136 | (gdb) l |
| 137 | 4 #include <linux/time.h> |
| 138 | 5 |
| 139 | 6 /* from kernel/printk.c */ |
| 140 | 7 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) |
| 141 | 8 |
| 142 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 143 | 10 int errno; |
| 144 | 11 char message[__LOG_BUF_LEN]; |
| 145 | 12 struct timespec ts; |
| 146 | 13 |
| 147 | (gdb) |
| 148 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 149 | 15 errno = -EFAULT; |
| 150 | 16 goto out; |
| 151 | 17 } |
| 152 | 18 |
| 153 | 19 if (message == NULL) { |
| 154 | 20 errno = -EINVAL; |
| 155 | 21 goto out; |
| 156 | 22 } |
| 157 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 158 | (gdb) |
| 159 | 24 errno = -EFAULT; |
| 160 | 25 goto out; |
| 161 | 26 } |
| 162 | 27 message[sizeof(message) - 1] = '\0'; |
| 163 | 28 |
| 164 | 29 printk(KERN_DEBUG "%s\n", message); |
| 165 | 30 |
| 166 | 31 if (tp_user != NULL) { |
| 167 | 32 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 168 | 33 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 169 | (gdb) |
| 170 | 34 errno = -EFAULT; |
| 171 | 35 goto out; |
| 172 | 36 } |
| 173 | 37 } |
| 174 | 38 |
| 175 | 39 errno = 0; |
| 176 | 40 |
| 177 | 41 out: |
| 178 | 42 return errno; |
| 179 | 43 } |
| 180 | (gdb) |
| 181 | Line number 44 out of range; arch/x86/kernel/new_debug.c has 43 lines. |
| 182 | (gdb) s |
| 183 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 184 | (gdb) |
| 185 | 41 out: |
| 186 | (gdb) |
| 187 | 43 } |
| 188 | (gdb) p errno |
| 189 | $1 = -14 |
| 190 | (gdb) finish |
| 191 | Run till exit from #0 sys_new_debug (message_user=0xbfc6499e "1", tp_user=0xbfc63804) at arch/x86/kernel/new_debug.c:43 |
| 192 | 0xc100288c in ?? () |
| 193 | Value returned is $2 = -14 |
| 194 | (gdb) c |
| 195 | Continuing. |
| 196 | |
| 197 | Breakpoint 1, sys_new_debug (message_user=0xbfc649a0 "2", tp_user=0xbfc63804) at arch/x86/kernel/new_debug.c:9 |
| 198 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 199 | (gdb) s |
| 200 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 201 | (gdb) |
| 202 | 41 out: |
| 203 | (gdb) finish |
| 204 | Run till exit from #0 sys_new_debug (message_user=0xbfc649a0 "2", tp_user=0xbfc63804) at arch/x86/kernel/new_debug.c:41 |
| 205 | 0xc100288c in ?? () |
| 206 | Value returned is $3 = -14 |
| 207 | (gdb) c |
| 208 | Continuing. |
| 209 | }}} |
| 210 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 |
| 211 | {{{ |
| 212 | new_debug with argv[i]: Bad address |
| 213 | new_debug with argv[i]: Bad address |
| 214 | }}} |
| 215 | |
| 216 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 217 | {{{ |
| 218 | (gdb) file vmlinux |
| 219 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 220 | (gdb) b sys_new_debug |
| 221 | Breakpoint 1 at 0xc101d89f: file arch/x86/kernel/new_debug.c, line 9. |
| 222 | (gdb) target remote windell46:8832 |
| 223 | Remote debugging using windell46:8832 |
| 224 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 225 | 49 asm volatile("sti; hlt": : :"memory"); |
| 226 | (gdb) c |
| 227 | Continuing. |
| 228 | |
| 229 | Breakpoint 1, sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:9 |
| 230 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 231 | (gdb) l |
| 232 | 4 #include <linux/time.h> |
| 233 | 5 |
| 234 | 6 /* from kernel/printk.c */ |
| 235 | 7 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) |
| 236 | 8 |
| 237 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 238 | 10 int errno; |
| 239 | 11 char message[__LOG_BUF_LEN]; |
| 240 | 12 struct timespec ts; |
| 241 | 13 |
| 242 | (gdb) |
| 243 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 244 | 15 errno = -EFAULT; |
| 245 | 16 goto out; |
| 246 | 17 } |
| 247 | 18 |
| 248 | 19 if (message == NULL) { |
| 249 | 20 errno = -EINVAL; |
| 250 | 21 goto out; |
| 251 | 22 } |
| 252 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 253 | (gdb) |
| 254 | 24 errno = -EFAULT; |
| 255 | 25 goto out; |
| 256 | 26 } |
| 257 | 27 message[sizeof(message) - 1] = '\0'; |
| 258 | 28 |
| 259 | 29 printk(KERN_DEBUG "%s\n", message); |
| 260 | 30 |
| 261 | 31 if (tp_user != NULL) { |
| 262 | 32 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 263 | 33 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 264 | (gdb) s |
| 265 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 266 | (gdb) |
| 267 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 268 | (gdb) |
| 269 | strncpy_from_user (dst=0xdf275f9c "", src=0x8048646 "new_debug()", count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 270 | 114 { |
| 271 | (gdb) l |
| 272 | 109 * If @count is smaller than the length of the string, copies @count bytes |
| 273 | 110 * and returns @count. |
| 274 | 111 */ |
| 275 | 112 long |
| 276 | 113 strncpy_from_user(char *dst, const char __user *src, long count) |
| 277 | 114 { |
| 278 | 115 long res = -EFAULT; |
| 279 | 116 if (access_ok(VERIFY_READ, src, 1)) |
| 280 | 117 __do_strncpy_from_user(dst, src, count, res); |
| 281 | 118 return res; |
| 282 | (gdb) |
| 283 | 119 } |
| 284 | 120 EXPORT_SYMBOL(strncpy_from_user); |
| 285 | 121 |
| 286 | 122 /* |
| 287 | 123 * Zero Userspace |
| 288 | 124 */ |
| 289 | 125 |
| 290 | 126 #define __do_clear_user(addr,size) \ |
| 291 | 127 do { \ |
| 292 | 128 int __d0; \ |
| 293 | (gdb) |
| 294 | 129 might_fault(); \ |
| 295 | 130 __asm__ __volatile__( \ |
| 296 | 131 "0: rep; stosl\n" \ |
| 297 | 132 " movl %2,%0\n" \ |
| 298 | 133 "1: rep; stosb\n" \ |
| 299 | 134 "2:\n" \ |
| 300 | 135 ".section .fixup,\"ax\"\n" \ |
| 301 | 136 "3: lea 0(%2,%0,4),%0\n" \ |
| 302 | 137 " jmp 2b\n" \ |
| 303 | 138 ".previous\n" \ |
| 304 | (gdb) |
| 305 | 139 _ASM_EXTABLE(0b,3b) \ |
| 306 | 140 _ASM_EXTABLE(1b,2b) \ |
| 307 | 141 : "=&c"(size), "=&D" (__d0) \ |
| 308 | 142 : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \ |
| 309 | 143 } while (0) |
| 310 | 144 |
| 311 | 145 /** |
| 312 | 146 * clear_user: - Zero a block of memory in user space. |
| 313 | 147 * @to: Destination address, in user space. |
| 314 | 148 * @n: Number of bytes to zero. |
| 315 | (gdb) s |
| 316 | 116 if (access_ok(VERIFY_READ, src, 1)) |
| 317 | (gdb) |
| 318 | 119 } |
| 319 | (gdb) p src |
| 320 | $1 = 0x8048646 "new_debug()" |
| 321 | (gdb) p dst |
| 322 | $2 = 0xdf275f9c "" |
| 323 | (gdb) p count |
| 324 | $3 = 262143 |
| 325 | (gdb) p res |
| 326 | $4 = -14 |
| 327 | (gdb) finish |
| 328 | Run till exit from #0 strncpy_from_user (dst=0xdf275f9c "", src=0x8048646 "new_debug()", count=262143) at arch/x86/lib/usercopy_32.c:119 |
| 329 | 0xc101d8d3 in sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:23 |
| 330 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 331 | Value returned is $5 = -14 |
| 332 | (gdb) s |
| 333 | 41 out: |
| 334 | (gdb) |
| 335 | 43 } |
| 336 | (gdb) finish |
| 337 | Run till exit from #0 sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:43 |
| 338 | 0xc100288c in ?? () |
| 339 | Value returned is $6 = -14 |
| 340 | (gdb) s |
| 341 | Cannot find bounds of current function |
| 342 | (gdb) c |
| 343 | Continuing. |
| 344 | }}} |
| 345 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 346 | {{{ |
| 347 | new_debug with argv[i]: Bad address |
| 348 | }}} |
| 349 | |
| 350 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 351 | {{{ |
| 352 | |
| 353 | (gdb) file vmlinux |
| 354 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 355 | (gdb) b sys_new_debug |
| 356 | Breakpoint 1 at 0xc101d89f: file arch/x86/kernel/new_debug.c, line 9. |
| 357 | (gdb) target remote windell46:8832 |
| 358 | Remote debugging using windell46:8832 |
| 359 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 360 | 49 asm volatile("sti; hlt": : :"memory"); |
| 361 | (gdb) c |
| 362 | Continuing. |
| 363 | |
| 364 | Breakpoint 1, sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:9 |
| 365 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 366 | (gdb) s |
| 367 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 368 | (gdb) |
| 369 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 370 | (gdb) |
| 371 | strncpy_from_user ( |
| 372 | dst=0xdc3d9f9c "\210\035i\b\250\035i\b\330\035i\b\250\270L\b\b\036i\b\030\036i\b\350\343O\b8\036i\bX\036i\bx\036i\b\270\036i\b\350\036i\b\330\036i\b\370\036i\b\b\037i\b\350\036i\b(\037i\b8\037i\bH\037i\bh\037i\b\210\037i\b\250\037i\b\350\037i\bX\021W\b\310\037i\bp\200h\b", src=0x8048646 "new_debug()", |
| 373 | count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 374 | 114 { |
| 375 | (gdb) |
| 376 | 116 if (access_ok(VERIFY_READ, src, 1)) |
| 377 | (gdb) |
| 378 | 119 } |
| 379 | (gdb) finish |
| 380 | Run till exit from #0 strncpy_from_user ( |
| 381 | dst=0xdc3d9f9c "\210\035i\b\250\035i\b\330\035i\b\250\270L\b\b\036i\b\030\036i\b\350\343O\b8\036i\bX\036i\bx\036i\b\270\036i\b\350\036i\b\330\036i\b\370\036i\b\b\037i\b\350\036i\b(\037i\b8\037i\bH\037i\bh\037i\b\210\037i\b\250\037i\b\350\037i\bX\021W\b\310\037i\bp\200h\b", src=0x8048646 "new_debug()", |
| 382 | count=262143) at arch/x86/lib/usercopy_32.c:119 |
| 383 | 0xc101d8d3 in sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:23 |
| 384 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 385 | Value returned is $1 = -14 |
| 386 | (gdb) |
| 387 | Run till exit from #0 0xc101d8d3 in sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:23 |
| 388 | 0xc100288c in ?? () |
| 389 | Value returned is $2 = -14 |
| 390 | (gdb) |
| 391 | Run till exit from #0 0xc100288c in ?? () |
| 392 | }}} |
| 393 | |
| 394 | * gdbでステップ実行していると、finishで関数から抜けようとした際に、以下のようにkernel panicを起こすことが多々あった[[br]][[Image(WS002510.png,33%)]][[Image(WS002511.png,33%)]] |
| 395 | |
| 396 | * まれにうまく動作した場合、message[]はstaticでは無いのに前のデータが残っていることがある模様 |
| 397 | * guest |
| 398 | {{{ |
| 399 | s0711489@ubuntu-lucid:~/03$ ./a.out |
| 400 | new_debug() |
| 401 | s0711489@ubuntu-lucid:~/03$ ./a.out |
| 402 | }}} |
| 403 | * gdb |
| 404 | {{{ |
| 405 | Breakpoint 1, sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:9 |
| 406 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 407 | (gdb) s |
| 408 | 14 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 409 | (gdb) |
| 410 | 23 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 411 | (gdb) |
| 412 | strncpy_from_user (dst=0xdc569f9c "new_debug()", src=0x8048646 "new_debug()", count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 413 | 114 { |
| 414 | (gdb) finish |
| 415 | Run till exit from #0 strncpy_from_user (dst=0xdc569f9c "new_debug()", src=0x8048646 "new_debug()", count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 416 | }}} |
| 417 | * [[Image(WS002512.png,33%)]] |
| 418 | |
| 419 | == len = strnlen_user == |
| 420 | * vim arch/x86/kernel/new_debug.c |
| 421 | {{{#!diff |
| 422 | Index: arch/x86/kernel/new_debug.c |
| 423 | =================================================================== |
| 424 | --- arch/x86/kernel/new_debug.c (リビジョン 1381) |
| 425 | +++ arch/x86/kernel/new_debug.c (作業コピー) |
| 426 | @@ -10,16 +10,22 @@ |
| 427 | int errno; |
| 428 | char message[__LOG_BUF_LEN]; |
| 429 | struct timespec ts; |
| 430 | + long len = 0; |
| 431 | |
| 432 | if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 433 | errno = -EFAULT; |
| 434 | goto out; |
| 435 | } |
| 436 | |
| 437 | - if (message == NULL) { |
| 438 | + if (message_user == NULL) { |
| 439 | errno = -EINVAL; |
| 440 | goto out; |
| 441 | } |
| 442 | + len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 443 | + if (len == 0 || len > __LOG_BUF_LEN) { |
| 444 | + errno = -EINVAL; |
| 445 | + goto out; |
| 446 | + } |
| 447 | if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 448 | errno = -EFAULT; |
| 449 | goto out; |
| 450 | }}} |
| 451 | |
| 452 | * windell46:i386 s0711489$ ./build |
| 453 | {{{ |
| 454 | Kernel: arch/x86/boot/bzImage is ready (#7) |
| 455 | }}} |
| 456 | |
| 457 | * s0711489@ubuntu-lucid:~$ sudo reboot |
| 458 | |
| 459 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 460 | {{{ |
| 461 | new_debug with argv[i]: Invalid argument |
| 462 | }}} |
| 463 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 464 | {{{ |
| 465 | |
| 466 | Breakpoint 1, sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:9 |
| 467 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 468 | (gdb) s |
| 469 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 470 | (gdb) |
| 471 | 20 if (message_user == NULL) { |
| 472 | (gdb) |
| 473 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 474 | (gdb) |
| 475 | strnlen_user (s=0x8048646 "new_debug()", n=262144) at arch/x86/lib/usercopy_32.c:196 |
| 476 | 196 { |
| 477 | (gdb) |
| 478 | 197 unsigned long mask = -__addr_ok(s); |
| 479 | (gdb) finish |
| 480 | Run till exit from #0 strnlen_user (s=0x8048646 "new_debug()", n=262144) at arch/x86/lib/usercopy_32.c:197 |
| 481 | |
| 482 | Program received signal SIGINT, Interrupt. |
| 483 | 0xc1332240 in __ticket_spin_lock () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/spinlock.h:65 |
| 484 | 65 asm volatile ( |
| 485 | (gdb) detach |
| 486 | Ending remote debugging. |
| 487 | }}} |
| 488 | * [[Image(WS002515.png,33%)]] |
| 489 | |
| 490 | == !__LOG_BUF_LEN 1024 == |
| 491 | * vim arch/x86/kernel/new_debug.c |
| 492 | {{{#!diff |
| 493 | Index: arch/x86/kernel/new_debug.c |
| 494 | =================================================================== |
| 495 | --- arch/x86/kernel/new_debug.c (リビジョン 1388) |
| 496 | +++ arch/x86/kernel/new_debug.c (作業コピー) |
| 497 | @@ -4,7 +4,7 @@ |
| 498 | #include <linux/time.h> |
| 499 | |
| 500 | /* from kernel/printk.c */ |
| 501 | -#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) |
| 502 | +#define __LOG_BUF_LEN 1024 |
| 503 | |
| 504 | SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 505 | int errno; |
| 506 | }}} |
| 507 | |
| 508 | * windell46:i386 s0711489$ ./build |
| 509 | {{{ |
| 510 | Kernel: arch/x86/boot/bzImage is ready (#8) |
| 511 | }}} |
| 512 | |
| 513 | * windell46:i386 s0711489$ make modules |
| 514 | |
| 515 | * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh |
| 516 | |
| 517 | * gdb |
| 518 | {{{ |
| 519 | (gdb) file vmlinux |
| 520 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 521 | (gdb) b sys_new_debug |
| 522 | Breakpoint 1 at 0xc101d8a0: file arch/x86/kernel/new_debug.c, line 9. |
| 523 | (gdb) target remote windell46:8832 |
| 524 | Remote debugging using windell46:8832 |
| 525 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 526 | 49 asm volatile("sti; hlt": : :"memory"); |
| 527 | (gdb) c |
| 528 | Continuing. |
| 529 | |
| 530 | Breakpoint 1, sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:9 |
| 531 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 532 | (gdb) l |
| 533 | 4 #include <linux/time.h> |
| 534 | 5 |
| 535 | 6 /* from kernel/printk.c */ |
| 536 | 7 #define __LOG_BUF_LEN 1024 |
| 537 | 8 |
| 538 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 539 | 10 int errno; |
| 540 | 11 char message[__LOG_BUF_LEN]; |
| 541 | 12 struct timespec ts; |
| 542 | 13 long len = 0; |
| 543 | (gdb) |
| 544 | 14 |
| 545 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 546 | 16 errno = -EFAULT; |
| 547 | 17 goto out; |
| 548 | 18 } |
| 549 | 19 |
| 550 | 20 if (message_user == NULL) { |
| 551 | 21 errno = -EINVAL; |
| 552 | 22 goto out; |
| 553 | 23 } |
| 554 | (gdb) |
| 555 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 556 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 557 | 26 errno = -EINVAL; |
| 558 | 27 goto out; |
| 559 | 28 } |
| 560 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 561 | 30 errno = -EFAULT; |
| 562 | 31 goto out; |
| 563 | 32 } |
| 564 | 33 message[sizeof(message) - 1] = '\0'; |
| 565 | (gdb) |
| 566 | 34 |
| 567 | 35 printk(KERN_DEBUG "%s\n", message); |
| 568 | 36 |
| 569 | 37 if (tp_user != NULL) { |
| 570 | 38 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 571 | 39 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 572 | 40 errno = -EFAULT; |
| 573 | 41 goto out; |
| 574 | 42 } |
| 575 | 43 } |
| 576 | (gdb) |
| 577 | 44 |
| 578 | 45 errno = 0; |
| 579 | 46 |
| 580 | 47 out: |
| 581 | 48 return errno; |
| 582 | 49 } |
| 583 | (gdb) s |
| 584 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 585 | (gdb) |
| 586 | 20 if (message_user == NULL) { |
| 587 | (gdb) |
| 588 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 589 | (gdb) |
| 590 | strnlen_user (s=0x8048646 "new_debug()", n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 591 | 196 { |
| 592 | (gdb) |
| 593 | 197 unsigned long mask = -__addr_ok(s); |
| 594 | (gdb) finish |
| 595 | Run till exit from #0 strnlen_user (s=0x8048646 "new_debug()", n=1024) at arch/x86/lib/usercopy_32.c:197 |
| 596 | sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:25 |
| 597 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 598 | Value returned is $1 = 12 |
| 599 | (gdb) s |
| 600 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 601 | (gdb) p message |
| 602 | $2 = '\000' <repeats 176 times>, "\022\002\000\000[\356U鬜\354\335,\236\354\335\060\236\354\335\064\236\354\335\070\236\354\335<\236\354\335\220\216NN\224O\377\206\002\222\374\302[\356U\351\203\002a\033\336\314}\350\002\222\374\302\b\301\261\215P\000\000\000\000\000\000\000 \000\000\000,\236\354\335L\236\354\335;^\035\301\354\235\354\335,\236\354\335b\236\354\335\250\026\367\337\331\377\377\377\000\000\000\000\000\177\300\301\000\000\000\000Ȝ\354\335\037p\000\301\020\235\354\335\223\206\004\301\254a\a\371F\000\000\000\374`\a\371F\000\000\000\374`\a\371F\000\000\000@\204\300\301@\177\300\301C\224)*\017H\017\000\000\000\000\000\034T\215\337\017H\017\000\070\235\354݄c\002\301t\235\354\335,b\004\301F\000\000\000\360S\215\337\017H\017\000\000\000\000\000R\334\070*\003\000\000\000\300\344\063\301@B\017\000\000\000\000\000@>\300\301\200\235\354\335|v\004\301@B\017\000\000\000\000\000@`\374\370F\000\000\000t\235\354\335X\235\354\335d\235\354\335\250d\001\301l\235\354\335\304f\001\301\220\235\354\335\063\352\004\301\063`\016\001\000\000\000\000\v\026\341\226w\004\000\000\200\242\v\371F\000\000\000\002\000\000\000\230"... |
| 603 | (gdb) p message_user |
| 604 | $3 = 0x8048646 "new_debug()" |
| 605 | (gdb) s |
| 606 | strncpy_from_user (dst=0xddec9b98 "", src=0x8048646 "new_debug()", count=1023) at arch/x86/lib/usercopy_32.c:114 |
| 607 | 114 { |
| 608 | (gdb) finish |
| 609 | Run till exit from #0 strncpy_from_user (dst=0xddec9b98 "", src=0x8048646 "new_debug()", count=1023) at arch/x86/lib/usercopy_32.c:114 |
| 610 | 0xc101d8f1 in sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:29 |
| 611 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 612 | Value returned is $4 = 11 |
| 613 | (gdb) p message_user |
| 614 | $5 = 0x8048646 "new_debug()" |
| 615 | (gdb) p message |
| 616 | $6 = "new_debug()", '\000' <repeats 165 times>, "\022\002\000\000[\356U鬜\354\335,\236\354\335\060\236\354\335\064\236\354\335\070\236\354\335<\236\354\335\220\216NN\224O\377\206\002\222\374\302[\356U\351\203\002a\033\336\314}\350\002\222\374\302\b\301\261\215P\000\000\000\000\000\000\000 \000\000\000,\236\354\335L\236\354\335;^\035\301\354\235\354\335,\236\354\335b\236\354\335\250\026\367\337\331\377\377\377\000\000\000\000\000\177\300\301\000\000\000\000Ȝ\354\335\037p\000\301\020\235\354\335\223\206\004\301\254a\a\371F\000\000\000\374`\a\371F\000\000\000\374`\a\371F\000\000\000@\204\300\301@\177\300\301C\224)*\017H\017\000\000\000\000\000\034T\215\337\017H\017\000\070\235\354݄c\002\301t\235\354\335,b\004\301F\000\000\000\360S\215\337\017H\017\000\000\000\000\000R\334\070*\003\000\000\000\300\344\063\301@B\017\000\000\000\000\000@>\300\301\200\235\354\335|v\004\301@B\017\000\000\000\000\000@`\374\370F\000\000\000t\235\354\335X\235\354\335d\235\354\335\250d\001\301l\235\354\335\304f\001\301\220\235\354\335\063\352\004\301\063`\016\001\000\000\000\000\v\026\341\226w"... |
| 617 | (gdb) s |
| 618 | 35 printk(KERN_DEBUG "%s\n", message); |
| 619 | (gdb) |
| 620 | 33 message[sizeof(message) - 1] = '\0'; |
| 621 | (gdb) |
| 622 | 35 printk(KERN_DEBUG "%s\n", message); |
| 623 | (gdb) n |
| 624 | 37 if (tp_user != NULL) { |
| 625 | (gdb) s |
| 626 | 49 } |
| 627 | (gdb) finish |
| 628 | Run till exit from #0 sys_new_debug (message_user=0x8048646 "new_debug()", tp_user=0x0) at arch/x86/kernel/new_debug.c:49 |
| 629 | 0xc100288c in ?? () |
| 630 | Value returned is $7 = 0 |
| 631 | (gdb) c |
| 632 | Continuing. |
| 633 | }}} |
| 634 | |
| 635 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 636 | {{{ |
| 637 | new_debug() |
| 638 | }}} |
| 639 | |
| 640 | * 期待通りの挙動を示した |
| 641 | |
| 642 | == static char message [] == |
| 643 | * vim arch/x86/kernel/new_debug.c |
| 644 | {{{#!diff |
| 645 | Index: arch/x86/kernel/new_debug.c |
| 646 | =================================================================== |
| 647 | --- arch/x86/kernel/new_debug.c (リビジョン 1388) |
| 648 | +++ arch/x86/kernel/new_debug.c (作業コピー) |
| 649 | @@ -8,7 +8,7 @@ |
| 650 | |
| 651 | SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 652 | int errno; |
| 653 | - char message[__LOG_BUF_LEN]; |
| 654 | + static char message[__LOG_BUF_LEN]; |
| 655 | struct timespec ts; |
| 656 | long len = 0; |
| 657 | |
| 658 | }}} |
| 659 | |
| 660 | * windell46:i386 s0711489$ ./build |
| 661 | {{{ |
| 662 | Kernel: arch/x86/boot/bzImage is ready (#9) |
| 663 | }}} |
| 664 | * windell46:i386 s0711489$ make modules |
| 665 | |
| 666 | * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh |
| 667 | |
| 668 | * gdb |
| 669 | {{{ |
| 670 | (gdb) file vmlinux |
| 671 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 672 | (gdb) b sys_new_debug |
| 673 | Breakpoint 1 at 0xc101d89c: file arch/x86/kernel/new_debug.c, line 9. |
| 674 | (gdb) target remote windell46:8832 |
| 675 | Remote debugging using windell46:8832 |
| 676 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 677 | 49 asm volatile("sti; hlt": : :"memory"); |
| 678 | (gdb) c |
| 679 | Continuing. |
| 680 | |
| 681 | Breakpoint 1, sys_new_debug (message_user=0xbf8b099c "1", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:9 |
| 682 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 683 | (gdb) l |
| 684 | 4 #include <linux/time.h> |
| 685 | 5 |
| 686 | 6 /* from kernel/printk.c */ |
| 687 | 7 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) |
| 688 | 8 |
| 689 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 690 | 10 int errno; |
| 691 | 11 static char message[__LOG_BUF_LEN]; |
| 692 | 12 struct timespec ts; |
| 693 | 13 long len = 0; |
| 694 | (gdb) |
| 695 | 14 |
| 696 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 697 | 16 errno = -EFAULT; |
| 698 | 17 goto out; |
| 699 | 18 } |
| 700 | 19 |
| 701 | 20 if (message_user == NULL) { |
| 702 | 21 errno = -EINVAL; |
| 703 | 22 goto out; |
| 704 | 23 } |
| 705 | (gdb) |
| 706 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 707 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 708 | 26 errno = -EINVAL; |
| 709 | 27 goto out; |
| 710 | 28 } |
| 711 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 712 | 30 errno = -EFAULT; |
| 713 | 31 goto out; |
| 714 | 32 } |
| 715 | 33 message[sizeof(message) - 1] = '\0'; |
| 716 | (gdb) |
| 717 | 34 |
| 718 | 35 printk(KERN_DEBUG "%s\n", message); |
| 719 | 36 |
| 720 | 37 if (tp_user != NULL) { |
| 721 | 38 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 722 | 39 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 723 | 40 errno = -EFAULT; |
| 724 | 41 goto out; |
| 725 | 42 } |
| 726 | 43 } |
| 727 | (gdb) |
| 728 | 44 |
| 729 | 45 errno = 0; |
| 730 | 46 |
| 731 | 47 out: |
| 732 | 48 return errno; |
| 733 | 49 } |
| 734 | (gdb) s |
| 735 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 736 | (gdb) |
| 737 | 20 if (message_user == NULL) { |
| 738 | (gdb) |
| 739 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 740 | (gdb) |
| 741 | strnlen_user (s=0xbf8b099c "1", n=262144) at arch/x86/lib/usercopy_32.c:196 |
| 742 | 196 { |
| 743 | (gdb) finish |
| 744 | Run till exit from #0 strnlen_user (s=0xbf8b099c "1", n=262144) at arch/x86/lib/usercopy_32.c:196 |
| 745 | sys_new_debug (message_user=0xbf8b099c "1", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:25 |
| 746 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 747 | Value returned is $1 = 2 |
| 748 | (gdb) s |
| 749 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 750 | (gdb) |
| 751 | strncpy_from_user (dst=0xc158da00 "fuga", src=0xbf8b099c "1", count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 752 | 114 { |
| 753 | (gdb) finish |
| 754 | Run till exit from #0 strncpy_from_user (dst=0xc158da00 "fuga", src=0xbf8b099c "1", count=262143) at arch/x86/lib/usercopy_32.c:114 |
| 755 | 0xc101d8ea in sys_new_debug (message_user=0xbf8b099c "1", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:29 |
| 756 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 757 | Value returned is $2 = 1 |
| 758 | (gdb) s |
| 759 | 35 printk(KERN_DEBUG "%s\n", message); |
| 760 | (gdb) |
| 761 | 33 message[sizeof(message) - 1] = '\0'; |
| 762 | (gdb) |
| 763 | 35 printk(KERN_DEBUG "%s\n", message); |
| 764 | (gdb) p message |
| 765 | $3 = "1\000ga\000ebug()", '\000' <repeats 262132 times> |
| 766 | (gdb) n |
| 767 | 37 if (tp_user != NULL) { |
| 768 | (gdb) s |
| 769 | 38 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 770 | (gdb) p ts |
| 771 | $4 = {tv_sec = -598564864, tv_nsec = -1217056780} |
| 772 | (gdb) n |
| 773 | 39 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 774 | (gdb) p ts |
| 775 | $5 = {tv_sec = -598564864, tv_nsec = -1217056780} |
| 776 | (gdb) n |
| 777 | 49 } |
| 778 | (gdb) p ts_user |
| 779 | No symbol "ts_user" in current context. |
| 780 | (gdb) p tp_ |
| 781 | tp_event tp_perf_event_destroy tp_probes tp_user |
| 782 | (gdb) p tp_user |
| 783 | $6 = (struct timespec *) 0xbf8af014 |
| 784 | (gdb) p errno |
| 785 | $7 = 0 |
| 786 | (gdb) finish |
| 787 | Run till exit from #0 sys_new_debug (message_user=0xbf8b099c "1", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:49 |
| 788 | 0xc100288c in ?? () |
| 789 | Value returned is $8 = 0 |
| 790 | (gdb) c |
| 791 | Continuing. |
| 792 | |
| 793 | Breakpoint 1, sys_new_debug (message_user=0xbf8b099e "2", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:9 |
| 794 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 795 | (gdb) c |
| 796 | Continuing. |
| 797 | |
| 798 | Breakpoint 1, sys_new_debug (message_user=0xbf8b09a0 "3", tp_user=0xbf8af014) at arch/x86/kernel/new_debug.c:9 |
| 799 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 800 | (gdb) c |
| 801 | Continuing. |
| 802 | |
| 803 | Breakpoint 1, sys_new_debug (message_user=0xbfc1e99c "1", tp_user=0xbfc1d654) at arch/x86/kernel/new_debug.c:9 |
| 804 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 805 | (gdb) c |
| 806 | Continuing. |
| 807 | |
| 808 | Breakpoint 1, sys_new_debug (message_user=0xbfc1e99e "2", tp_user=0xbfc1d654) at arch/x86/kernel/new_debug.c:9 |
| 809 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 810 | (gdb) s |
| 811 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 812 | (gdb) |
| 813 | 20 if (message_user == NULL) { |
| 814 | (gdb) n |
| 815 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 816 | (gdb) |
| 817 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 818 | (gdb) |
| 819 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 820 | (gdb) |
| 821 | 35 printk(KERN_DEBUG "%s\n", message); |
| 822 | (gdb) |
| 823 | 33 message[sizeof(message) - 1] = '\0'; |
| 824 | (gdb) |
| 825 | 35 printk(KERN_DEBUG "%s\n", message); |
| 826 | (gdb) |
| 827 | 37 if (tp_user != NULL) { |
| 828 | (gdb) p tp_user |
| 829 | $9 = (struct timespec *) 0xbfc1d654 |
| 830 | (gdb) p ts |
| 831 | $10 = {tv_sec = 0, tv_nsec = 0} |
| 832 | (gdb) n |
| 833 | 38 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 834 | (gdb) |
| 835 | 39 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 836 | (gdb) |
| 837 | 49 } |
| 838 | (gdb) finish |
| 839 | Run till exit from #0 sys_new_debug (message_user=0xbfc1e99e "2", tp_user=0xbfc1d654) at arch/x86/kernel/new_debug.c:49 |
| 840 | 0xc100288c in ?? () |
| 841 | Value returned is $11 = 0 |
| 842 | (gdb) c |
| 843 | Continuing. |
| 844 | |
| 845 | Breakpoint 1, sys_new_debug (message_user=0xbfc1e9a0 "3", tp_user=0xbfc1d654) at arch/x86/kernel/new_debug.c:9 |
| 846 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 847 | (gdb) c |
| 848 | Continuing. |
| 849 | }}} |
| 850 | |
| 851 | * s0711489@ubuntu-lucid:~/03$ ./a.out hoge fuga |
| 852 | {{{ |
| 853 | [-598562624.-1216589836] hoge |
| 854 | [0.000000000] fuga |
| 855 | }}} |
| 856 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 3 |
| 857 | {{{ |
| 858 | [-598564864.-1217056780] 1 |
| 859 | [0.000000000] 2 |
| 860 | [0.000000000] 3 |
| 861 | }}} |
| 862 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 3 |
| 863 | {{{ |
| 864 | [-598564864.-1215885324] 1 |
| 865 | [0.000000000] 2 |
| 866 | [0.000000000] 3 |
| 867 | }}} |
| 868 | |
| 869 | * こちらも問題無く動作した |
| 870 | |
| 871 | == very long argument == |
| 872 | * gdb |
| 873 | {{{ |
| 874 | (gdb) target remote windell46:8832 |
| 875 | Remote debugging using windell46:8832 |
| 876 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 877 | 49 asm volatile("sti; hlt": : :"memory"); |
| 878 | (gdb) c |
| 879 | Continuing. |
| 880 | |
| 881 | Breakpoint 1, sys_new_debug (message_user=0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfcf62d4) |
| 882 | at arch/x86/kernel/new_debug.c:9 |
| 883 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 884 | (gdb) s |
| 885 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 886 | (gdb) |
| 887 | 20 if (message_user == NULL) { |
| 888 | (gdb) p message |
| 889 | $12 = '\000' <repeats 262143 times> |
| 890 | (gdb) p message_user |
| 891 | $13 = 0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"... |
| 892 | (gdb) p tp_user |
| 893 | $14 = (struct timespec *) 0xbfcf62d4 |
| 894 | (gdb) s |
| 895 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 896 | (gdb) p len |
| 897 | $15 = <value optimized out> |
| 898 | (gdb) n |
| 899 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 900 | (gdb) s |
| 901 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 902 | (gdb) |
| 903 | strncpy_from_user (dst=0xc158da00 "", src=0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., count=262143) |
| 904 | at arch/x86/lib/usercopy_32.c:114 |
| 905 | 114 { |
| 906 | (gdb) finish |
| 907 | Run till exit from #0 strncpy_from_user (dst=0xc158da00 "", src=0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., count=262143) |
| 908 | at arch/x86/lib/usercopy_32.c:114 |
| 909 | 0xc101d8ea in sys_new_debug (message_user=0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfcf62d4) |
| 910 | at arch/x86/kernel/new_debug.c:29 |
| 911 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 912 | Value returned is $16 = 5000 |
| 913 | (gdb) p message |
| 914 | $17 = '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "2", '0' <repeats 99 times>, "3", '0' <repeats 99 times>, "4", '0' <repeats 99 times>, "5", '0' <repeats 99 times>, "6", '0' <repeats 99 times>, "7", '0' <repeats 99 times>, "8", '0' <repeats 99 times>, "9", '0' <repeats 98 times>, "1", '0' <repeats 99 times>, "11", '0' <repeats 98 times>, "12", '0' <repeats 98 times>, "13", '0' <repeats 98 times>, "14", '0' <repeats 98 times>, "15", '0' <repeats 98 times>, "16", '0' <repeats 98 times>, "17", '0' <repeats 98 times>... |
| 915 | (gdb) s |
| 916 | 35 printk(KERN_DEBUG "%s\n", message); |
| 917 | (gdb) n |
| 918 | 33 message[sizeof(message) - 1] = '\0'; |
| 919 | (gdb) p sizeof(message) |
| 920 | $18 = 262144 |
| 921 | (gdb) n |
| 922 | 35 printk(KERN_DEBUG "%s\n", message); |
| 923 | (gdb) |
| 924 | 37 if (tp_user != NULL) { |
| 925 | (gdb) |
| 926 | 38 sys_clock_gettime(CLOCK_REALTIME, &ts); |
| 927 | (gdb) p ts |
| 928 | $19 = {tv_sec = -598614528, tv_nsec = -1216688140} |
| 929 | (gdb) n |
| 930 | 39 if (copy_to_user(tp_user, &ts, sizeof(ts)) != 0) { |
| 931 | (gdb) |
| 932 | 49 } |
| 933 | (gdb) finish |
| 934 | Run till exit from #0 sys_new_debug (message_user=0xbfcf7619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfcf62d4) |
| 935 | at arch/x86/kernel/new_debug.c:49 |
| 936 | 0xc100288c in ?? () |
| 937 | Value returned is $20 = 0 |
| 938 | (gdb) c |
| 939 | Continuing. |
| 940 | }}} |
| 941 | |
| 942 | * s0711489@ubuntu-lucid:~/03$ ./a.out 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000 |
| 943 | {{{ |
| 944 | [-598614528.-1216688140] 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000 |
| 945 | }}} |
| 946 | * s0711489@ubuntu-lucid:~/03$ dmesg | tail -n 2 |
| 947 | {{{ |
| 948 | [ 6.197442] vmblock: version magic '2.6.32-33-generic SMP mod_unload modversions 586 ' should be '2.6.35.14 SMP mod_unload 686 ' |
| 949 | [ 276.962399] 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000 |
| 950 | }}} |
| 951 | |
| 952 | * printk() |
| 953 | {{{ |
| 954 | Breakpoint 1, sys_new_debug (message_user=0xbfee1619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfedfda4) |
| 955 | at arch/x86/kernel/new_debug.c:9 |
| 956 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 957 | (gdb) n |
| 958 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 959 | (gdb) |
| 960 | 20 if (message_user == NULL) { |
| 961 | (gdb) |
| 962 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 963 | (gdb) |
| 964 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 965 | (gdb) |
| 966 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 967 | (gdb) |
| 968 | 35 printk(KERN_DEBUG "%s\n", message); |
| 969 | (gdb) s |
| 970 | 33 message[sizeof(message) - 1] = '\0'; |
| 971 | (gdb) |
| 972 | 35 printk(KERN_DEBUG "%s\n", message); |
| 973 | (gdb) |
| 974 | printk (fmt=0xc1449542 "<7>%s\n") at kernel/printk.c:614 |
| 975 | 614 va_start(args, fmt); |
| 976 | (gdb) finish |
| 977 | Run till exit from #0 printk (fmt=0xc1449542 "<7>%s\n") at kernel/printk.c:614 |
| 978 | sys_new_debug (message_user=0xbfee1619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfedfda4) |
| 979 | at arch/x86/kernel/new_debug.c:37 |
| 980 | 37 if (tp_user != NULL) { |
| 981 | Value returned is $21 = 1041 |
| 982 | (gdb) |
| 983 | Run till exit from #0 sys_new_debug (message_user=0xbfee1619 '0' <repeats 97 times>, "1", '0' <repeats 99 times>, "200"..., tp_user=0xbfedfda4) |
| 984 | at arch/x86/kernel/new_debug.c:37 |
| 985 | 0xc100288c in ?? () |
| 986 | Value returned is $22 = 0 |
| 987 | (gdb) c |
| 988 | Continuing. |
| 989 | }}} |
| 990 | |
| 991 | == shorten message[] == |
| 992 | * printk()は1020文字程度しか出力してくれない(Ubuntu 10.04 i386)ので、バッファイサイズをずっと短くする |
| 993 | |
| 994 | * vim arch/x86/kernel/new_debug.c |
| 995 | {{{#!diff |
| 996 | Index: arch/x86/kernel/new_debug.c |
| 997 | =================================================================== |
| 998 | --- arch/x86/kernel/new_debug.c (リビジョン 1389) |
| 999 | +++ arch/x86/kernel/new_debug.c (作業コピー) |
| 1000 | @@ -4,7 +4,7 @@ |
| 1001 | #include <linux/time.h> |
| 1002 | |
| 1003 | /* from kernel/printk.c */ |
| 1004 | -#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) |
| 1005 | +#define __LOG_BUF_LEN 1024 |
| 1006 | |
| 1007 | SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1008 | int errno; |
| 1009 | }}} |
| 1010 | |
| 1011 | * windell46:i386 s0711489$ ./build |
| 1012 | {{{ |
| 1013 | Kernel: arch/x86/boot/bzImage is ready (#11) |
| 1014 | }}} |
| 1015 | * windell46:i386 s0711489$ make modules |
| 1016 | |
| 1017 | * s0711489@ubuntu-lucid:~$ sudo /mnt/hgfs/tools/install.sh |
| 1018 | |
| 1019 | * s0711489@ubuntu-lucid:~/03$ ./a.out |
| 1020 | {{{ |
| 1021 | new_debug() |
| 1022 | }}} |
| 1023 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 3 4 |
| 1024 | {{{ |
| 1025 | [-572681344.-1217335308] 1 |
| 1026 | [0.000000000] 2 |
| 1027 | [0.000000000] 3 |
| 1028 | [0.000000000] 4 |
| 1029 | }}} |
| 1030 | * s0711489@ubuntu-lucid:~/03$ ./a.out 1 2 3 4 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020123 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000201234 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000002012345 |
| 1031 | {{{ |
| 1032 | [-572680448.-1215909900] 1 |
| 1033 | [0.000000000] 2 |
| 1034 | [0.000000000] 3 |
| 1035 | [0.000000000] 4 |
| 1036 | [0.000000000] 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000 |
| 1037 | [0.000000000] 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020 |
| 1038 | [0.000000000] 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020123 |
| 1039 | new_debug with argv[i]: Invalid argument |
| 1040 | new_debug with argv[i]: Invalid argument |
| 1041 | }}} |
| 1042 | |
| 1043 | * gdb |
| 1044 | {{{ |
| 1045 | (gdb) file vmlinux |
| 1046 | Reading symbols from /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/vmlinux...(no debugging symbols found)...done. |
| 1047 | b sys_new_debug |
| 1048 | (gdb) b sys_new_debug |
| 1049 | Breakpoint 1 at 0xc101d89c: file arch/x86/kernel/new_debug.c, line 9. |
| 1050 | (gdb) target remote windell46:8832 |
| 1051 | Remote debugging using windell46:8832 |
| 1052 | 0xc1007cdf in native_safe_halt () at /home/ugrad/07/s0711489/coursework/KernelHack/linux-2.6.35.14/i386/arch/x86/include/asm/irqflags.h:49 |
| 1053 | 49 asm volatile("sti; hlt": : :"memory"); |
| 1054 | (gdb) c |
| 1055 | Continuing. |
| 1056 | |
| 1057 | Breakpoint 1, sys_new_debug (message_user=0xbfa735b9 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:9 |
| 1058 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1059 | (gdb) n |
| 1060 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 1061 | (gdb) |
| 1062 | 20 if (message_user == NULL) { |
| 1063 | (gdb) |
| 1064 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1065 | (gdb) s |
| 1066 | strnlen_user (s=0xbfa735b9 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1067 | 196 { |
| 1068 | (gdb) finish |
| 1069 | Run till exit from #0 strnlen_user (s=0xbfa735b9 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1070 | sys_new_debug (message_user=0xbfa735b9 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:25 |
| 1071 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1072 | Value returned is $1 = 1001 |
| 1073 | (gdb) c |
| 1074 | Continuing. |
| 1075 | |
| 1076 | Breakpoint 1, sys_new_debug (message_user=0xbfa739a2 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:9 |
| 1077 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1078 | (gdb) n |
| 1079 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 1080 | (gdb) |
| 1081 | 20 if (message_user == NULL) { |
| 1082 | (gdb) |
| 1083 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1084 | (gdb) s |
| 1085 | strnlen_user (s=0xbfa739a2 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1086 | 196 { |
| 1087 | (gdb) finish |
| 1088 | Run till exit from #0 strnlen_user (s=0xbfa739a2 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1089 | sys_new_debug (message_user=0xbfa739a2 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:25 |
| 1090 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1091 | Value returned is $2 = 1021 |
| 1092 | (gdb) s |
| 1093 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 1094 | (gdb) |
| 1095 | strncpy_from_user (dst=0xc158da00 '0' <repeats 200 times>..., src=0xbfa739a2 '0' <repeats 200 times>..., count=1023) at arch/x86/lib/usercopy_32.c:114 |
| 1096 | 114 { |
| 1097 | (gdb) finish |
| 1098 | Run till exit from #0 strncpy_from_user (dst=0xc158da00 '0' <repeats 200 times>..., src=0xbfa739a2 '0' <repeats 200 times>..., count=1023) |
| 1099 | at arch/x86/lib/usercopy_32.c:114 |
| 1100 | 0xc101d8ea in sys_new_debug (message_user=0xbfa739a2 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:29 |
| 1101 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 1102 | Value returned is $3 = 1020 |
| 1103 | (gdb) c |
| 1104 | Continuing. |
| 1105 | |
| 1106 | Breakpoint 1, sys_new_debug (message_user=0xbfa73d9f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:9 |
| 1107 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1108 | (gdb) n |
| 1109 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 1110 | (gdb) |
| 1111 | 20 if (message_user == NULL) { |
| 1112 | (gdb) |
| 1113 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1114 | (gdb) s |
| 1115 | strnlen_user (s=0xbfa73d9f '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1116 | 196 { |
| 1117 | (gdb) finish |
| 1118 | Run till exit from #0 strnlen_user (s=0xbfa73d9f '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1119 | sys_new_debug (message_user=0xbfa73d9f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:25 |
| 1120 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1121 | Value returned is $4 = 1024 |
| 1122 | (gdb) s |
| 1123 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 1124 | (gdb) |
| 1125 | strncpy_from_user (dst=0xc158da00 '0' <repeats 200 times>..., src=0xbfa73d9f '0' <repeats 200 times>..., count=1023) at arch/x86/lib/usercopy_32.c:114 |
| 1126 | 114 { |
| 1127 | (gdb) finish |
| 1128 | Run till exit from #0 strncpy_from_user (dst=0xc158da00 '0' <repeats 200 times>..., src=0xbfa73d9f '0' <repeats 200 times>..., count=1023) |
| 1129 | at arch/x86/lib/usercopy_32.c:114 |
| 1130 | 0xc101d8ea in sys_new_debug (message_user=0xbfa73d9f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:29 |
| 1131 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 1132 | Value returned is $5 = 1023 |
| 1133 | (gdb) c |
| 1134 | Continuing. |
| 1135 | |
| 1136 | Breakpoint 1, sys_new_debug (message_user=0xbfa7419f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:9 |
| 1137 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1138 | (gdb) n |
| 1139 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 1140 | (gdb) |
| 1141 | 20 if (message_user == NULL) { |
| 1142 | (gdb) |
| 1143 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1144 | (gdb) s |
| 1145 | strnlen_user (s=0xbfa7419f '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1146 | 196 { |
| 1147 | (gdb) finish |
| 1148 | Run till exit from #0 strnlen_user (s=0xbfa7419f '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1149 | sys_new_debug (message_user=0xbfa7419f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:25 |
| 1150 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1151 | Value returned is $6 = 1025 |
| 1152 | (gdb) s |
| 1153 | 49 } |
| 1154 | (gdb) l 25 |
| 1155 | 20 if (message_user == NULL) { |
| 1156 | 21 errno = -EINVAL; |
| 1157 | 22 goto out; |
| 1158 | 23 } |
| 1159 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1160 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1161 | 26 errno = -EINVAL; |
| 1162 | 27 goto out; |
| 1163 | 28 } |
| 1164 | 29 if (strncpy_from_user(message, message_user, sizeof(message) - 1) < 0) { |
| 1165 | (gdb) p errno |
| 1166 | $7 = -22 |
| 1167 | (gdb) finish |
| 1168 | Run till exit from #0 sys_new_debug (message_user=0xbfa7419f '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:49 |
| 1169 | 0xc100288c in ?? () |
| 1170 | Value returned is $8 = -22 |
| 1171 | (gdb) c |
| 1172 | Continuing. |
| 1173 | |
| 1174 | Breakpoint 1, sys_new_debug (message_user=0xbfa745a0 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:9 |
| 1175 | 9 SYSCALL_DEFINE2(new_debug, const char *, message_user, struct timespec*, tp_user) { |
| 1176 | (gdb) n |
| 1177 | 15 if(tp_user != NULL && ! access_ok(VERIFY_WRITE, tp_user, sizeof(*tp_user)) ) { |
| 1178 | (gdb) |
| 1179 | 20 if (message_user == NULL) { |
| 1180 | (gdb) |
| 1181 | 24 len = strnlen_user(message_user, __LOG_BUF_LEN); |
| 1182 | (gdb) s |
| 1183 | strnlen_user (s=0xbfa745a0 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1184 | 196 { |
| 1185 | (gdb) finish |
| 1186 | Run till exit from #0 strnlen_user (s=0xbfa745a0 '0' <repeats 200 times>..., n=1024) at arch/x86/lib/usercopy_32.c:196 |
| 1187 | sys_new_debug (message_user=0xbfa745a0 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:25 |
| 1188 | 25 if (len == 0 || len > __LOG_BUF_LEN) { |
| 1189 | Value returned is $9 = 1025 |
| 1190 | (gdb) s |
| 1191 | 49 } |
| 1192 | (gdb) p errno |
| 1193 | $10 = -22 |
| 1194 | (gdb) finish |
| 1195 | Run till exit from #0 sys_new_debug (message_user=0xbfa745a0 '0' <repeats 200 times>..., tp_user=0xbfa716a4) at arch/x86/kernel/new_debug.c:49 |
| 1196 | 0xc100288c in ?? () |
| 1197 | Value returned is $11 = -22 |
| 1198 | (gdb) c |
| 1199 | Continuing. |
| 1200 | }}} |
| 1201 | * s0711489@ubuntu-lucid:~/03$ ./a.out 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020123 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000201234 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000002012345 |
| 1202 | {{{ |
| 1203 | [-593455808.-1216405516] 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000 |
| 1204 | [0.000000000] 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020 |
| 1205 | [0.000000000] 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000020123 |
| 1206 | new_debug with argv[i]: Invalid argument |
| 1207 | new_debug with argv[i]: Invalid argument |
| 1208 | }}} |