28 May, 2010

2 commits

  • Now that Mike Frysinger unified the FDPIC ptrace code, we can fix the
    unsafe usage of child->mm in ptrace_request(PTRACE_GETFDPIC).

    We have the reference to task_struct, and ptrace_check_attach() verified
    the tracee is stopped. But nothing can protect from SIGKILL after that,
    we must not assume child->mm != NULL.

    Signed-off-by: Oleg Nesterov
    Acked-by: Mike Frysinger
    Acked-by: David Howells
    Cc: Paul Mundt
    Cc: Greg Ungerer
    Acked-by: Roland McGrath
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • The Blackfin/FRV/SuperH guys all have the same exact FDPIC ptrace code in
    their arch handlers (since they were probably copied & pasted). Since
    these ptrace interfaces are an arch independent aspect of the FDPIC code,
    unify them in the common ptrace code so new FDPIC ports don't need to copy
    and paste this fundamental stuff yet again.

    Signed-off-by: Mike Frysinger
    Acked-by: Roland McGrath
    Acked-by: David Howells
    Acked-by: Paul Mundt
    Cc: Oleg Nesterov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mike Frysinger
     

18 May, 2010

1 commit

  • …git/tip/linux-2.6-tip

    * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (311 commits)
    perf tools: Add mode to build without newt support
    perf symbols: symbol inconsistency message should be done only at verbose=1
    perf tui: Add explicit -lslang option
    perf options: Type check all the remaining OPT_ variants
    perf options: Type check OPT_BOOLEAN and fix the offenders
    perf options: Check v type in OPT_U?INTEGER
    perf options: Introduce OPT_UINTEGER
    perf tui: Add workaround for slang < 2.1.4
    perf record: Fix bug mismatch with -c option definition
    perf options: Introduce OPT_U64
    perf tui: Add help window to show key associations
    perf tui: Make <- exit menus too
    perf newt: Add single key shortcuts for zoom into DSO and threads
    perf newt: Exit browser unconditionally when CTRL+C, q or Q is pressed
    perf newt: Fix the 'A'/'a' shortcut for annotate
    perf newt: Make <- exit the ui_browser
    x86, perf: P4 PMU - fix counters management logic
    perf newt: Make <- zoom out filters
    perf report: Report number of events, not samples
    perf hist: Clarify events_stats fields usage
    ...

    Fix up trivial conflicts in kernel/fork.c and tools/perf/builtin-record.c

    Linus Torvalds
     

27 Apr, 2010

1 commit

  • BKL isn't present anymore into this file thus we can safely remove
    smp_lock.h inclusion.

    Signed-off-by: Alessio Igor Bogani
    Cc: Roland McGrath
    Cc: Oleg Nesterov
    Cc: Andrew Morton
    Cc: James Morris
    Cc: Ingo Molnar
    Signed-off-by: Frederic Weisbecker

    Alessio Igor Bogani
     

10 Apr, 2010

1 commit

  • The comment suggests that this usage is stale. There is no bkl in the
    exec path so if there is a race lurking there, the bkl in ptrace is
    not going to help in this regard.

    Overview of the possibility of "accidental" races this bkl might
    protect:

    - ptrace_traceme() is protected against task removal and concurrent
    read/write on current->ptrace as it locks write tasklist_lock.

    - arch_ptrace_attach() is serialized by ptrace_traceme() against
    concurrent PTRACE_TRACEME or PTRACE_ATTACH

    - ptrace_attach() is protected the same way ptrace_traceme() and
    in turn serializes arch_ptrace_attach()

    - ptrace_check_attach() does its own well described serializing too.

    There is no obvious race here.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Frederic Weisbecker
    Acked-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Cc: Andrew Morton
    Cc: Roland McGrath

    Arnd Bergmann
     

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
     

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
     

24 Sep, 2009

1 commit

  • The bug is old, it wasn't cause by recent changes.

    Test case:

    static void *tfunc(void *arg)
    {
    int pid = (long)arg;

    assert(ptrace(PTRACE_ATTACH, pid, NULL, NULL) == 0);
    kill(pid, SIGKILL);

    sleep(1);
    return NULL;
    }

    int main(void)
    {
    pthread_t th;
    long pid = fork();

    if (!pid)
    pause();

    signal(SIGCHLD, SIG_IGN);
    assert(pthread_create(&th, NULL, tfunc, (void*)pid) == 0);

    int r = waitpid(-1, NULL, __WNOTHREAD);
    printf("waitpid: %d %m\n", r);

    return 0;
    }

    Before the patch this program hangs, after this patch waitpid() correctly
    fails with errno == -ECHILD.

    The problem is, __ptrace_detach() reaps the EXIT_ZOMBIE tracee if its
    ->real_parent is our sub-thread and we ignore SIGCHLD. But in this case
    we should wake up other threads which can sleep in do_wait().

    Signed-off-by: Oleg Nesterov
    Cc: Roland McGrath
    Cc: Vitaly Mayatskikh
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

13 Jul, 2009

1 commit


07 Jul, 2009

1 commit

  • do_execve() and ptrace_attach() return -EINTR if
    mutex_lock_interruptible(->cred_guard_mutex) fails.

    This is not right, change the code to return ERESTARTNOINTR.

    Perhaps we should also change proc_pid_attr_write().

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

    Oleg Nesterov
     

24 Jun, 2009

1 commit

  • The ->ptrace_may_access() methods are named confusingly - the real
    ptrace_may_access() returns a bool, while these security checks have
    a retval convention.

    Rename it to ptrace_access_check, to reduce the confusion factor.

    [ Impact: cleanup, no code changed ]

    Signed-off-by: Ingo Molnar
    Signed-off-by: James Morris

    Ingo Molnar
     

19 Jun, 2009

5 commits

  • Change ptrace_getsiginfo/ptrace_setsiginfo to use lock_task_sighand()
    without tasklist_lock. Perhaps it makes sense to make a single helper
    with "bool rw" argument.

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

    Oleg Nesterov
     
  • - 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
     
  • Remove the "Nasty, nasty" lock dance in ptrace_attach()/ptrace_traceme() -
    from now task_lock() has nothing to do with ptrace at all.

    With the recent changes nobody uses task_lock() to serialize with ptrace,
    but in fact it was never needed and it was never used consistently.

    However ptrace_attach() calls __ptrace_may_access() and needs task_lock()
    to pin task->mm for get_dumpable(). But we can call __ptrace_may_access()
    before we take tasklist_lock, ->cred_exec_mutex protects us against
    do_execve() path which can change creds and MMF_DUMP* flags.

    (ugly, but we can't use ptrace_may_access() because it hides the error
    code, so we have to take task_lock() and use __ptrace_may_access()).

    NOTE: this change assumes that LSM hooks, security_ptrace_may_access() and
    security_ptrace_traceme(), can be called without task_lock() held.

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

    Oleg Nesterov
     
  • ptrace_attach() and ptrace_traceme() are the last functions which look as
    if the untraced task can have task->ptrace != 0, this must not be
    possible. Change the code to just check ->ptrace != 0 and s/|=/=/ to set
    PT_PTRACED.

    Also, a couple of trivial whitespace cleanups in ptrace_attach().

    And move ptrace_traceme() up near ptrace_attach() to keep them close to
    each other.

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

    Oleg Nesterov
     
  • - Add PF_KTHREAD check to prevent attaching to the kernel thread
    with a borrowed ->mm.

    With or without this change we can race with daemonize() which
    can set PF_KTHREAD or clear ->mm after ptrace_attach() does the
    check, but this doesn't matter because reparent_to_kthreadd()
    does ptrace_unlink().

    - Kill "!task->mm" check. We don't really care about ->mm != NULL,
    and the task can call exit_mm() right after we drop task_lock().
    What we need is to make sure we can't attach after exit_notify(),
    check task->exit_state != 0 instead.

    Also, move the "already traced" check down for cosmetic reasons.

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

    Oleg Nesterov
     

12 Jun, 2009

1 commit

  • …s/security-testing-2.6

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (44 commits)
    nommu: Provide mmap_min_addr definition.
    TOMOYO: Add description of lists and structures.
    TOMOYO: Remove unused field.
    integrity: ima audit dentry_open failure
    TOMOYO: Remove unused parameter.
    security: use mmap_min_addr indepedently of security models
    TOMOYO: Simplify policy reader.
    TOMOYO: Remove redundant markers.
    SELinux: define audit permissions for audit tree netlink messages
    TOMOYO: Remove unused mutex.
    tomoyo: avoid get+put of task_struct
    smack: Remove redundant initialization.
    integrity: nfsd imbalance bug fix
    rootplug: Remove redundant initialization.
    smack: do not beyond ARRAY_SIZE of data
    integrity: move ima_counts_get
    integrity: path_check update
    IMA: Add __init notation to ima functions
    IMA: Minimal IMA policy and boot param for TCB IMA policy
    selinux: remove obsolete read buffer limit from sel_read_bool
    ...

    Linus Torvalds
     

11 Jun, 2009

1 commit

  • * 'tracing-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (244 commits)
    Revert "x86, bts: reenable ptrace branch trace support"
    tracing: do not translate event helper macros in print format
    ftrace/documentation: fix typo in function grapher name
    tracing/events: convert block trace points to TRACE_EVENT(), fix !CONFIG_BLOCK
    tracing: add protection around module events unload
    tracing: add trace_seq_vprint interface
    tracing: fix the block trace points print size
    tracing/events: convert block trace points to TRACE_EVENT()
    ring-buffer: fix ret in rb_add_time_stamp
    ring-buffer: pass in lockdep class key for reader_lock
    tracing: add annotation to what type of stack trace is recorded
    tracing: fix multiple use of __print_flags and __print_symbolic
    tracing/events: fix output format of user stack
    tracing/events: fix output format of kernel stack
    tracing/trace_stack: fix the number of entries in the header
    ring-buffer: discard timestamps that are at the start of the buffer
    ring-buffer: try to discard unneeded timestamps
    ring-buffer: fix bug in ring_buffer_discard_commit
    ftrace: do not profile functions when disabled
    tracing: make trace pipe recognize latency format flag
    ...

    Linus Torvalds
     

09 Jun, 2009

1 commit


05 Jun, 2009

1 commit

  • Commit 95a3540da9c81a5987be810e1d9a83640a366bd5 ("ptrace_detach: the wrong
    wakeup breaks the ERESTARTxxx logic") removed the "extra"
    wake_up_process() from ptrace_detach(), but as Jan pointed out this breaks
    the compatibility.

    I believe the changelog is right and this wake_up() is wrong in many
    ways, but GDB assumes that ptrace(PTRACE_DETACH, child, 0, 0) always
    wakes up the tracee.

    Despite the fact this breaks SIGNAL_STOP_STOPPED/group_stop_count logic,
    and despite the fact this wake_up_process() can break another
    assumption: PTRACE_DETACH with SIGSTOP should leave the tracee in
    TASK_STOPPED case. Because the untraced child can dequeue SIGSTOP and
    call do_signal_stop() before ptrace_detach() calls wake_up_process().

    Revert this change for now. We need some fixes even if we we want to keep
    the current behaviour, but these fixes are not for 2.6.30.

    Signed-off-by: Oleg Nesterov
    Acked-by: Roland McGrath
    Cc: Jan Kratochvil
    Cc: Denys Vlasenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     

11 May, 2009

1 commit


07 May, 2009

1 commit


27 Apr, 2009

1 commit


24 Apr, 2009

1 commit


14 Apr, 2009

1 commit

  • Pointed out by Roland. The bug was recently introduced by me in
    "forget_original_parent: split out the un-ptrace part", commit
    39c626ae47c469abdfd30c6e42eff884931380d6.

    Since that patch we have a window after exit_ptrace() drops tasklist and
    before forget_original_parent() takes it again. In this window the child
    can do ptrace(PTRACE_TRACEME) and nobody can untrace this child after
    that.

    Change ptrace_traceme() to not attach to the exiting ->real_parent. We
    don't report the error in this case, we pretend we attach right before
    ->real_parent calls exit_ptrace() which should untrace us anyway.

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

    Oleg Nesterov
     

09 Apr, 2009

1 commit

  • This fixes all the checkpatch --file complaints about kernel/ptrace.c
    and also removes an unused #include. I've verified that there are no
    changes to the compiled code on x86_64.

    Signed-off-by: Roland McGrath
    [ Removed the parts that just split a line - Linus ]
    Signed-off-by: Linus Torvalds

    Roland McGrath
     

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
     

04 Apr, 2009

1 commit


03 Apr, 2009

5 commits

  • This bug is ancient too. ptrace_untrace() must not resume the task
    if the group stop in progress, we should set TASK_STOPPED instead.

    Unfortunately, we still have problems here:

    - if the process/thread was traced, SIGNAL_STOP_STOPPED
    does not necessary means this thread group is stopped.

    - ptrace breaks the bookkeeping of ->group_stop_count.

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

    Oleg Nesterov
     
  • Another ancient bug. Consider this trivial test-case,

    int main(void)
    {
    int pid = fork();

    if (pid) {
    ptrace(PTRACE_ATTACH, pid, NULL, NULL);
    wait(NULL);
    ptrace(PTRACE_DETACH, pid, NULL, NULL);
    } else {
    pause();
    printf("WE HAVE A KERNEL BUG!!!\n");
    }

    return 0;
    }

    the child must not "escape" for sys_pause(), but it can and this was seen
    in practice.

    This is because ptrace_detach does:

    if (!child->exit_state)
    wake_up_process(child);

    this wakeup can happen after this child has already restarted sys_pause(),
    because it gets another wakeup from ptrace_untrace().

    With or without this patch, perhaps sys_pause() needs a fix. But this
    wakeup also breaks the SIGNAL_STOP_STOPPED logic in ptrace_untrace().

    Remove this wakeup. The caller saw this task in TASK_TRACED state, and
    unless it was SIGKILL'ed in between __ptrace_unlink()->ptrace_untrace()
    should handle this case correctly. If it was SIGKILL'ed, we don't need to
    wakup the dying tracee too.

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

    Oleg Nesterov
     
  • 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
     
  • Move the code from __ptrace_detach() to its single caller and kill this
    helper.

    Also, fix the ->exit_state check, we shouldn't wake up EXIT_DEAD tasks.
    Actually, I think task_is_stopped_or_traced() makes more sense, but this
    needs another patch.

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

    Oleg Nesterov
     

10 Mar, 2009

1 commit


14 Jan, 2009

1 commit


29 Dec, 2008

1 commit

  • …el/git/tip/linux-2.6-tip

    * 'tracing-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (241 commits)
    sched, trace: update trace_sched_wakeup()
    tracing/ftrace: don't trace on early stage of a secondary cpu boot, v3
    Revert "x86: disable X86_PTRACE_BTS"
    ring-buffer: prevent false positive warning
    ring-buffer: fix dangling commit race
    ftrace: enable format arguments checking
    x86, bts: memory accounting
    x86, bts: add fork and exit handling
    ftrace: introduce tracing_reset_online_cpus() helper
    tracing: fix warnings in kernel/trace/trace_sched_switch.c
    tracing: fix warning in kernel/trace/trace.c
    tracing/ring-buffer: remove unused ring_buffer size
    trace: fix task state printout
    ftrace: add not to regex on filtering functions
    trace: better use of stack_trace_enabled for boot up code
    trace: add a way to enable or disable the stack tracer
    x86: entry_64 - introduce FTRACE_ frame macro v2
    tracing/ftrace: add the printk-msg-only option
    tracing/ftrace: use preempt_enable_no_resched_notrace in ring_buffer_time_stamp()
    x86, bts: correctly report invalid bts records
    ...

    Fixed up trivial conflict in scripts/recordmcount.pl due to SH bits
    being already partly merged by the SH merge.

    Linus Torvalds
     

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
     

04 Dec, 2008

1 commit


01 Dec, 2008

1 commit

  • All architectures now use the generic compat_sys_ptrace, as should every
    new architecture that needs 32bit compat (if we'll ever get another).

    Remove the now superflous __ARCH_WANT_COMPAT_SYS_PTRACE define, and also
    kill a comment about __ARCH_SYS_PTRACE that was added after
    __ARCH_SYS_PTRACE was already gone.

    Signed-off-by: Christoph Hellwig
    Acked-by: David S. Miller
    Signed-off-by: Linus Torvalds

    Christoph Hellwig