uretprobes: Introduce uprobe_consumer()->ret_handler()

  Enclose return probes implementation, introduce ->ret_handler() and update
existing code to rely on ->handler() *and* ->ret_handler() for uprobe and
uretprobe respectively.

v1 changes:
  - add bp_vaddr argument to ->ret_handler()

RFCv5 changes:
  - don't remove uprobe in case there are no uprobe consumer(handler),
    see handler_chain() changes.

RFCv3 changes: (the patch is introduced in v3)
  - check whether at least one of the consumer's handlers were set.
  - a 'TODO' cap that will be removed once return probes be implemented.
  - introduce ->ret_handler().

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes: Reserve the first slot in xol_vma for trampoline

  - Allocate trampoline page, as the very first one in uprobed
    task xol area, and fill it with breakpoint opcode.
  - Also introduce get_trampoline_vaddr() helper, to wrap the
    trampoline address extraction from area->vaddr. That removes
    confusion and eases the debug experience in case ->vaddr
    notion will be changed.

v1 changes:
  - rework get_trampoline_vaddr() helper.
  - init xol_area->slot_count.

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes: Return probe entry, prepare_uretprobe()

  When a uprobe with return probe consumer is hit, prepare_uretprobe()
function is invoked. It creates return_instance, hijacks return address
and replaces it with the trampoline.

  - Return instances are kept as stack per uprobed task.
  - Return instance is chained, when the original return address is
    trampoline's page vaddr (e.g. recursive call of the probed function).

v1 changes:
 - preserve address of the breakpoint in return_instance.
 - don't forget NULLify return_instances on free_utask.
 - simplify prepare_uretprobe().

RFCv6 changes:
 - rework prepare_uretprobe() logic in order to make further unwinding
   in handler_uretprobe() simplier.
 - introduce the 'dirty' field.

RFCv5 changes:
 - switch from hlist to simply linked list for tracking ->*return_uprobes.
 - revert (*) from v4.
 - preallocate first slot xol_area for return probes, see xol_get_area()
   changes.
 - add get_trampoline_vaddr() helper, to emphasize area->vaddr overload.

RFCv4 changes:
 - get rid of area->rp_trampoline_vaddr as it always the same as ->vaddr.
 - cleanup ->return_uprobes list in uprobe_free_utask(), because the
   task can exit from inside the ret-probe'd function(s).
 - in find_active_uprobe(): Once we inserted "int3" we must ensure that
   handle_swbp() will be called even if this uprobe goes away. We have
   the reference but it only protects uprobe itself, it can't protect
   agains delete_uprobe().

RFCv3 changes:
 - protected uprobe with refcounter. See atomic_inc in prepare_uretprobe()
   and put_uprobe() in a following patch in handle_uretprobe().

RFCv2 changes:
 - get rid of ->return_consumers member from struct uprobe, introduce
   ret_handler() in consumer.

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes: Return probe exit, invoke handlers

  Uretprobe handlers are invoked when the trampoline is hit, on completion the
trampoline is replaced with the saved return address and the uretprobe instance
deleted.

v1 changes:
  - pass bp_vaddr to ret_handler()
  - simplify handle_uretprobe()

RFCv6 changes:
  - rework handle_uretprobe()

RFCv5 changes:
  - switch to simply linked list ->return_uprobes
  - rework handle_uretprobe()

RFCv4 changes:
  - check, whether utask is not NULL in handle_uretprobe()
  - get rid of area->rp_trampoline_vaddr
  - minor handle_uretprobe() fixups

RFCv3 changes:
  - protected uprobe with refcounter. See put_uprobe() in handle_uretprobe()
    that reflects increment in prepare_uretprobe()

RFCv2 changes:
  - get rid of ->return_consumers member from struct uprobe, introduce
    ret_handler() in consumer instead

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes/x86: Hijack return address

  - Hijack the return address and replace it with a trampoline address.

v1 changes:
  - use force_sig_info()
  - use is_compat_task() instead of is_ia32_task(). Don't forget about
    x32 arch.
  - rework and simplify logic

RFCv5 changes:
  - change the fail return code, because orig_ret_vaddr=0 is possible
  - style fixup
RFCv2 changes:
  - remove ->doomed flag, kill task immediately

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes: Limit the depth of return probe nestedness

  Unlike the kretprobes we can't trust userspace, thus must have
protection from user space attacks, this patch limits the return
probes nestedness as a simple remedy for it. Plus the user-space
have the "unlimited" stack, it looks simply impossible to handle
the deep recursion correctly.

  The intention is to have KISS and bare minimum solution for the
initial implementation in order to not complicate the uretprobes
code.

  In the future we may come up with more sophisticated solution that
should remove this depth limitation, however it is not easy task
and lays beyond this patchset. It should consider things like: breakpoint
address lays outside the stack and stack growth direction, longjmp,
sigaltstack... be able to clean up return instances.

Signed-off-by: Anton Arapov <anton@redhat.com>
uretprobes: Remove -ENOSYS as return probes implemented

  Enclose return probes implementation.

Signed-off-by: Anton Arapov <anton@redhat.com>