14 Aug, 2008

1 commit

  • Fix the setting of PF_SUPERPRIV by __capable() as it could corrupt the flags
    the target process if that is not the current process and it is trying to
    change its own flags in a different way at the same time.

    __capable() is using neither atomic ops nor locking to protect t->flags. This
    patch removes __capable() and introduces has_capability() that doesn't set
    PF_SUPERPRIV on the process being queried.

    This patch further splits security_ptrace() in two:

    (1) security_ptrace_may_access(). This passes judgement on whether one
    process may access another only (PTRACE_MODE_ATTACH for ptrace() and
    PTRACE_MODE_READ for /proc), and takes a pointer to the child process.
    current is the parent.

    (2) security_ptrace_traceme(). This passes judgement on PTRACE_TRACEME only,
    and takes only a pointer to the parent process. current is the child.

    In Smack and commoncap, this uses has_capability() to determine whether
    the parent will be permitted to use PTRACE_ATTACH if normal checks fail.
    This does not set PF_SUPERPRIV.

    Two of the instances of __capable() actually only act on current, and so have
    been changed to calls to capable().

    Of the places that were using __capable():

    (1) The OOM killer calls __capable() thrice when weighing the killability of a
    process. All of these now use has_capability().

    (2) cap_ptrace() and smack_ptrace() were using __capable() to check to see
    whether the parent was allowed to trace any process. As mentioned above,
    these have been split. For PTRACE_ATTACH and /proc, capable() is now
    used, and for PTRACE_TRACEME, has_capability() is used.

    (3) cap_safe_nice() only ever saw current, so now uses capable().

    (4) smack_setprocattr() rejected accesses to tasks other than current just
    after calling __capable(), so the order of these two tests have been
    switched and capable() is used instead.

    (5) In smack_file_send_sigiotask(), we need to allow privileged processes to
    receive SIGIO on files they're manipulating.

    (6) In smack_task_wait(), we let a process wait for a privileged process,
    whether or not the process doing the waiting is privileged.

    I've tested this with the LTP SELinux and syscalls testscripts.

    Signed-off-by: David Howells
    Acked-by: Serge Hallyn
    Acked-by: Casey Schaufler
    Acked-by: Andrew G. Morgan
    Acked-by: Al Viro
    Signed-off-by: James Morris

    David Howells
     

27 Jul, 2008

1 commit

  • This extends wait_task_inactive() with a new argument so it can be used in
    a "soft" mode where it will check for the task changing state unexpectedly
    and back off. There is no change to existing callers. This lays the
    groundwork to allow robust, noninvasive tracing that can try to sample a
    blocked thread but back off safely if it wakes up.

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

    Roland McGrath
     

17 Jul, 2008

1 commit

  • ptrace no longer fiddles with the children/sibling links, and the
    old ptrace_children list is gone. Now ptrace, whether of one's own
    children or another's via PTRACE_ATTACH, just uses the new ptraced
    list instead.

    There should be no user-visible difference that matters. The only
    change is the order in which do_wait() sees multiple stopped
    children and stopped ptrace attachees. Since wait_task_stopped()
    was changed earlier so it no longer reorders the children list, we
    already know this won't cause any new problems.

    Signed-off-by: Roland McGrath

    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
     

02 May, 2008

1 commit

  • With s390 the last arch switched to the generic sys_ptrace yesterday so
    we can now kill the ifdef around it to enforce every new port it using
    it instead of introducing new weirdo versions.

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

    Christoph Hellwig
     

30 Apr, 2008

3 commits

  • Afaics, currently there are no kernel problems with ptracing init, it can't
    lose SIGNAL_UNKILLABLE flag and be killed/stopped by accident.

    The ability to strace/debug init can be very useful if you try to figure out
    why it does not work as expected.

    However, admin should know what he does, "gdb /sbin/init 1" stops init, it
    can't reap orphaned zombies or take care of /etc/inittab until continued. It
    is even possible to crash init (and thus the whole system) if you wish,
    ptracer has full control.

    See also the long discussion: http://marc.info/?t=120628018600001

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

    Oleg Nesterov
     
  • Nobody can block/ignore SIGSTOP, no need to use force_sig_specific() in
    ptrace_attach. Use the "regular" send_sig_info().

    With this patch stracing of /sbin/init doesn't clear its SIGNAL_UNKILLABLE,
    but not that this makes ptracing of init safe.

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

    Oleg Nesterov
     
  • Currently __ptrace_unlink() checks list_empty(->ptrace_list) to figure out
    whether the child was reparented. Change the code to use ptrace_reparented()
    to make this check more explicit and consistent.

    No functional changes.

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

    Oleg Nesterov
     

29 Apr, 2008

1 commit

  • My recent additions to compat_ptrace_request made it mandatory
    for CONFIG_COMPAT arch's to define copy_siginfo_from_user32.
    This broke some builds, though they all really should get cleaned
    up in that way.

    Since all the arch's that actually call compat_ptrace_request have
    now been cleaned up to use the generic compat_sys_ptrace, we can
    avoid the build problems on the crufty arch's by changing the
    conditionals on the definition.

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

    Roland McGrath
     

22 Apr, 2008

1 commit

  • This adds support for PTRACE_GETSIGINFO and PTRACE_SETSIGINFO in
    compat_ptrace_request. It relies on existing arch definitions for
    copy_siginfo_to_user32 and copy_siginfo_from_user32.

    On powerpc, this fixes a longstanding regression of 32-bit ptrace
    calls on 64-bit kernels vs native calls (64-bit calls or 32-bit
    kernels). This can be seen in a 32-bit call using PTRACE_GETSIGINFO
    to examine e.g. siginfo_t.si_addr from a signal that sets it.
    (This was broken as of 2.6.24 and, I presume, many or all prior versions.)

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

    Roland McGrath
     

09 Feb, 2008

2 commits

  • It is not possible to see the PT_PTRACED task without ->signal/sighand under
    tasklist_lock, release_task() does ptrace_unlink() first. If the task was
    already released before, ptrace_attach() can't succeed and set PT_PTRACED.
    Remove this check.

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

    Oleg Nesterov
     
  • 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

2 commits

  • Every file should include the headers containing the prototypes for its global
    functions (in this case sys_ptrace()).

    Signed-off-by: Adrian Bunk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Adrian Bunk
     
  • 1. It is much easier to grep for ->state change if __set_task_state() is used
    instead of the direct assignment.

    2. ptrace_stop() and handle_group_stop() use set_task_state() which adds the
    unneeded mb() (btw even if we use mb() it is still possible that do_wait()
    sees the new ->state but not ->exit_code, but this is ok).

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

    Oleg Nesterov
     

01 Feb, 2008

1 commit

  • * 'task_killable' of git://git.kernel.org/pub/scm/linux/kernel/git/willy/misc: (22 commits)
    Remove commented-out code copied from NFS
    NFS: Switch from intr mount option to TASK_KILLABLE
    Add wait_for_completion_killable
    Add wait_event_killable
    Add schedule_timeout_killable
    Use mutex_lock_killable in vfs_readdir
    Add mutex_lock_killable
    Use lock_page_killable
    Add lock_page_killable
    Add fatal_signal_pending
    Add TASK_WAKEKILL
    exit: Use task_is_*
    signal: Use task_is_*
    sched: Use task_contributes_to_load, TASK_ALL and TASK_NORMAL
    ptrace: Use task_is_*
    power: Use task_is_*
    wait: Use TASK_NORMAL
    proc/base.c: Use task_is_*
    proc/array.c: Use TASK_REPORT
    perfmon: Use task_is_*
    ...

    Fixed up conflicts in NFS/sunrpc manually..

    Linus Torvalds
     

30 Jan, 2008

5 commits

  • This adds a generic definition of compat_sys_ptrace that calls
    compat_arch_ptrace, parallel to sys_ptrace/arch_ptrace. Some
    machines needing this already define a function by that name.
    The new generic function is defined only on machines that
    put #define __ARCH_WANT_COMPAT_SYS_PTRACE into asm/ptrace.h.

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

    Roland McGrath
     
  • This adds a compat_ptrace_request that is the analogue of ptrace_request
    for the things that 32-on-64 ptrace implementations can share in common.
    So far there are just a couple of requests handled generically.

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

    Roland McGrath
     
  • This makes ptrace_request handle {PEEK,POKE}{TEXT,DATA} directly.
    Every arch_ptrace that could call generic_ptrace_peekdata already
    has a default case calling ptrace_request, so this keeps things
    simpler for the arch code.

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

    Roland McGrath
     
  • 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 makes ptrace_request handle all the ptrace requests that wake
    up the traced task. These do low-level ptrace implementation magic
    that is not arch-specific and should be kept out of arch code. The
    implementations on each arch usually do the same thing. The new
    generic code makes use of the arch_has_single_step macro and generic
    entry points to handle PTRACE_SINGLESTEP.

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

    Roland McGrath
     

25 Jan, 2008

1 commit

  • arch_ptrace_attach() is a hook that allows the architecture to do
    book-keeping after a ptrace attach. This patch adds a call to this
    hook when handling a PTRACE_TRACEME request as well.

    Currently only one architecture, m32r, implements this hook. When
    called, it initializes a number of debug trap slots in the ptraced
    task's thread struct, and it looks to me like this is the right thing
    to do after a PTRACE_TRACEME request as well, not only after
    PTRACE_ATTACH. Please correct me if I'm wrong.

    I want to use this hook on AVR32 to turn the debugging hardware on
    when a process is actually being debugged and keep it off otherwise.
    To be able to do this, I need to intercept PTRACE_TRACEME and
    PTRACE_ATTACH, as well as PTRACE_DETACH and thread exit. The latter
    two can be handled by existing hooks.

    Signed-off-by: Haavard Skinnemoen

    Haavard Skinnemoen
     

03 Jan, 2008

2 commits


07 Dec, 2007

1 commit


20 Oct, 2007

3 commits

  • With pid namespaces this field is now dangerous to use explicitly, so hide
    it behind the helpers.

    Also the pid and pgrp fields o task_struct and signal_struct are to be
    deprecated. Unfortunately this patch cannot be sent right now as this
    leads to tons of warnings, so start isolating them, and deprecate later.

    Actually the p->tgid == pid has to be changed to has_group_leader_pid(),
    but Oleg pointed out that in case of posix cpu timers this is the same, and
    thread_group_leader() is more preferable.

    Signed-off-by: Pavel Emelyanov
    Acked-by: Oleg Nesterov
    Cc: Sukadev Bhattiprolu
    Cc: "Eric W. Biederman"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelyanov
     
  • The find_task_by_something is a set of macros are used to find task by pid
    depending on what kind of pid is proposed - global or virtual one. All of
    them are wrappers above the most generic one - find_task_by_pid_type_ns() -
    and just substitute some args for it.

    It turned out, that dereferencing the current->nsproxy->pid_ns construction
    and pushing one more argument on the stack inline cause kernel text size to
    grow.

    This patch moves all this stuff out-of-line into kernel/pid.c. Together
    with the next patch it saves a bit less than 400 bytes from the .text
    section.

    Signed-off-by: Pavel Emelyanov
    Cc: Sukadev Bhattiprolu
    Cc: Oleg Nesterov
    Cc: Paul Menage
    Cc: "Eric W. Biederman"
    Acked-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelyanov
     
  • This is the largest patch in the set. Make all (I hope) the places where
    the pid is shown to or get from user operate on the virtual pids.

    The idea is:
    - all in-kernel data structures must store either struct pid itself
    or the pid's global nr, obtained with pid_nr() call;
    - when seeking the task from kernel code with the stored id one
    should use find_task_by_pid() call that works with global pids;
    - when showing pid's numerical value to the user the virtual one
    should be used, but however when one shows task's pid outside this
    task's namespace the global one is to be used;
    - when getting the pid from userspace one need to consider this as
    the virtual one and use appropriate task/pid-searching functions.

    [akpm@linux-foundation.org: build fix]
    [akpm@linux-foundation.org: nuther build fix]
    [akpm@linux-foundation.org: yet nuther build fix]
    [akpm@linux-foundation.org: remove unneeded casts]
    Signed-off-by: Pavel Emelyanov
    Signed-off-by: Alexey Dobriyan
    Cc: Sukadev Bhattiprolu
    Cc: Oleg Nesterov
    Cc: Paul Menage
    Cc: "Eric W. Biederman"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelyanov
     

17 Oct, 2007

2 commits

  • Convert m32r to the generic sys_ptrace. The conversion requires an
    architecture hook after ptrace_attach which this patch adds. The hook
    will also be needed for a conersion of ia64 to the generic ptrace code.

    Thanks to Hirokazu Takata for fixing a bug in the first version of this
    code.

    Signed-off-by: Christoph Hellwig
    Cc: Hirokazu Takata
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     
  • Identical handlers of PTRACE_DETACH go into ptrace_request().
    Not touching compat code.
    Not touching archs that don't call ptrace_request.

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

    Alexey Dobriyan
     

11 Sep, 2007

1 commit

  • When PTRACE_SYSCALL was used and then PTRACE_DETACH is used, the
    TIF_SYSCALL_TRACE flag is left set on the formerly-traced task. This
    means that when a new tracer comes along and does PTRACE_ATTACH, it's
    possible he gets a syscall tracing stop even though he's never used
    PTRACE_SYSCALL. This happens if the task was in the middle of a system
    call when the second PTRACE_ATTACH was done. The symptom is an
    unexpected SIGTRAP when the tracer thinks that only SIGSTOP should have
    been provoked by his ptrace calls so far.

    A few machines already fixed this in ptrace_disable (i386, ia64, m68k).
    But all other machines do not, and still have this bug. On x86_64, this
    constitutes a regression in IA32 compatibility support.

    Since all machines now use TIF_SYSCALL_TRACE for this, I put the
    clearing of TIF_SYSCALL_TRACE in the generic ptrace_detach code rather
    than adding it to every other machine's ptrace_disable.

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

    Roland McGrath
     

20 Jul, 2007

1 commit

  • This patch changes mm_struct.dumpable to a pair of bit flags.

    set_dumpable() converts three-value dumpable to two flags and stores it into
    lower two bits of mm_struct.flags instead of mm_struct.dumpable.
    get_dumpable() behaves in the opposite way.

    [akpm@linux-foundation.org: export set_dumpable]
    Signed-off-by: Hidehiro Kawai
    Cc: Alan Cox
    Cc: David Howells
    Cc: Hugh Dickins
    Cc: Nick Piggin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kawai, Hidehiro
     

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
     

17 Jul, 2007

1 commit


11 May, 2007

1 commit


30 Sep, 2006

1 commit

  • This is an updated version of Eric Biederman's is_init() patch.
    (http://lkml.org/lkml/2006/2/6/280). It applies cleanly to 2.6.18-rc3 and
    replaces a few more instances of ->pid == 1 with is_init().

    Further, is_init() checks pid and thus removes dependency on Eric's other
    patches for now.

    Eric's original description:

    There are a lot of places in the kernel where we test for init
    because we give it special properties. Most significantly init
    must not die. This results in code all over the kernel test
    ->pid == 1.

    Introduce is_init to capture this case.

    With multiple pid spaces for all of the cases affected we are
    looking for only the first process on the system, not some other
    process that has pid == 1.

    Signed-off-by: Eric W. Biederman
    Signed-off-by: Sukadev Bhattiprolu
    Cc: Dave Hansen
    Cc: Serge Hallyn
    Cc: Cedric Le Goater
    Cc:
    Acked-by: Paul Mackerras
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sukadev Bhattiprolu
     

27 Sep, 2006

1 commit


04 Jul, 2006

1 commit


27 Jun, 2006

2 commits

  • 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
     
  • In process of getting proc_fd_access_allowed to work it has developed a few
    warts. In particular the special case that always allows introspection and
    the special case to allow inspection of kernel threads.

    The special case for introspection is needed for /proc/self/mem.

    The special case for kernel threads really should be overridable
    by security modules.

    So consolidate these checks into ptrace.c:may_attach().

    The check to always allow introspection is trivial.

    The check to allow access to kernel threads, and zombies is a little
    trickier. mem_read and mem_write already verify an mm exists so it isn't
    needed twice. proc_fd_access_allowed only doesn't want a check to verify
    task->mm exits, s it prevents all access to kernel threads. So just move
    the task->mm check into ptrace_attach where it is needed for practical
    reasons.

    I did a quick audit and none of the security modules in the kernel seem to
    care if they are passed a task without an mm into security_ptrace. So the
    above move should be safe and it allows security modules to come up with
    more restrictive policy.

    Signed-off-by: Eric W. Biederman
    Cc: Stephen Smalley
    Cc: Chris Wright
    Cc: James Morris
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman