ftrace: return error on failed modified text.
Have the ftrace_modify_code return error values: -EFAULT on error of reading the address -EINVAL if what is read does not match what it expected -EPERM if the write fails to update after a successful match. Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Родитель
34698bcbdf
Коммит
593eb8a2d6
|
@ -62,7 +62,6 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
||||||
unsigned char *new_code)
|
unsigned char *new_code)
|
||||||
{
|
{
|
||||||
unsigned char replaced[MCOUNT_INSN_SIZE];
|
unsigned char replaced[MCOUNT_INSN_SIZE];
|
||||||
int ret;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: Due to modules and __init, code can
|
* Note: Due to modules and __init, code can
|
||||||
|
@ -72,15 +71,16 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
||||||
* No real locking needed, this code is run through
|
* No real locking needed, this code is run through
|
||||||
* kstop_machine, or before SMP starts.
|
* kstop_machine, or before SMP starts.
|
||||||
*/
|
*/
|
||||||
if (__copy_from_user_inatomic(replaced, (char __user *)ip, MCOUNT_INSN_SIZE))
|
if (__copy_from_user_inatomic(replaced, (char __user *)ip,
|
||||||
return 1;
|
MCOUNT_INSN_SIZE))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
|
if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
|
||||||
return 2;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = __copy_to_user_inatomic((char __user *)ip, new_code,
|
if (__copy_to_user_inatomic((char __user *)ip, new_code,
|
||||||
MCOUNT_INSN_SIZE);
|
MCOUNT_INSN_SIZE))
|
||||||
WARN_ON_ONCE(ret);
|
return -EPERM;
|
||||||
|
|
||||||
sync_core();
|
sync_core();
|
||||||
|
|
||||||
|
|
|
@ -72,13 +72,33 @@ extern unsigned char *ftrace_nop_replace(void);
|
||||||
extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
|
extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
|
||||||
extern int ftrace_dyn_arch_init(void *data);
|
extern int ftrace_dyn_arch_init(void *data);
|
||||||
extern int ftrace_mcount_set(unsigned long *data);
|
extern int ftrace_mcount_set(unsigned long *data);
|
||||||
extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
|
||||||
unsigned char *new_code);
|
|
||||||
extern int ftrace_update_ftrace_func(ftrace_func_t func);
|
extern int ftrace_update_ftrace_func(ftrace_func_t func);
|
||||||
extern void ftrace_caller(void);
|
extern void ftrace_caller(void);
|
||||||
extern void ftrace_call(void);
|
extern void ftrace_call(void);
|
||||||
extern void mcount_call(void);
|
extern void mcount_call(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ftrace_modify_code - modify code segment
|
||||||
|
* @ip: the address of the code segment
|
||||||
|
* @old_code: the contents of what is expected to be there
|
||||||
|
* @new_code: the code to patch in
|
||||||
|
*
|
||||||
|
* This is a very sensitive operation and great care needs
|
||||||
|
* to be taken by the arch. The operation should carefully
|
||||||
|
* read the location, check to see if what is read is indeed
|
||||||
|
* what we expect it to be, and then on success of the compare,
|
||||||
|
* it should write to the location.
|
||||||
|
*
|
||||||
|
* Return must be:
|
||||||
|
* 0 on success
|
||||||
|
* -EFAULT on error reading the location
|
||||||
|
* -EINVAL on a failed compare of the contents
|
||||||
|
* -EPERM on error writing to the location
|
||||||
|
* Any other value will be considered a failure.
|
||||||
|
*/
|
||||||
|
extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
|
||||||
|
unsigned char *new_code);
|
||||||
|
|
||||||
extern int skip_trace(unsigned long ip);
|
extern int skip_trace(unsigned long ip);
|
||||||
|
|
||||||
extern void ftrace_release(void *start, unsigned long size);
|
extern void ftrace_release(void *start, unsigned long size);
|
||||||
|
|
|
@ -596,22 +596,22 @@ ftrace_code_disable(struct dyn_ftrace *rec)
|
||||||
{
|
{
|
||||||
unsigned long ip;
|
unsigned long ip;
|
||||||
unsigned char *nop, *call;
|
unsigned char *nop, *call;
|
||||||
int failed;
|
int ret;
|
||||||
|
|
||||||
ip = rec->ip;
|
ip = rec->ip;
|
||||||
|
|
||||||
nop = ftrace_nop_replace();
|
nop = ftrace_nop_replace();
|
||||||
call = ftrace_call_replace(ip, mcount_addr);
|
call = ftrace_call_replace(ip, mcount_addr);
|
||||||
|
|
||||||
failed = ftrace_modify_code(ip, call, nop);
|
ret = ftrace_modify_code(ip, call, nop);
|
||||||
if (failed) {
|
if (ret) {
|
||||||
switch (failed) {
|
switch (ret) {
|
||||||
case 1:
|
case -EFAULT:
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
pr_info("ftrace faulted on modifying ");
|
pr_info("ftrace faulted on modifying ");
|
||||||
print_ip_sym(ip);
|
print_ip_sym(ip);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case -EINVAL:
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
pr_info("ftrace failed to modify ");
|
pr_info("ftrace failed to modify ");
|
||||||
print_ip_sym(ip);
|
print_ip_sym(ip);
|
||||||
|
@ -620,6 +620,15 @@ ftrace_code_disable(struct dyn_ftrace *rec)
|
||||||
print_ip_ins(" replace: ", nop);
|
print_ip_ins(" replace: ", nop);
|
||||||
printk(KERN_CONT "\n");
|
printk(KERN_CONT "\n");
|
||||||
break;
|
break;
|
||||||
|
case -EPERM:
|
||||||
|
WARN_ON_ONCE(1);
|
||||||
|
pr_info("ftrace faulted on writing ");
|
||||||
|
print_ip_sym(ip);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
WARN_ON_ONCE(1);
|
||||||
|
pr_info("ftrace faulted on unknown error ");
|
||||||
|
print_ip_sym(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
rec->flags |= FTRACE_FL_FAILED;
|
rec->flags |= FTRACE_FL_FAILED;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче