diff options
author | Oleg Nesterov <oleg@redhat.com> | 2009-04-02 19:58:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-02 22:05:02 -0400 |
commit | 52ee2dfdd4f51cf422ea6a96a0846dc94244aa37 (patch) | |
tree | e15753e01d2c2fbe980edc45f78a9ae77d2cf891 /include | |
parent | 2ae448efc87df6d328f5835969076c7f9fce59c3 (diff) |
pids: refactor vnr/nr_ns helpers to make them safe
Inho, the safety rules for vnr/nr_ns helpers are horrible and buggy.
task_pid_nr_ns(task) needs rcu/tasklist depending on task == current.
As for "special" pids, vnr/nr_ns helpers always need rcu. However, if
task != current, they are unsafe even under rcu lock, we can't trust
task->group_leader without the special checks.
And almost every helper has a callsite which needs a fix.
Also, it is a bit annoying that the implementations of, say,
task_pgrp_vnr() and task_pgrp_nr_ns() are not "symmetrical".
This patch introduces the new helper, __task_pid_nr_ns(), which is always
safe to use, and turns all other helpers into the trivial wrappers.
After this I'll send another patch which converts task_tgid_xxx() as well,
they're are a bit special.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Louis Rilling <Louis.Rilling@kerlabs.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Emelyanov <xemul@openvz.org>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/sched.h | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 722dd313bf8a..49df878a0cad 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1519,17 +1519,23 @@ struct pid_namespace; | |||
1519 | * | 1519 | * |
1520 | * see also pid_nr() etc in include/linux/pid.h | 1520 | * see also pid_nr() etc in include/linux/pid.h |
1521 | */ | 1521 | */ |
1522 | pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, | ||
1523 | struct pid_namespace *ns); | ||
1522 | 1524 | ||
1523 | static inline pid_t task_pid_nr(struct task_struct *tsk) | 1525 | static inline pid_t task_pid_nr(struct task_struct *tsk) |
1524 | { | 1526 | { |
1525 | return tsk->pid; | 1527 | return tsk->pid; |
1526 | } | 1528 | } |
1527 | 1529 | ||
1528 | pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); | 1530 | static inline pid_t task_pid_nr_ns(struct task_struct *tsk, |
1531 | struct pid_namespace *ns) | ||
1532 | { | ||
1533 | return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns); | ||
1534 | } | ||
1529 | 1535 | ||
1530 | static inline pid_t task_pid_vnr(struct task_struct *tsk) | 1536 | static inline pid_t task_pid_vnr(struct task_struct *tsk) |
1531 | { | 1537 | { |
1532 | return pid_vnr(task_pid(tsk)); | 1538 | return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL); |
1533 | } | 1539 | } |
1534 | 1540 | ||
1535 | 1541 | ||
@@ -1551,11 +1557,15 @@ static inline pid_t task_pgrp_nr(struct task_struct *tsk) | |||
1551 | return tsk->signal->__pgrp; | 1557 | return tsk->signal->__pgrp; |
1552 | } | 1558 | } |
1553 | 1559 | ||
1554 | pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); | 1560 | static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, |
1561 | struct pid_namespace *ns) | ||
1562 | { | ||
1563 | return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns); | ||
1564 | } | ||
1555 | 1565 | ||
1556 | static inline pid_t task_pgrp_vnr(struct task_struct *tsk) | 1566 | static inline pid_t task_pgrp_vnr(struct task_struct *tsk) |
1557 | { | 1567 | { |
1558 | return pid_vnr(task_pgrp(tsk)); | 1568 | return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL); |
1559 | } | 1569 | } |
1560 | 1570 | ||
1561 | 1571 | ||
@@ -1564,14 +1574,17 @@ static inline pid_t task_session_nr(struct task_struct *tsk) | |||
1564 | return tsk->signal->__session; | 1574 | return tsk->signal->__session; |
1565 | } | 1575 | } |
1566 | 1576 | ||
1567 | pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); | 1577 | static inline pid_t task_session_nr_ns(struct task_struct *tsk, |
1578 | struct pid_namespace *ns) | ||
1579 | { | ||
1580 | return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns); | ||
1581 | } | ||
1568 | 1582 | ||
1569 | static inline pid_t task_session_vnr(struct task_struct *tsk) | 1583 | static inline pid_t task_session_vnr(struct task_struct *tsk) |
1570 | { | 1584 | { |
1571 | return pid_vnr(task_session(tsk)); | 1585 | return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL); |
1572 | } | 1586 | } |
1573 | 1587 | ||
1574 | |||
1575 | /** | 1588 | /** |
1576 | * pid_alive - check that a task structure is not stale | 1589 | * pid_alive - check that a task structure is not stale |
1577 | * @p: Task structure to be checked. | 1590 | * @p: Task structure to be checked. |