mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
audit: Use rcu for task lookup protection
Protect the task lookups in audit_receive_msg() with rcu_read_lock() instead of tasklist_lock and use lock/unlock_sighand to protect against the exit race. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Eric Paris <eparis@redhat.com> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
207032051a
commit
ab263f47c9
1 changed files with 14 additions and 16 deletions
|
@ -873,17 +873,16 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||||||
case AUDIT_TTY_GET: {
|
case AUDIT_TTY_GET: {
|
||||||
struct audit_tty_status s;
|
struct audit_tty_status s;
|
||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
read_lock(&tasklist_lock);
|
rcu_read_lock();
|
||||||
tsk = find_task_by_vpid(pid);
|
tsk = find_task_by_vpid(pid);
|
||||||
if (!tsk)
|
if (tsk && lock_task_sighand(tsk, &flags)) {
|
||||||
err = -ESRCH;
|
|
||||||
else {
|
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
|
||||||
s.enabled = tsk->signal->audit_tty != 0;
|
s.enabled = tsk->signal->audit_tty != 0;
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
unlock_task_sighand(tsk, &flags);
|
||||||
}
|
} else
|
||||||
read_unlock(&tasklist_lock);
|
err = -ESRCH;
|
||||||
|
rcu_read_unlock();
|
||||||
|
|
||||||
if (!err)
|
if (!err)
|
||||||
audit_send_reply(NETLINK_CB(skb).pid, seq,
|
audit_send_reply(NETLINK_CB(skb).pid, seq,
|
||||||
|
@ -893,22 +892,21 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||||||
case AUDIT_TTY_SET: {
|
case AUDIT_TTY_SET: {
|
||||||
struct audit_tty_status *s;
|
struct audit_tty_status *s;
|
||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
if (nlh->nlmsg_len < sizeof(struct audit_tty_status))
|
if (nlh->nlmsg_len < sizeof(struct audit_tty_status))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
s = data;
|
s = data;
|
||||||
if (s->enabled != 0 && s->enabled != 1)
|
if (s->enabled != 0 && s->enabled != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
read_lock(&tasklist_lock);
|
rcu_read_lock();
|
||||||
tsk = find_task_by_vpid(pid);
|
tsk = find_task_by_vpid(pid);
|
||||||
if (!tsk)
|
if (tsk && lock_task_sighand(tsk, &flags)) {
|
||||||
err = -ESRCH;
|
|
||||||
else {
|
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
|
||||||
tsk->signal->audit_tty = s->enabled != 0;
|
tsk->signal->audit_tty = s->enabled != 0;
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
unlock_task_sighand(tsk, &flags);
|
||||||
}
|
} else
|
||||||
read_unlock(&tasklist_lock);
|
err = -ESRCH;
|
||||||
|
rcu_read_unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue