浏览代码

uprobes/x86: Kill adjust_ret_addr(), simplify UPROBE_FIX_CALL logic

The only insn which could have both UPROBE_FIX_IP and UPROBE_FIX_CALL
was 0xe8 "call relative", and now it is handled by branch_xol_ops.

So we can change default_post_xol_op(UPROBE_FIX_CALL) to simply push
the address of next insn == utask->vaddr + insn.length, just we need
to record insn.length into the new auprobe->def.ilen member.

Note: if/when we teach branch_xol_ops to support jcxz/loopz we can
remove the "correction" logic, UPROBE_FIX_IP can use the same address.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Oleg Nesterov 11 年之前
父节点
当前提交
1dc76e6eac
共有 2 个文件被更改,包括 4 次插入21 次删除
  1. 1 0
      arch/x86/include/asm/uprobes.h
  2. 3 21
      arch/x86/kernel/uprobes.c

+ 1 - 0
arch/x86/include/asm/uprobes.h

@@ -54,6 +54,7 @@ struct arch_uprobe {
 			long	riprel_target;
 			long	riprel_target;
 #endif
 #endif
 			u8	fixups;
 			u8	fixups;
+			u8	ilen;
 		} 			def;
 		} 			def;
 	};
 	};
 };
 };

+ 3 - 21
arch/x86/kernel/uprobes.c

@@ -418,24 +418,6 @@ static int push_ret_address(struct pt_regs *regs, unsigned long ip)
 	return 0;
 	return 0;
 }
 }
 
 
-/*
- * Adjust the return address pushed by a call insn executed out of line.
- */
-static int adjust_ret_addr(unsigned long sp, long correction)
-{
-	int rasize = sizeof_long();
-	long ra;
-
-	if (copy_from_user(&ra, (void __user *)sp, rasize))
-		return -EFAULT;
-
-	ra += correction;
-	if (copy_to_user((void __user *)sp, &ra, rasize))
-		return -EFAULT;
-
-	return 0;
-}
-
 static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs)
 static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs)
 {
 {
 	struct uprobe_task *utask = current->utask;
 	struct uprobe_task *utask = current->utask;
@@ -446,10 +428,9 @@ static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs
 		regs->ip += correction;
 		regs->ip += correction;
 
 
 	if (auprobe->def.fixups & UPROBE_FIX_CALL) {
 	if (auprobe->def.fixups & UPROBE_FIX_CALL) {
-		if (adjust_ret_addr(regs->sp, correction)) {
-			regs->sp += sizeof_long();
+		regs->sp += sizeof_long();
+		if (push_ret_address(regs, utask->vaddr + auprobe->def.ilen))
 			return -ERESTART;
 			return -ERESTART;
-		}
 	}
 	}
 	/* popf; tell the caller to not touch TF */
 	/* popf; tell the caller to not touch TF */
 	if (auprobe->def.fixups & UPROBE_FIX_SETF)
 	if (auprobe->def.fixups & UPROBE_FIX_SETF)
@@ -687,6 +668,7 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
 		handle_riprel_insn(auprobe, &insn);
 		handle_riprel_insn(auprobe, &insn);
 	}
 	}
 
 
+	auprobe->def.ilen = insn.length;
 	if (fix_ip)
 	if (fix_ip)
 		auprobe->def.fixups |= UPROBE_FIX_IP;
 		auprobe->def.fixups |= UPROBE_FIX_IP;
 	if (fix_call)
 	if (fix_call)