1. 29 Sep, 2012 10 commits
    • Oleg Nesterov's avatar
      uprobes: Introduce copy_opcode(), kill read_opcode() · cceb55aa
      Oleg Nesterov authored
      No functional changes, preparations.
      
      1. Extract the kmap-and-memcpy code from read_opcode() into the
         new trivial helper, copy_opcode(). The next patch will add
         another user.
      
      2. read_opcode() becomes really trivial, fold it into its single
         caller, is_swbp_at_addr().
      
      3. Remove "auprobe" argument from write_opcode(), it is not used
         since f403072c.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      cceb55aa
    • Oleg Nesterov's avatar
      uprobes: Kill set_swbp()->is_swbp_at_addr() · e97f65a1
      Oleg Nesterov authored
      A separate patch for better documentation.
      
      set_swbp()->is_swbp_at_addr() is not needed for correctness, it is
      harmless to do the unnecessary __replace_page(old_page, new_page)
      when these 2 pages are identical.
      
      And it can not be counted as optimization. mmap/register races are
      very unlikely, while in the likely case is_swbp_at_addr() adds the
      extra get_user_pages() even if the caller is uprobe_mmap(current->mm)
      and returns false.
      
      Note also that the semantics/usage of is_swbp_at_addr() in uprobe.c
      is confusing. set_swbp() uses it to detect the case when this insn
      was already modified by uprobes, that is why it should always compare
      the opcode with UPROBE_SWBP_INSN even if the hardware (like powerpc)
      has other trap insns. It doesn't matter if this breakpoint was in fact
      installed by gdb or application itself, we are going to "steal" this
      breakpoint anyway and execute the original insn from vm_file even if
      it no longer matches the memory.
      
      OTOH, handle_swbp()->find_active_uprobe() uses is_swbp_at_addr() to
      figure out whether we need to send SIGTRAP or not if we can not find
      uprobe, so in this case it should return true for all trap variants,
      not only for UPROBE_SWBP_INSN.
      
      This patch removes set_swbp()->is_swbp_at_addr(), the next patches
      will remove it from set_orig_insn() which is similar to set_swbp()
      in this respect. So the only caller will be handle_swbp() and we
      can make its semantics clear.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      e97f65a1
    • Oleg Nesterov's avatar
      uprobes: Restrict valid_vma(false) to skip VM_SHARED vmas · e40cfce6
      Oleg Nesterov authored
      valid_vma(false) ignores ->vm_flags, this is not actually right.
      We should never try to write into MAP_SHARED mapping, this can
      confuse an apllication which actually writes to ->vm_file.
      
      With this patch valid_vma(false) ignores VM_WRITE only but checks
      other (immutable) bits checked by valid_vma(true). This can also
      speedup uprobe_munmap() and uprobe_unregister().
      
      Note: even after this patch _unregister can confuse the probed
      application if it does mprotect(PROT_WRITE) after _register and
      installs "int3", but this is hardly possible to avoid and this
      doesn't differ from gdb case.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      e40cfce6
    • Oleg Nesterov's avatar
      uprobes: Change valid_vma() to demand VM_MAYEXEC rather than VM_EXEC · 78a32054
      Oleg Nesterov authored
      uprobe_register() or uprobe_mmap() requires VM_READ | VM_EXEC, this
      is not right. An apllication can do mprotect(PROT_EXEC) later and
      execute this code.
      
      Change valid_vma(is_register => true) to check VM_MAYEXEC instead.
      No need to check VM_MAYREAD, it is always set.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      78a32054
    • Oleg Nesterov's avatar
      uprobes: Change write_opcode() to use FOLL_FORCE · 75ed82ea
      Oleg Nesterov authored
      write_opcode()->get_user_pages() needs FOLL_FORCE to ensure we can
      read the page even if the probed task did mprotect(PROT_NONE) after
      uprobe_register(). Without FOLL_WRITE, FOLL_FORCE doesn't have any
      side effect but allows to read the !VM_READ memory.
      
      Otherwiese the subsequent uprobe_unregister()->set_orig_insn() fails
      and we leak "int3". If that task does mprotect(PROT_READ | EXEC) and
      execute the probed insn later it will be killed.
      
      Note: in fact this is also needed for _register, see the next patch.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      75ed82ea
    • Oleg Nesterov's avatar
      uprobes: Move clear_thread_flag(TIF_UPROBE) to uprobe_notify_resume() · db023ea5
      Oleg Nesterov authored
      Move clear_thread_flag(TIF_UPROBE) from do_notify_resume() to
      uprobe_notify_resume() for !CONFIG_UPROBES case.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      db023ea5
    • Oleg Nesterov's avatar
      uprobes: Kill UTASK_BP_HIT state · 1b08e907
      Oleg Nesterov authored
      Kill UTASK_BP_HIT state, it buys nothing but complicates the code.
      It is only used in uprobe_notify_resume() to decide who should be
      called, we can check utask->active_uprobe != NULL instead. And this
      allows us to simplify handle_swbp(), no need to clear utask->state.
      
      Likewise we could kill UTASK_SSTEP, but UTASK_BP_HIT is worse and
      imho should die. The problem is, it creates the special case when
      task->utask is NULL, we can't distinguish RUNNING and BP_HIT. With
      this patch utask == NULL always means RUNNING.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      1b08e907
    • Oleg Nesterov's avatar
      uprobes: Fix UPROBE_SKIP_SSTEP checks in handle_swbp() · 0578a970
      Oleg Nesterov authored
      If handle_swbp()->add_utask() fails but UPROBE_SKIP_SSTEP is set,
      cleanup_ret: path do not restart the insn, this is wrong. Remove
      this check and add the additional label for can_skip_sstep() = T
      case.
      
      Note also that UPROBE_SKIP_SSTEP can be false positive, we simply
      can not trust it unless arch_uprobe_skip_sstep() was already called.
      
      Also, move another UPROBE_SKIP_SSTEP check before can_skip_sstep()
      into this helper, this looks more clean and understandable.
      
      Note: probably we should rename "skip" to "emulate" and I think
      that "clear UPROBE_SKIP_SSTEP" should be moved to arch_can_skip.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      0578a970
    • Oleg Nesterov's avatar
      uprobes: Do not setup ->active_uprobe/state prematurely · 746a9e6b
      Oleg Nesterov authored
      handle_swbp() sets utask->active_uprobe before handler_chain(),
      and UTASK_SSTEP before pre_ssout(). This complicates the code
      for no reason,  arch_ hooks or consumer->handler() should not
      (and can't) use this info.
      
      Change handle_swbp() to initialize them after pre_ssout(), and
      remove the no longer needed cleanup-utask code.
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      cked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      746a9e6b
    • Oleg Nesterov's avatar
      uprobes: Do not leak UTASK_BP_HIT if find_active_uprobe() fails · 79d54b24
      Oleg Nesterov authored
      If handle_swbp()->find_active_uprobe() fails we return with
      utask->state = UTASK_BP_HIT.
      
      Change handle_swbp() to reset utask->state at the start. Note
      that we do this unconditionally, see the next patch(es).
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
      79d54b24
  2. 28 Sep, 2012 1 commit
  3. 27 Sep, 2012 3 commits
  4. 26 Sep, 2012 15 commits
  5. 25 Sep, 2012 2 commits
  6. 24 Sep, 2012 9 commits