aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAndi Kleen <ak@suse.de>2006-12-06 20:14:06 -0500
committerAndi Kleen <andi@basil.nowhere.org>2006-12-06 20:14:06 -0500
commit11a4180c0b03e2ee0c948fd8430ee092dc1625b3 (patch)
treec0f5018983f859d84b0832ea793ba0c49d344935 /arch
parentab2bf0c1c689905b628dca94d0acd9c50e152468 (diff)
[PATCH] i386: Use probe_kernel_address instead of __get_user in fault paths
Makes the intention of the code cleaner to read and avoids a potential deadlock on mmap_sem. Also change the types of the arguments to not include __user because they're really not user addresses. Signed-off-by: Andi Kleen <ak@suse.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/kernel/traps.c24
-rw-r--r--arch/i386/mm/fault.c12
2 files changed, 19 insertions, 17 deletions
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index 237f4884a1e1..7b2f9f022089 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -380,7 +380,7 @@ void show_registers(struct pt_regs *regs)
380 * time of the fault.. 380 * time of the fault..
381 */ 381 */
382 if (in_kernel) { 382 if (in_kernel) {
383 u8 __user *eip; 383 u8 *eip;
384 int code_bytes = 64; 384 int code_bytes = 64;
385 unsigned char c; 385 unsigned char c;
386 386
@@ -389,18 +389,20 @@ void show_registers(struct pt_regs *regs)
389 389
390 printk(KERN_EMERG "Code: "); 390 printk(KERN_EMERG "Code: ");
391 391
392 eip = (u8 __user *)regs->eip - 43; 392 eip = (u8 *)regs->eip - 43;
393 if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) { 393 if (eip < (u8 *)PAGE_OFFSET ||
394 probe_kernel_address(eip, c)) {
394 /* try starting at EIP */ 395 /* try starting at EIP */
395 eip = (u8 __user *)regs->eip; 396 eip = (u8 *)regs->eip;
396 code_bytes = 32; 397 code_bytes = 32;
397 } 398 }
398 for (i = 0; i < code_bytes; i++, eip++) { 399 for (i = 0; i < code_bytes; i++, eip++) {
399 if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) { 400 if (eip < (u8 *)PAGE_OFFSET ||
401 probe_kernel_address(eip, c)) {
400 printk(" Bad EIP value."); 402 printk(" Bad EIP value.");
401 break; 403 break;
402 } 404 }
403 if (eip == (u8 __user *)regs->eip) 405 if (eip == (u8 *)regs->eip)
404 printk("<%02x> ", c); 406 printk("<%02x> ", c);
405 else 407 else
406 printk("%02x ", c); 408 printk("%02x ", c);
@@ -416,7 +418,7 @@ static void handle_BUG(struct pt_regs *regs)
416 418
417 if (eip < PAGE_OFFSET) 419 if (eip < PAGE_OFFSET)
418 return; 420 return;
419 if (probe_kernel_address((unsigned short __user *)eip, ud2)) 421 if (probe_kernel_address((unsigned short *)eip, ud2))
420 return; 422 return;
421 if (ud2 != 0x0b0f) 423 if (ud2 != 0x0b0f)
422 return; 424 return;
@@ -429,11 +431,11 @@ static void handle_BUG(struct pt_regs *regs)
429 char *file; 431 char *file;
430 char c; 432 char c;
431 433
432 if (probe_kernel_address((unsigned short __user *)(eip + 2), 434 if (probe_kernel_address((unsigned short *)(eip + 2), line))
433 line))
434 break; 435 break;
435 if (__get_user(file, (char * __user *)(eip + 4)) || 436 if (probe_kernel_address((char **)(eip + 4), file) ||
436 (unsigned long)file < PAGE_OFFSET || __get_user(c, file)) 437 (unsigned long)file < PAGE_OFFSET ||
438 probe_kernel_address(file, c))
437 file = "<bad filename>"; 439 file = "<bad filename>";
438 440
439 printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line); 441 printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
diff --git a/arch/i386/mm/fault.c b/arch/i386/mm/fault.c
index 2581575786c1..aaaa4d225f7e 100644
--- a/arch/i386/mm/fault.c
+++ b/arch/i386/mm/fault.c
@@ -22,9 +22,9 @@
22#include <linux/highmem.h> 22#include <linux/highmem.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/kprobes.h> 24#include <linux/kprobes.h>
25#include <linux/uaccess.h>
25 26
26#include <asm/system.h> 27#include <asm/system.h>
27#include <asm/uaccess.h>
28#include <asm/desc.h> 28#include <asm/desc.h>
29#include <asm/kdebug.h> 29#include <asm/kdebug.h>
30#include <asm/segment.h> 30#include <asm/segment.h>
@@ -167,7 +167,7 @@ static inline unsigned long get_segment_eip(struct pt_regs *regs,
167static int __is_prefetch(struct pt_regs *regs, unsigned long addr) 167static int __is_prefetch(struct pt_regs *regs, unsigned long addr)
168{ 168{
169 unsigned long limit; 169 unsigned long limit;
170 unsigned long instr = get_segment_eip (regs, &limit); 170 unsigned char *instr = (unsigned char *)get_segment_eip (regs, &limit);
171 int scan_more = 1; 171 int scan_more = 1;
172 int prefetch = 0; 172 int prefetch = 0;
173 int i; 173 int i;
@@ -177,9 +177,9 @@ static int __is_prefetch(struct pt_regs *regs, unsigned long addr)
177 unsigned char instr_hi; 177 unsigned char instr_hi;
178 unsigned char instr_lo; 178 unsigned char instr_lo;
179 179
180 if (instr > limit) 180 if (instr > (unsigned char *)limit)
181 break; 181 break;
182 if (__get_user(opcode, (unsigned char __user *) instr)) 182 if (probe_kernel_address(instr, opcode))
183 break; 183 break;
184 184
185 instr_hi = opcode & 0xf0; 185 instr_hi = opcode & 0xf0;
@@ -204,9 +204,9 @@ static int __is_prefetch(struct pt_regs *regs, unsigned long addr)
204 case 0x00: 204 case 0x00:
205 /* Prefetch instruction is 0x0F0D or 0x0F18 */ 205 /* Prefetch instruction is 0x0F0D or 0x0F18 */
206 scan_more = 0; 206 scan_more = 0;
207 if (instr > limit) 207 if (instr > (unsigned char *)limit)
208 break; 208 break;
209 if (__get_user(opcode, (unsigned char __user *) instr)) 209 if (probe_kernel_address(instr, opcode))
210 break; 210 break;
211 prefetch = (instr_lo == 0xF) && 211 prefetch = (instr_lo == 0xF) &&
212 (opcode == 0x0D || opcode == 0x18); 212 (opcode == 0x0D || opcode == 0x18);