26 Mar, 2010

1 commit

  • Support for the PMU's BTS features has been upstreamed in
    v2.6.32, but we still have the old and disabled ptrace-BTS,
    as Linus noticed it not so long ago.

    It's buggy: TIF_DEBUGCTLMSR is trampling all over that MSR without
    regard for other uses (perf) and doesn't provide the flexibility
    needed for perf either.

    Its users are ptrace-block-step and ptrace-bts, since ptrace-bts
    was never used and ptrace-block-step can be implemented using a
    much simpler approach.

    So axe all 3000 lines of it. That includes the *locked_memory*()
    APIs in mm/mlock.c as well.

    Reported-by: Linus Torvalds
    Signed-off-by: Peter Zijlstra
    Cc: Roland McGrath
    Cc: Oleg Nesterov
    Cc: Markus Metzger
    Cc: Steven Rostedt
    Cc: Andrew Morton
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

13 Mar, 2010

1 commit

  • While in theory user_enable_single_step/user_disable_single_step/
    user_enable_blockstep could also be provided as an inline or macro there's
    no good reason to do so, and having the prototype in one places keeps code
    size and confusion down.

    Roland said:

    The original thought there was that user_enable_single_step() et al
    might well be only an instruction or three on a sane machine (as if we
    have any of those!), and since there is only one call site inlining
    would be beneficial. But I agree that there is no strong reason to care
    about inlining it.

    As to the arch changes, there is only one thought I'd add to the
    record. It was always my thinking that for an arch where
    PTRACE_SINGLESTEP does text-modifying breakpoint insertion,
    user_enable_single_step() should not be provided. That is,
    arch_has_single_step()=>true means that there is an arch facility with
    "pure" semantics that does not have any unexpected side effects.
    Inserting a breakpoint might do very unexpected strange things in
    multi-threaded situations. Aside from that, it is a peculiar side
    effect that user_{enable,disable}_single_step() should cause COW
    de-sharing of text pages and so forth. For PTRACE_SINGLESTEP, all these
    peculiarities are the status quo ante for that arch, so having
    arch_ptrace() itself do those is one thing. But for building other
    things in the future, it is nicer to have a uniform "pure" semantics
    that arch-independent code can expect.

    OTOH, all such arch issues are really up to the arch maintainer. As
    of today, there is nothing but ptrace using user_enable_single_step() et
    al so it's a distinction without a practical difference. If/when there
    are other facilities that use user_enable_single_step() and might care,
    the affected arch's can revisit the question when someone cares about
    the quality of the arch support for said new facility.

    Signed-off-by: Christoph Hellwig
    Cc: Oleg Nesterov
    Cc: Roland McGrath
    Acked-by: David Howells
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

24 Feb, 2010

1 commit


12 Feb, 2010

1 commit

  • Generic support for PTRACE_GETREGSET/PTRACE_SETREGSET commands which
    export the regsets supported by each architecture using the correponding
    NT_* types. These NT_* types are already part of the userland ABI, used
    in representing the architecture specific register sets as different NOTES
    in an ELF core file.

    'addr' parameter for the ptrace system call encode the REGSET type (using
    the corresppnding NT_* type) and the 'data' parameter points to the
    struct iovec having the user buffer and the length of that buffer.

    struct iovec iov = { buf, len};
    ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);

    On successful completion, iov.len will be updated by the kernel specifying
    how much the kernel has written/read to/from the user's iov.buf.

    x86 extended state registers are primarily exported using this interface.

    Signed-off-by: Suresh Siddha
    LKML-Reference:
    Acked-by: Hongjiu Lu
    Cc: Roland McGrath
    Signed-off-by: H. Peter Anvin

    Suresh Siddha
     

16 Dec, 2009

2 commits

  • Suggested by Roland.

    Currently there is no way to synthesize a single-stepping trap in the
    arch-independent manner. This patch adds the default helper which fills
    siginfo_t, arch/ can can override it.

    Architetures which implement user_enable_single_step() should add
    user_single_step_siginfo() also.

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Cc:
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • No functional changes.

    ptrace_init_task() looks confusing, as if we always auto-attach when "bool
    ptrace" argument is true, while in fact we attach only if current is
    traced.

    Make the code more explicit and kill now unused ptrace_link().

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

19 Jun, 2009

1 commit

  • - Use rcu_read_lock() instead of tasklist_lock to find/get the task
    in ptrace_get_task_struct().

    - Make it static, it has no callers outside of ptrace.c.

    - The comment doesn't match the reality, this helper does not do
    any checks. Beacuse it is really trivial and static I removed the
    whole comment.

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

07 Apr, 2009

1 commit

  • Add the ptrace bts context field to task_struct unconditionally.

    Initialize the field directly in copy_process().
    Remove all the unneeded functionality used to initialize that field.

    Signed-off-by: Markus Metzger
    Cc: roland@redhat.com
    Cc: eranian@googlemail.com
    Cc: oleg@redhat.com
    Cc: juan.villacis@intel.com
    Cc: ak@linux.jf.intel.com
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Markus Metzger
     

03 Apr, 2009

2 commits

  • By discussion with Roland.

    - Rename ptrace_exit() to exit_ptrace(), and change it to do all the
    necessary work with ->ptraced list by its own.

    - Move this code from exit.c to ptrace.c

    - Update the comment in ptrace_detach() to explain the rechecking of
    the child->ptrace.

    Signed-off-by: Oleg Nesterov
    Cc: "Eric W. Biederman"
    Cc: "Metzger, Markus T"
    Cc: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • When ptrace_detach() takes tasklist, the tracee can be SIGKILL'ed. If it
    has already passed exit_notify() we can leak a zombie, because a) ptracing
    disables the auto-reaping logic, and b) ->real_parent was not notified
    about the child's death.

    ptrace_detach() should follow the ptrace_exit's logic, change the code
    accordingly.

    Signed-off-by: Oleg Nesterov
    Cc: Jerome Marchand
    Cc: Roland McGrath
    Tested-by: Denys Vlasenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

20 Dec, 2008

1 commit

  • Impact: introduce new ptrace facility

    Add arch_ptrace_untrace() function that is called when the tracer
    detaches (either voluntarily or when the tracing task dies);
    ptrace_disable() is only called on a voluntary detach.

    Add ptrace_fork() and arch_ptrace_fork(). They are called when a
    traced task is forked.

    Clear DS and BTS related fields on fork.

    Release DS resources and reclaim memory in ptrace_untrace(). This
    releases resources already when the tracing task dies. We used to do
    that when the traced task dies.

    Signed-off-by: Markus Metzger
    Signed-off-by: Ingo Molnar

    Markus Metzger
     

20 Oct, 2008

1 commit


08 Aug, 2008

1 commit

  • In the change in commit 09a05394fe2448a4139b014936330af23fa7ec83, I
    overlooked two nits in the logic and this broke using CLONE_PTRACE
    when PTRACE_O_TRACE* are not being used.

    A parent that is itself traced at all but not using PTRACE_O_TRACE*,
    using CLONE_PTRACE would have its new child fail to be traced.

    A parent that is not itself traced at all that uses CLONE_PTRACE
    (which should be a no-op in this case) would confuse the bookkeeping
    and lead to a crash at exit time.

    This restores the missing checks and fixes both failure modes.

    Reported-by: Eduardo Habkost
    Signed-off-by: Roland McGrath

    Roland McGrath
     

27 Jul, 2008

4 commits

  • This adds the new function task_current_syscall() on machines where the
    asm/syscall.h interface is supported (CONFIG_HAVE_ARCH_TRACEHOOK). It's
    exported for modules to use in the future. This function safely samples
    the state of a blocked thread to collect what system call it is blocked
    in, and the six system call argument registers.

    Signed-off-by: Roland McGrath
    Cc: Oleg Nesterov
    Reviewed-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     
  • This moves the ptrace-related logic from release_task into tracehook.h and
    ptrace.h inlines. It provides clean hooks both before and after locking
    tasklist_lock, for future tracing logic to do more cleanup without the
    lock.

    This also changes release_task() itself in the rare "zap_leader" case to
    set the leader to EXIT_DEAD before iterating. This maintains the
    invariant that release_task() only ever handles a task in EXIT_DEAD. This
    is a common-sense invariant that is already always true except in this one
    arcane case of zombie leader whose parent ignores SIGCHLD.

    This change is harmless and only costs one store in this one rare case.
    It keeps the expected state more consisently sane, which is nicer when
    debugging weirdness in release_task(). It also lets some future code in
    the tracehook entry points rely on this invariant for bookkeeping.

    Signed-off-by: Roland McGrath
    Cc: Oleg Nesterov
    Reviewed-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     
  • This moves all the ptrace initialization and tracing logic for task
    creation into tracehook.h and ptrace.h inlines. It reorganizes the code
    slightly, but should not change any behavior.

    There are four tracehook entry points, at each important stage of task
    creation. This keeps the interface from the core fork.c code fairly
    clean, while supporting the complex setup required for ptrace or something
    like it.

    Signed-off-by: Roland McGrath
    Cc: Oleg Nesterov
    Reviewed-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     
  • This patch series introduces the "tracehook" interface layer of inlines in
    . There are more details in the log entry for patch
    01/23 and in the header file comments inside that patch. Most of these
    changes move code around with little or no change, and they should not
    break anything or change any behavior.

    This sets a new standard for uniform arch support to enable clean
    arch-independent implementations of new debugging and tracing stuff,
    denoted by CONFIG_HAVE_ARCH_TRACEHOOK. Patch 20/23 adds that symbol to
    arch/Kconfig, with comments listing everything an arch has to do before
    setting "select HAVE_ARCH_TRACEHOOK". These are elaborted a bit at:

    http://sourceware.org/systemtap/wiki/utrace/arch/HowTo

    The new inlines that arch code must define or call have detailed kerneldoc
    comments in the generic header files that say what is required.

    No arch is obligated to do any work, and no arch's build should be broken
    by these changes. There are several steps that each arch should take so
    it can set HAVE_ARCH_TRACEHOOK. Most of these are simple. Providing this
    support will let new things people add for doing debugging and tracing of
    user-level threads "just work" for your arch in the future. For an arch
    that does not provide HAVE_ARCH_TRACEHOOK, some new options for such
    features will not be available for config.

    I have done some arch work and will submit this to the arch maintainers
    after the generic tracehook series settles in. For now, that work is
    available in my GIT repositories, and in patch and mbox-of-patches form at
    http://people.redhat.com/roland/utrace/2.6-current/

    This paves the way for my "utrace" work, to be submitted later. But it is
    not innately tied to that. I hope that the tracehook series can go in
    soon regardless of what eventually does or doesn't go on top of it. For
    anyone implementing any kind of new tracing/debugging plan, or just
    understanding all the context of the existing ptrace implementation,
    having tracehook.h makes things much easier to find and understand.

    This patch:

    This adds the new kernel-internal header file . This
    is not yet used at all. The comments in the header introduce what the
    following series of patches is about.

    The aim is to formalize and consolidate all the places that the core
    kernel code and the arch code now ties into the ptrace implementation.

    These patches mostly don't cause any functional change. They just move
    the details of ptrace logic out of core code into tracehook.h inlines,
    where they are mostly compiled away to the same as before. All that
    changes is that everything is thoroughly documented and any future
    reworking of ptrace, or addition of something new, would not have to touch
    core code all over, just change the tracehook.h inlines.

    The new linux/ptrace.h inlines are used by the following patches in the
    new tracehook_*() inlines. Using these helpers for the ptrace event stops
    makes it simple to change or disable the old ptrace implementation of
    these stops conditionally later.

    Signed-off-by: Roland McGrath
    Cc: Oleg Nesterov
    Reviewed-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     

14 Jul, 2008

1 commit

  • Enable security modules to distinguish reading of process state via
    proc from full ptrace access by renaming ptrace_may_attach to
    ptrace_may_access and adding a mode argument indicating whether only
    read access or full attach access is requested. This allows security
    modules to permit access to reading process state without granting
    full ptrace access. The base DAC/capability checking remains unchanged.

    Read access to /proc/pid/mem continues to apply a full ptrace attach
    check since check_mem_permission() already requires the current task
    to already be ptracing the target. The other ptrace checks within
    proc for elements like environ, maps, and fds are changed to pass the
    read mode instead of attach.

    In the SELinux case, we model such reading of process state as a
    reading of a proc file labeled with the target process' label. This
    enables SELinux policy to permit such reading of process state without
    permitting control or manipulation of the target process, as there are
    a number of cases where programs probe for such information via proc
    but do not need to be able to control the target (e.g. procps,
    lsof, PolicyKit, ConsoleKit). At present we have to choose between
    allowing full ptrace in policy (more permissive than required/desired)
    or breaking functionality (or in some cases just silencing the denials
    via dontaudit rules but this can hide genuine attacks).

    This version of the patch incorporates comments from Casey Schaufler
    (change/replace existing ptrace_may_attach interface, pass access
    mode), and Chris Wright (provide greater consistency in the checking).

    Note that like their predecessors __ptrace_may_attach and
    ptrace_may_attach, the __ptrace_may_access and ptrace_may_access
    interfaces use different return value conventions from each other (0
    or -errno vs. 1 or 0). I retained this difference to avoid any
    changes to the caller logic but made the difference clearer by
    changing the latter interface to return a bool rather than an int and
    by adding a comment about it to ptrace.h for any future callers.

    Signed-off-by: Stephen Smalley
    Acked-by: Chris Wright
    Signed-off-by: James Morris

    Stephen Smalley
     

30 Apr, 2008

1 commit

  • Add another trivial helper for the sake of grep. It also auto-documents the
    fact that ->parent != real_parent implies ->ptrace.

    No functional changes.

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

09 Feb, 2008

1 commit

  • Since the patch

    "Fix ptrace_attach()/ptrace_traceme()/de_thread() race"
    commit f5b40e363ad6041a96e3da32281d8faa191597b9

    we set PT_ATTACHED and change child->parent "atomically" wrt task_list lock.

    This means we can remove the checks like "PT_ATTACHED && ->parent != ptracer"
    which were needed to catch the "ptrace attach is in progress" case. We can
    also remove the flag itself since nobody else uses it.

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Cc: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

07 Feb, 2008

1 commit

  • This adds support to allow asm/ptrace.h to define two new macros,
    arch_ptrace_stop_needed and arch_ptrace_stop. These control special
    machine-specific actions to be done before a ptrace stop. The new code
    compiles away to nothing when the new macros are not defined. This is the
    case on all machines to begin with.

    On ia64, these macros will be defined to solve the long-standing issue of
    ptrace vs register backing store.

    Signed-off-by: Roland McGrath
    Cc: Petr Tesarik
    Cc: Tony Luck
    Cc: Matthew Wilcox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     

30 Jan, 2008

3 commits

  • This makes ptrace_request handle PTRACE_SINGLEBLOCK along with
    PTRACE_CONT et al. The new generic code makes use of the
    arch_has_block_step macro and generic entry points on machines
    that define them.

    [ mingo@elte.hu: bugfix ]

    Signed-off-by: Roland McGrath
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    Roland McGrath
     
  • This defines the new macro arch_has_block_step() in linux/ptrace.h, a
    default for when asm/ptrace.h does not define it. This is the analog
    of arch_has_single_step() for step-until-branch on machines that have
    it. It declares the new user_enable_block_step function, which goes
    with the existing user_enable_single_step and user_disable_single_step.
    This is not used yet, but paves the way to harmonize on this interface
    for the arch-specific calls on all machines.

    Signed-off-by: Roland McGrath
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    Roland McGrath
     
  • This defines the new macro arch_has_single_step() in linux/ptrace.h, a
    default for when asm/ptrace.h does not define it. It declares the new
    user_enable_single_step and user_disable_single_step functions.
    This is not used yet, but paves the way to harmonize on this interface
    for the arch-specific calls on all machines.

    Signed-off-by: Roland McGrath
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner

    Roland McGrath
     

03 Jan, 2008

1 commit

  • Contents of /proc/*/maps is sensitive and may become sensitive after
    open() (e.g. if target originally shares our ->mm and later does exec
    on suid-root binary).

    Check at read() (actually, ->start() of iterator) time that mm_struct
    we'd grabbed and locked is
    - still the ->mm of target
    - equal to reader's ->mm or the target is ptracable by reader.

    Signed-off-by: Al Viro
    Acked-by: Rik van Riel
    Signed-off-by: Linus Torvalds

    Al Viro
     

18 Jul, 2007

2 commits

  • Identical implementations of PTRACE_POKEDATA go into generic_ptrace_pokedata()
    function.

    AFAICS, fix bug on xtensa where successful PTRACE_POKEDATA will nevertheless
    return EPERM.

    Signed-off-by: Alexey Dobriyan
    Cc: Christoph Hellwig
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     
  • Identical implementations of PTRACE_PEEKDATA go into generic_ptrace_peekdata()
    function.

    Signed-off-by: Alexey Dobriyan
    Cc: Christoph Hellwig
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

30 Sep, 2006

1 commit

  • It is sure confusing that linux/ptrace.h has:
    #define PTRACE_SINGLESTEP 9
    #define PTRACE_ATTACH 0x10
    #define PTRACE_DETACH 0x11
    #define PTRACE_SYSCALL 24
    All the low-numbered constants are in decimal, but the last two in hex.
    It sure makes it likely that someone will look at this and think that
    9, 10, 11 are used, and that 16 and 17 are not used.

    How about we use the same notation for all the numbers [0,24] in the
    same short list?

    Signed-off-by: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roland McGrath
     

27 Jun, 2006

1 commit

  • With this patch zap_process() sets SIGNAL_GROUP_EXIT while sending SIGKILL to
    the thread group. This means that a TASK_TRACED task

    1. Will be awakened by signal_wake_up(1)

    2. Can't sleep again via ptrace_notify()

    3. Can't go to do_signal_stop() after return
    from ptrace_stop() in get_signal_to_deliver()

    So we can remove all ptrace related stuff from coredump path.

    Signed-off-by: Oleg Nesterov
    Cc: "Eric W. Biederman"
    Cc: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

23 Jun, 2006

1 commit

  • After a lot of reading the code and thinking about how it behaves I have
    managed to figure out what the current ptrace locking rules are. The
    current code is in much better that it appears at first glance. The
    troublesome code paths are actually the code paths that violate the current
    rules.

    ptrace uses simple exclusive access as it's locking. You can only touch
    task->ptrace if the task is stopped and you are the ptracer, or if the task
    is running and are the task itself.

    Very simple, very easy to maintain. It just needs to be documented so
    people know not to touch ptrace from elsewhere.

    Currently we do have a few pieces of code that are in violation of this
    rule. Particularly the core dump code, and ptrace_attach. But so far the
    code looks fixable.

    Signed-off-by: Eric W. Biederman
    Cc: Oleg Nesterov
    Cc: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

16 Feb, 2006

1 commit

  • 1. The tracee can go from ptrace_stop() to do_signal_stop()
    after __ptrace_unlink(p).

    2. It is unsafe to __ptrace_unlink(p) while p->parent may wait
    for tasklist_lock in ptrace_detach().

    Signed-off-by: Oleg Nesterov
    Cc: Roland McGrath
    Cc: Ingo Molnar
    Cc: Christoph Hellwig
    Cc: Eric W. Biederman
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

09 Jan, 2006

2 commits

  • PTRACE_SYSEMU{,_SINGLESTEP} is actually arch specific, for now, and the
    current allocated number clashes with a ptrace code of frv, i.e.
    PTRACE_GETFDPIC. I should have submitted this much earlier, anyway we get no
    breakage for this.

    CC: Daniel Jacobowitz
    Signed-off-by: Paolo 'Blaisorblade' Giarrusso
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paolo 'Blaisorblade' Giarrusso
     
  • The ptrace_get_task_struct() helper that I added as part of the ptrace
    consolidation is useful in variety of places that currently opencode it.
    Switch them to the common helpers.

    Add a ptrace_traceme() helper that needs to be explicitly called, and simplify
    the ptrace_get_task_struct() interface. We don't need the request argument
    now, and we return the task_struct directly, using ERR_PTR() for error
    returns. It's a bit more code in the callers, but we have two sane routines
    that do one thing well now.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

07 Nov, 2005

1 commit

  • The sys_ptrace boilerplate code (everything outside the big switch
    statement for the arch-specific requests) is shared by most architectures.
    This patch moves it to kernel/ptrace.c and leaves the arch-specific code as
    arch_ptrace.

    Some architectures have a too different ptrace so we have to exclude them.
    They continue to keep their implementations. For sh64 I had to add a
    sh64_ptrace wrapper because it does some initialization on the first call.
    For um I removed an ifdefed SUBARCH_PTRACE_SPECIAL block, but
    SUBARCH_PTRACE_SPECIAL isn't defined anywhere in the tree.

    Signed-off-by: Christoph Hellwig
    Acked-by: Paul Mackerras
    Acked-by: Ralf Baechle
    Acked-By: David Howells
    Acked-by: Russell King
    Acked-by: Paul Mundt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

08 Sep, 2005

1 commit


05 Sep, 2005

2 commits

  • This patch implements the new ptrace option PTRACE_SYSEMU_SINGLESTEP, which
    can be used by UML to singlestep a process: it will receive SINGLESTEP
    interceptions for normal instructions and syscalls, but syscall execution will
    be skipped just like with PTRACE_SYSEMU.

    Signed-off-by: Bodo Stroesser
    Signed-off-by: Paolo 'Blaisorblade' Giarrusso
    Cc: Jeff Dike
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Bodo Stroesser
     
  • Jeff Dike ,
    Paolo 'Blaisorblade' Giarrusso ,
    Bodo Stroesser

    Adds a new ptrace(2) mode, called PTRACE_SYSEMU, resembling PTRACE_SYSCALL
    except that the kernel does not execute the requested syscall; this is useful
    to improve performance for virtual environments, like UML, which want to run
    the syscall on their own.

    In fact, using PTRACE_SYSCALL means stopping child execution twice, on entry
    and on exit, and each time you also have two context switches; with SYSEMU you
    avoid the 2nd stop and so save two context switches per syscall.

    Also, some architectures don't have support in the host for changing the
    syscall number via ptrace(), which is currently needed to skip syscall
    execution (UML turns any syscall into getpid() to avoid it being executed on
    the host). Fixing that is hard, while SYSEMU is easier to implement.

    * This version of the patch includes some suggestions of Jeff Dike to avoid
    adding any instructions to the syscall fast path, plus some other little
    changes, by myself, to make it work even when the syscall is executed with
    SYSENTER (but I'm unsure about them). It has been widely tested for quite a
    lot of time.

    * Various fixed were included to handle the various switches between
    various states, i.e. when for instance a syscall entry is traced with one of
    PT_SYSCALL / _SYSEMU / _SINGLESTEP and another one is used on exit.
    Basically, this is done by remembering which one of them was used even after
    the call to ptrace_notify().

    * We're combining TIF_SYSCALL_EMU with TIF_SYSCALL_TRACE or TIF_SINGLESTEP
    to make do_syscall_trace() notice that the current syscall was started with
    SYSEMU on entry, so that no notification ought to be done in the exit path;
    this is a bit of a hack, so this problem is solved in another way in next
    patches.

    * Also, the effects of the patch:
    "Ptrace - i386: fix Syscall Audit interaction with singlestep"
    are cancelled; they are restored back in the last patch of this series.

    Detailed descriptions of the patches doing this kind of processing follow (but
    I've already summed everything up).

    * Fix behaviour when changing interception kind #1.

    In do_syscall_trace(), we check the status of the TIF_SYSCALL_EMU flag
    only after doing the debugger notification; but the debugger might have
    changed the status of this flag because he continued execution with
    PTRACE_SYSCALL, so this is wrong. This patch fixes it by saving the flag
    status before calling ptrace_notify().

    * Fix behaviour when changing interception kind #2:
    avoid intercepting syscall on return when using SYSCALL again.

    A guest process switching from using PTRACE_SYSEMU to PTRACE_SYSCALL
    crashes.

    The problem is in arch/i386/kernel/entry.S. The current SYSEMU patch
    inhibits the syscall-handler to be called, but does not prevent
    do_syscall_trace() to be called after this for syscall completion
    interception.

    The appended patch fixes this. It reuses the flag TIF_SYSCALL_EMU to
    remember "we come from PTRACE_SYSEMU and now are in PTRACE_SYSCALL", since
    the flag is unused in the depicted situation.

    * Fix behaviour when changing interception kind #3:
    avoid intercepting syscall on return when using SINGLESTEP.

    When testing 2.6.9 and the skas3.v6 patch, with my latest patch and had
    problems with singlestepping on UML in SKAS with SYSEMU. It looped
    receiving SIGTRAPs without moving forward. EIP of the traced process was
    the same for all SIGTRAPs.

    What's missing is to handle switching from PTRACE_SYSCALL_EMU to
    PTRACE_SINGLESTEP in a way very similar to what is done for the change from
    PTRACE_SYSCALL_EMU to PTRACE_SYSCALL_TRACE.

    I.e., after calling ptrace(PTRACE_SYSEMU), on the return path, the debugger is
    notified and then wake ups the process; the syscall is executed (or skipped,
    when do_syscall_trace() returns 0, i.e. when using PTRACE_SYSEMU), and
    do_syscall_trace() is called again. Since we are on the return path of a
    SYSEMU'd syscall, if the wake up is performed through ptrace(PTRACE_SYSCALL),
    we must still avoid notifying the parent of the syscall exit. Now, this
    behaviour is extended even to resuming with PTRACE_SINGLESTEP.

    Signed-off-by: Paolo 'Blaisorblade' Giarrusso
    Cc: Jeff Dike
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Laurent Vivier
     

17 Apr, 2005

1 commit

  • Initial git repository build. I'm not bothering with the full history,
    even though we have it. We can create a separate "historical" git
    archive of that later if we want to, and in the meantime it's about
    3.2GB when imported into git - space that would just make the early
    git days unnecessarily complicated, when we don't have a lot of good
    infrastructure for it.

    Let it rip!

    Linus Torvalds