[PATCH] pids: sys_getsid: make sure we don't return 0 instead of -ESRCH - Kernel

This is a discussion on [PATCH] pids: sys_getsid: make sure we don't return 0 instead of -ESRCH - Kernel ; The task can exit between find_task_by_vpid() and task_session_vnr(), in that unlikely case sys_getsid() returns 0 instead of -ESRCH. The bug was introduced by me in ac9a8e3f0f43d20fc316162e8e5f9186d295ff49. Signed-off-by: Oleg Nesterov --- 25/kernel/sys.c~1_GETSID 2008-03-20 18:21:17.000000000 +0300 +++ 25/kernel/sys.c 2008-03-23 19:25:36.000000000 +0300 @@ ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: [PATCH] pids: sys_getsid: make sure we don't return 0 instead of -ESRCH

  1. [PATCH] pids: sys_getsid: make sure we don't return 0 instead of -ESRCH

    The task can exit between find_task_by_vpid() and task_session_vnr(), in
    that unlikely case sys_getsid() returns 0 instead of -ESRCH.

    The bug was introduced by me in ac9a8e3f0f43d20fc316162e8e5f9186d295ff49.

    Signed-off-by: Oleg Nesterov

    --- 25/kernel/sys.c~1_GETSID 2008-03-20 18:21:17.000000000 +0300
    +++ 25/kernel/sys.c 2008-03-23 19:25:36.000000000 +0300
    @@ -1019,19 +1019,19 @@ asmlinkage long sys_getsid(pid_t pid)
    if (!pid)
    return task_session_vnr(current);
    else {
    - int retval;
    + int retval = 0;
    struct task_struct *p;

    rcu_read_lock();
    p = find_task_by_vpid(pid);
    - retval = -ESRCH;
    if (p) {
    retval = security_task_getsid(p);
    if (!retval)
    retval = task_session_vnr(p);
    }
    rcu_read_unlock();
    - return retval;
    +
    + return retval ?: -ESRCH;
    }
    }


    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  2. Re: [PATCH] pids: sys_getsid: make sure we don't return 0 instead of -ESRCH

    Sorry! please ignore this patch and
    "[PATCH] pids: sys_getpgid: use rcu_read_lock() instead of tasklist_lock",

    I'll send the updated version.

    It turns out that sys_getsid/sys_getpgid have other problems which should
    be fixed.

    On 03/23, Oleg Nesterov wrote:
    >
    > The task can exit between find_task_by_vpid() and task_session_vnr(), in
    > that unlikely case sys_getsid() returns 0 instead of -ESRCH.
    >
    > The bug was introduced by me in ac9a8e3f0f43d20fc316162e8e5f9186d295ff49.
    >
    > Signed-off-by: Oleg Nesterov
    >
    > --- 25/kernel/sys.c~1_GETSID 2008-03-20 18:21:17.000000000 +0300
    > +++ 25/kernel/sys.c 2008-03-23 19:25:36.000000000 +0300
    > @@ -1019,19 +1019,19 @@ asmlinkage long sys_getsid(pid_t pid)
    > if (!pid)
    > return task_session_vnr(current);
    > else {
    > - int retval;
    > + int retval = 0;
    > struct task_struct *p;
    >
    > rcu_read_lock();
    > p = find_task_by_vpid(pid);
    > - retval = -ESRCH;
    > if (p) {
    > retval = security_task_getsid(p);
    > if (!retval)
    > retval = task_session_vnr(p);
    > }
    > rcu_read_unlock();
    > - return retval;
    > +
    > + return retval ?: -ESRCH;
    > }
    > }
    >


    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread