Commit 25f12ae4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

maccess: rename probe_kernel_address to get_kernel_nofault

Better describe what this helper does, and match the naming of
copy_from_kernel_nofault.

Also switch the argument order around, so that it acts and looks
like get_user().
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c0ee37e8
...@@ -396,7 +396,7 @@ int is_valid_bugaddr(unsigned long pc) ...@@ -396,7 +396,7 @@ int is_valid_bugaddr(unsigned long pc)
u32 insn = __opcode_to_mem_arm(BUG_INSTR_VALUE); u32 insn = __opcode_to_mem_arm(BUG_INSTR_VALUE);
#endif #endif
if (probe_kernel_address((unsigned *)pc, bkpt)) if (get_kernel_nofault(bkpt, (unsigned *)pc))
return 0; return 0;
return bkpt == insn; return bkpt == insn;
......
...@@ -774,7 +774,7 @@ static int alignment_get_arm(struct pt_regs *regs, u32 *ip, u32 *inst) ...@@ -774,7 +774,7 @@ static int alignment_get_arm(struct pt_regs *regs, u32 *ip, u32 *inst)
if (user_mode(regs)) if (user_mode(regs))
fault = get_user(instr, ip); fault = get_user(instr, ip);
else else
fault = probe_kernel_address(ip, instr); fault = get_kernel_nofault(instr, ip);
*inst = __mem_to_opcode_arm(instr); *inst = __mem_to_opcode_arm(instr);
...@@ -789,7 +789,7 @@ static int alignment_get_thumb(struct pt_regs *regs, u16 *ip, u16 *inst) ...@@ -789,7 +789,7 @@ static int alignment_get_thumb(struct pt_regs *regs, u16 *ip, u16 *inst)
if (user_mode(regs)) if (user_mode(regs))
fault = get_user(instr, ip); fault = get_user(instr, ip);
else else
fault = probe_kernel_address(ip, instr); fault = get_kernel_nofault(instr, ip);
*inst = __mem_to_opcode_thumb16(instr); *inst = __mem_to_opcode_thumb16(instr);
......
...@@ -376,7 +376,7 @@ static int call_undef_hook(struct pt_regs *regs) ...@@ -376,7 +376,7 @@ static int call_undef_hook(struct pt_regs *regs)
if (!user_mode(regs)) { if (!user_mode(regs)) {
__le32 instr_le; __le32 instr_le;
if (probe_kernel_address((__force __le32 *)pc, instr_le)) if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
goto exit; goto exit;
instr = le32_to_cpu(instr_le); instr = le32_to_cpu(instr_le);
} else if (compat_thumb_mode(regs)) { } else if (compat_thumb_mode(regs)) {
......
...@@ -35,7 +35,7 @@ static inline void *dereference_function_descriptor(void *ptr) ...@@ -35,7 +35,7 @@ static inline void *dereference_function_descriptor(void *ptr)
struct fdesc *desc = ptr; struct fdesc *desc = ptr;
void *p; void *p;
if (!probe_kernel_address(&desc->ip, p)) if (!get_kernel_nofault(p, &desc->ip))
ptr = p; ptr = p;
return ptr; return ptr;
} }
......
...@@ -293,7 +293,7 @@ void *dereference_function_descriptor(void *ptr) ...@@ -293,7 +293,7 @@ void *dereference_function_descriptor(void *ptr)
Elf64_Fdesc *desc = ptr; Elf64_Fdesc *desc = ptr;
void *p; void *p;
if (!probe_kernel_address(&desc->addr, p)) if (!get_kernel_nofault(p, &desc->addr))
ptr = p; ptr = p;
return ptr; return ptr;
} }
......
...@@ -85,7 +85,7 @@ static inline void *dereference_function_descriptor(void *ptr) ...@@ -85,7 +85,7 @@ static inline void *dereference_function_descriptor(void *ptr)
struct ppc64_opd_entry *desc = ptr; struct ppc64_opd_entry *desc = ptr;
void *p; void *p;
if (!probe_kernel_address(&desc->funcaddr, p)) if (!get_kernel_nofault(p, &desc->funcaddr))
ptr = p; ptr = p;
return ptr; return ptr;
} }
......
...@@ -421,7 +421,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) ...@@ -421,7 +421,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
unsigned int instr; unsigned int instr;
struct ppc_inst *addr = (struct ppc_inst *)bpt->bpt_addr; struct ppc_inst *addr = (struct ppc_inst *)bpt->bpt_addr;
err = probe_kernel_address(addr, instr); err = get_kernel_nofault(instr, addr);
if (err) if (err)
return err; return err;
......
...@@ -289,7 +289,7 @@ int kprobe_handler(struct pt_regs *regs) ...@@ -289,7 +289,7 @@ int kprobe_handler(struct pt_regs *regs)
if (!p) { if (!p) {
unsigned int instr; unsigned int instr;
if (probe_kernel_address(addr, instr)) if (get_kernel_nofault(instr, addr))
goto no_kprobe; goto no_kprobe;
if (instr != BREAKPOINT_INSTRUCTION) { if (instr != BREAKPOINT_INSTRUCTION) {
......
...@@ -1271,7 +1271,7 @@ static void show_instructions(struct pt_regs *regs) ...@@ -1271,7 +1271,7 @@ static void show_instructions(struct pt_regs *regs)
#endif #endif
if (!__kernel_text_address(pc) || if (!__kernel_text_address(pc) ||
probe_kernel_address((const void *)pc, instr)) { get_kernel_nofault(instr, (const void *)pc)) {
pr_cont("XXXXXXXX "); pr_cont("XXXXXXXX ");
} else { } else {
if (regs->nip == pc) if (regs->nip == pc)
......
...@@ -1069,7 +1069,7 @@ int fsl_pci_mcheck_exception(struct pt_regs *regs) ...@@ -1069,7 +1069,7 @@ int fsl_pci_mcheck_exception(struct pt_regs *regs)
ret = copy_from_user_nofault(&inst, ret = copy_from_user_nofault(&inst,
(void __user *)regs->nip, sizeof(inst)); (void __user *)regs->nip, sizeof(inst));
else else
ret = probe_kernel_address((void *)regs->nip, inst); ret = get_kernel_nofault(inst, (void *)regs->nip);
if (!ret && mcheck_handle_load(regs, inst)) { if (!ret && mcheck_handle_load(regs, inst)) {
regs->nip += 4; regs->nip += 4;
......
...@@ -62,7 +62,7 @@ int get_step_address(struct pt_regs *regs, unsigned long *next_addr) ...@@ -62,7 +62,7 @@ int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
unsigned int rs1_num, rs2_num; unsigned int rs1_num, rs2_num;
int op_code; int op_code;
if (probe_kernel_address((void *)pc, op_code)) if (get_kernel_nofault(op_code, (void *)pc))
return -EINVAL; return -EINVAL;
if ((op_code & __INSN_LENGTH_MASK) != __INSN_LENGTH_GE_32) { if ((op_code & __INSN_LENGTH_MASK) != __INSN_LENGTH_GE_32) {
if (is_c_jalr_insn(op_code) || is_c_jr_insn(op_code)) { if (is_c_jalr_insn(op_code) || is_c_jr_insn(op_code)) {
...@@ -146,7 +146,7 @@ int do_single_step(struct pt_regs *regs) ...@@ -146,7 +146,7 @@ int do_single_step(struct pt_regs *regs)
return error; return error;
/* Store the op code in the stepped address */ /* Store the op code in the stepped address */
error = probe_kernel_address((void *)addr, stepped_opcode); error = get_kernel_nofault(stepped_opcode, (void *)addr);
if (error) if (error)
return error; return error;
......
...@@ -137,7 +137,7 @@ static inline unsigned long get_break_insn_length(unsigned long pc) ...@@ -137,7 +137,7 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
{ {
bug_insn_t insn; bug_insn_t insn;
if (probe_kernel_address((bug_insn_t *)pc, insn)) if (get_kernel_nofault(insn, (bug_insn_t *)pc))
return 0; return 0;
return GET_INSN_LENGTH(insn); return GET_INSN_LENGTH(insn);
...@@ -165,7 +165,7 @@ int is_valid_bugaddr(unsigned long pc) ...@@ -165,7 +165,7 @@ int is_valid_bugaddr(unsigned long pc)
if (pc < VMALLOC_START) if (pc < VMALLOC_START)
return 0; return 0;
if (probe_kernel_address((bug_insn_t *)pc, insn)) if (get_kernel_nofault(insn, (bug_insn_t *)pc))
return 0; return 0;
if ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) if ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32)
return (insn == __BUG_INSN_32); return (insn == __BUG_INSN_32);
......
...@@ -105,7 +105,7 @@ static int bad_address(void *p) ...@@ -105,7 +105,7 @@ static int bad_address(void *p)
{ {
unsigned long dummy; unsigned long dummy;
return probe_kernel_address((unsigned long *)p, dummy); return get_kernel_nofault(dummy, (unsigned long *)p);
} }
static void dump_pagetable(unsigned long asce, unsigned long address) static void dump_pagetable(unsigned long asce, unsigned long address)
......
...@@ -118,7 +118,7 @@ int is_valid_bugaddr(unsigned long addr) ...@@ -118,7 +118,7 @@ int is_valid_bugaddr(unsigned long addr)
if (addr < PAGE_OFFSET) if (addr < PAGE_OFFSET)
return 0; return 0;
if (probe_kernel_address((insn_size_t *)addr, opcode)) if (get_kernel_nofault(opcode, (insn_size_t *)addr))
return 0; return 0;
if (opcode == TRAPA_BUG_OPCODE) if (opcode == TRAPA_BUG_OPCODE)
return 1; return 1;
......
...@@ -99,7 +99,7 @@ static bool probe_list(struct pci_dev *pdev, unsigned short vendor, ...@@ -99,7 +99,7 @@ static bool probe_list(struct pci_dev *pdev, unsigned short vendor,
unsigned short device; unsigned short device;
do { do {
if (probe_kernel_address(rom_list, device) != 0) if (get_kernel_nofault(device, rom_list) != 0)
device = 0; device = 0;
if (device && match_id(pdev, vendor, device)) if (device && match_id(pdev, vendor, device))
...@@ -125,13 +125,13 @@ static struct resource *find_oprom(struct pci_dev *pdev) ...@@ -125,13 +125,13 @@ static struct resource *find_oprom(struct pci_dev *pdev)
break; break;
rom = isa_bus_to_virt(res->start); rom = isa_bus_to_virt(res->start);
if (probe_kernel_address(rom + 0x18, offset) != 0) if (get_kernel_nofault(offset, rom + 0x18) != 0)
continue; continue;
if (probe_kernel_address(rom + offset + 0x4, vendor) != 0) if (get_kernel_nofault(vendor, rom + offset + 0x4) != 0)
continue; continue;
if (probe_kernel_address(rom + offset + 0x6, device) != 0) if (get_kernel_nofault(device, rom + offset + 0x6) != 0)
continue; continue;
if (match_id(pdev, vendor, device)) { if (match_id(pdev, vendor, device)) {
...@@ -139,8 +139,8 @@ static struct resource *find_oprom(struct pci_dev *pdev) ...@@ -139,8 +139,8 @@ static struct resource *find_oprom(struct pci_dev *pdev)
break; break;
} }
if (probe_kernel_address(rom + offset + 0x8, list) == 0 && if (get_kernel_nofault(list, rom + offset + 0x8) == 0 &&
probe_kernel_address(rom + offset + 0xc, rev) == 0 && get_kernel_nofault(rev, rom + offset + 0xc) == 0 &&
rev >= 3 && list && rev >= 3 && list &&
probe_list(pdev, vendor, rom + offset + list)) { probe_list(pdev, vendor, rom + offset + list)) {
oprom = res; oprom = res;
...@@ -183,14 +183,14 @@ static int __init romsignature(const unsigned char *rom) ...@@ -183,14 +183,14 @@ static int __init romsignature(const unsigned char *rom)
const unsigned short * const ptr = (const unsigned short *)rom; const unsigned short * const ptr = (const unsigned short *)rom;
unsigned short sig; unsigned short sig;
return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE; return get_kernel_nofault(sig, ptr) == 0 && sig == ROMSIGNATURE;
} }
static int __init romchecksum(const unsigned char *rom, unsigned long length) static int __init romchecksum(const unsigned char *rom, unsigned long length)
{ {
unsigned char sum, c; unsigned char sum, c;
for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--) for (sum = 0; length && get_kernel_nofault(c, rom++) == 0; length--)
sum += c; sum += c;
return !length && !sum; return !length && !sum;
} }
...@@ -211,7 +211,7 @@ void __init probe_roms(void) ...@@ -211,7 +211,7 @@ void __init probe_roms(void)
video_rom_resource.start = start; video_rom_resource.start = start;
if (probe_kernel_address(rom + 2, c) != 0) if (get_kernel_nofault(c, rom + 2) != 0)
continue; continue;
/* 0 < length <= 0x7f * 512, historically */ /* 0 < length <= 0x7f * 512, historically */
...@@ -249,7 +249,7 @@ void __init probe_roms(void) ...@@ -249,7 +249,7 @@ void __init probe_roms(void)
if (!romsignature(rom)) if (!romsignature(rom))
continue; continue;
if (probe_kernel_address(rom + 2, c) != 0) if (get_kernel_nofault(c, rom + 2) != 0)
continue; continue;
/* 0 < length <= 0x7f * 512, historically */ /* 0 < length <= 0x7f * 512, historically */
......
...@@ -91,7 +91,7 @@ int is_valid_bugaddr(unsigned long addr) ...@@ -91,7 +91,7 @@ int is_valid_bugaddr(unsigned long addr)
if (addr < TASK_SIZE_MAX) if (addr < TASK_SIZE_MAX)
return 0; return 0;
if (probe_kernel_address((unsigned short *)addr, ud)) if (get_kernel_nofault(ud, (unsigned short *)addr))
return 0; return 0;
return ud == INSN_UD0 || ud == INSN_UD2; return ud == INSN_UD0 || ud == INSN_UD2;
......
...@@ -99,7 +99,7 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr, ...@@ -99,7 +99,7 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
return !instr_lo || (instr_lo>>1) == 1; return !instr_lo || (instr_lo>>1) == 1;
case 0x00: case 0x00:
/* Prefetch instruction is 0x0F0D or 0x0F18 */ /* Prefetch instruction is 0x0F0D or 0x0F18 */
if (probe_kernel_address(instr, opcode)) if (get_kernel_nofault(opcode, instr))
return 0; return 0;
*prefetch = (instr_lo == 0xF) && *prefetch = (instr_lo == 0xF) &&
...@@ -133,7 +133,7 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr) ...@@ -133,7 +133,7 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
while (instr < max_instr) { while (instr < max_instr) {
unsigned char opcode; unsigned char opcode;
if (probe_kernel_address(instr, opcode)) if (get_kernel_nofault(opcode, instr))
break; break;
instr++; instr++;
...@@ -301,7 +301,7 @@ static int bad_address(void *p) ...@@ -301,7 +301,7 @@ static int bad_address(void *p)
{ {
unsigned long dummy; unsigned long dummy;
return probe_kernel_address((unsigned long *)p, dummy); return get_kernel_nofault(dummy, (unsigned long *)p);
} }
static void dump_pagetable(unsigned long address) static void dump_pagetable(unsigned long address)
......
...@@ -302,7 +302,7 @@ static const struct pci_raw_ops *__init pci_find_bios(void) ...@@ -302,7 +302,7 @@ static const struct pci_raw_ops *__init pci_find_bios(void)
check <= (union bios32 *) __va(0xffff0); check <= (union bios32 *) __va(0xffff0);
++check) { ++check) {
long sig; long sig;
if (probe_kernel_address(&check->fields.signature, sig)) if (get_kernel_nofault(sig, &check->fields.signature))
continue; continue;
if (check->fields.signature != BIOS32_SIGNATURE) if (check->fields.signature != BIOS32_SIGNATURE)
......
...@@ -318,14 +318,14 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, ...@@ -318,14 +318,14 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr,
long strnlen_user_nofault(const void __user *unsafe_addr, long count); long strnlen_user_nofault(const void __user *unsafe_addr, long count);
/** /**
* probe_kernel_address(): safely attempt to read from a location * get_kernel_nofault(): safely attempt to read from a location
* @addr: address to read from * @val: read into this variable
* @retval: read into this variable * @ptr: address to read from
* *
* Returns 0 on success, or -EFAULT. * Returns 0 on success, or -EFAULT.
*/ */
#define probe_kernel_address(addr, retval) \ #define get_kernel_nofault(val, ptr) \
copy_from_kernel_nofault(&retval, addr, sizeof(retval)) copy_from_kernel_nofault(&(val), (ptr), sizeof(val))
#ifndef user_access_begin #ifndef user_access_begin
#define user_access_begin(ptr,len) access_ok(ptr, len) #define user_access_begin(ptr,len) access_ok(ptr, len)
......
...@@ -419,8 +419,8 @@ static bool test_kernel_ptr(unsigned long addr, int size) ...@@ -419,8 +419,8 @@ static bool test_kernel_ptr(unsigned long addr, int size)
/* should be at least readable kernel address */ /* should be at least readable kernel address */
if (access_ok(ptr, 1) || if (access_ok(ptr, 1) ||
access_ok(ptr + size - 1, 1) || access_ok(ptr + size - 1, 1) ||
probe_kernel_address(ptr, buf) || get_kernel_nofault(buf, ptr) ||
probe_kernel_address(ptr + size - 1, buf)) { get_kernel_nofault(buf, ptr + size - 1)) {
pr_err("invalid kernel ptr: %#lx\n", addr); pr_err("invalid kernel ptr: %#lx\n", addr);
return true; return true;
} }
...@@ -437,7 +437,7 @@ static bool __maybe_unused test_magic(unsigned long addr, int offset, ...@@ -437,7 +437,7 @@ static bool __maybe_unused test_magic(unsigned long addr, int offset,
if (!addr) if (!addr)
return false; return false;
if (probe_kernel_address(ptr, magic) || magic != expected) { if (get_kernel_nofault(magic, ptr) || magic != expected) {
pr_err("invalid magic at %#lx + %#x = %#x, expected %#x\n", pr_err("invalid magic at %#lx + %#x = %#x, expected %#x\n",
addr, offset, magic, expected); addr, offset, magic, expected);
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment