22 Jun, 2017

1 commit

  • This patch suppresses gcc 7 warnings about falling through in switch
    statements when building with W=1. From the gcc documentation: The
    -Wimplicit-fallthrough=3 warning is enabled by -Wextra. See also
    https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html.

    Signed-off-by: Bart Van Assche
    Signed-off-by: Jens Axboe

    Bart Van Assche
     

20 Apr, 2017

1 commit

  • Since ioprio_best() translates IOPRIO_CLASS_NONE into IOPRIO_CLASS_BE
    and since lower numerical priority values represent a higher priority
    a simple numerical comparison is sufficient.

    Signed-off-by: Bart Van Assche
    Reviewed-by: Adam Manzanares
    Tested-by: Adam Manzanares
    Reviewed-by: Christoph Hellwig
    Cc: Matias Bjørling
    Signed-off-by: Jens Axboe

    Bart Van Assche
     

02 Mar, 2017

3 commits


23 Feb, 2017

1 commit

  • IOPRIO_WHO_USER case in sys_ioprio_set()/sys_ioprio_get() are using
    while_each_thread(), which is unsafe under RCU lock according to commit
    0c740d0afc3bff0a ("introduce for_each_thread() to replace the buggy
    while_each_thread()"). Use for_each_thread() (via
    for_each_process_thread()) which is safe under RCU lock.

    Link: http://lkml.kernel.org/r/201702011947.DBD56740.OMVHOLOtSJFFFQ@I-love.SAKURA.ne.jp
    Link: http://lkml.kernel.org/r/1486041779-4401-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp
    Signed-off-by: Tetsuo Handa
    Cc: Oleg Nesterov
    Cc: Jens Axboe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tetsuo Handa
     

01 Jul, 2016

1 commit

  • get_task_ioprio() accesses the task->io_context without holding the task
    lock and thus can race with exit_io_context(), leading to a
    use-after-free. The reproducer below hits this within a few seconds on
    my 4-core QEMU VM:

    #define _GNU_SOURCE
    #include
    #include
    #include
    #include

    int main(int argc, char **argv)
    {
    pid_t pid, child;
    long nproc, i;

    /* ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)); */
    syscall(SYS_ioprio_set, 1, 0, 0x6000);

    nproc = sysconf(_SC_NPROCESSORS_ONLN);

    for (i = 0; i < nproc; i++) {
    pid = fork();
    assert(pid != -1);
    if (pid == 0) {
    for (;;) {
    pid = fork();
    assert(pid != -1);
    if (pid == 0) {
    _exit(0);
    } else {
    child = wait(NULL);
    assert(child == pid);
    }
    }
    }

    pid = fork();
    assert(pid != -1);
    if (pid == 0) {
    for (;;) {
    /* ioprio_get(IOPRIO_WHO_PGRP, 0); */
    syscall(SYS_ioprio_get, 2, 0);
    }
    }
    }

    for (;;) {
    /* ioprio_get(IOPRIO_WHO_PGRP, 0); */
    syscall(SYS_ioprio_get, 2, 0);
    }

    return 0;
    }

    This gets us KASAN dumps like this:

    [ 35.526914] ==================================================================
    [ 35.530009] BUG: KASAN: out-of-bounds in get_task_ioprio+0x7b/0x90 at addr ffff880066f34e6c
    [ 35.530009] Read of size 2 by task ioprio-gpf/363
    [ 35.530009] =============================================================================
    [ 35.530009] BUG blkdev_ioc (Not tainted): kasan: bad access detected
    [ 35.530009] -----------------------------------------------------------------------------

    [ 35.530009] Disabling lock debugging due to kernel taint
    [ 35.530009] INFO: Allocated in create_task_io_context+0x2b/0x370 age=0 cpu=0 pid=360
    [ 35.530009] ___slab_alloc+0x55d/0x5a0
    [ 35.530009] __slab_alloc.isra.20+0x2b/0x40
    [ 35.530009] kmem_cache_alloc_node+0x84/0x200
    [ 35.530009] create_task_io_context+0x2b/0x370
    [ 35.530009] get_task_io_context+0x92/0xb0
    [ 35.530009] copy_process.part.8+0x5029/0x5660
    [ 35.530009] _do_fork+0x155/0x7e0
    [ 35.530009] SyS_clone+0x19/0x20
    [ 35.530009] do_syscall_64+0x195/0x3a0
    [ 35.530009] return_from_SYSCALL_64+0x0/0x6a
    [ 35.530009] INFO: Freed in put_io_context+0xe7/0x120 age=0 cpu=0 pid=1060
    [ 35.530009] __slab_free+0x27b/0x3d0
    [ 35.530009] kmem_cache_free+0x1fb/0x220
    [ 35.530009] put_io_context+0xe7/0x120
    [ 35.530009] put_io_context_active+0x238/0x380
    [ 35.530009] exit_io_context+0x66/0x80
    [ 35.530009] do_exit+0x158e/0x2b90
    [ 35.530009] do_group_exit+0xe5/0x2b0
    [ 35.530009] SyS_exit_group+0x1d/0x20
    [ 35.530009] entry_SYSCALL_64_fastpath+0x1a/0xa4
    [ 35.530009] INFO: Slab 0xffffea00019bcd00 objects=20 used=4 fp=0xffff880066f34ff0 flags=0x1fffe0000004080
    [ 35.530009] INFO: Object 0xffff880066f34e58 @offset=3672 fp=0x0000000000000001
    [ 35.530009] ==================================================================

    Fix it by grabbing the task lock while we poke at the io_context.

    Cc: stable@vger.kernel.org
    Reported-by: Dmitry Vyukov
    Signed-off-by: Omar Sandoval
    Signed-off-by: Jens Axboe

    Omar Sandoval
     

07 Nov, 2015

1 commit

  • setpriority(PRIO_USER, 0, x) will change the priority of tasks outside of
    the current pid namespace. This is in contrast to both the other modes of
    setpriority and the example of kill(-1). Fix this. getpriority and
    ioprio have the same failure mode, fix them too.

    Eric said:

    : After some more thinking about it this patch sounds justifiable.
    :
    : My goal with namespaces is not to build perfect isolation mechanisms
    : as that can get into ill defined territory, but to build well defined
    : mechanisms. And to handle the corner cases so you can use only
    : a single namespace with well defined results.
    :
    : In this case you have found the two interfaces I am aware of that
    : identify processes by uid instead of by pid. Which quite frankly is
    : weird. Unfortunately the weird unexpected cases are hard to handle
    : in the usual way.
    :
    : I was hoping for a little more information. Changes like this one we
    : have to be careful of because someone might be depending on the current
    : behavior. I don't think they are and I do think this make sense as part
    : of the pid namespace.

    Signed-off-by: Ben Segall
    Cc: Oleg Nesterov
    Cc: Al Viro
    Cc: Ambrose Feinstein
    Acked-by: "Eric W. Biederman"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ben Segall
     

31 Oct, 2014

1 commit

  • Priority of a merged request is computed by ioprio_best(). If one of the
    requests has undefined priority (IOPRIO_CLASS_NONE) and another request
    has priority from IOPRIO_CLASS_BE, the function will return the
    undefined priority which is wrong. Fix the function to properly return
    priority of a request with the defined priority.

    Fixes: d58cdfb89ce0c6bd5f81ae931a984ef298dbda20
    CC: stable@vger.kernel.org
    Signed-off-by: Jan Kara
    Reviewed-by: Jeff Moyer
    Signed-off-by: Jens Axboe

    Jan Kara
     

20 May, 2014

1 commit