signal: Use PIDTYPE_TGID to clearly store where file signals will be sent
When f_setown is called a pid and a pid type are stored. Replace the use of PIDTYPE_PID with PIDTYPE_TGID as PIDTYPE_TGID goes to the entire thread group. Replace the use of PIDTYPE_MAX with PIDTYPE_PID as PIDTYPE_PID now is only for a thread. Update the users of __f_setown to use PIDTYPE_TGID instead of PIDTYPE_PID. For now the code continues to capture task_pid (when task_tgid would really be appropriate), and iterate on PIDTYPE_PID (even when type == PIDTYPE_TGID) out of an abundance of caution to preserve existing behavior. Oleg Nesterov suggested using the test to ensure we use PIDTYPE_PID for tgid lookup also be used to avoid taking the tasklist lock. Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
This commit is contained in:
parent
6883f81aac
commit
019191342f
5 changed files with 37 additions and 26 deletions
|
@ -3216,7 +3216,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (on) {
|
if (on) {
|
||||||
__f_setown(file, task_pid(current), PIDTYPE_PID, 0);
|
__f_setown(file, task_pid(current), PIDTYPE_TGID, 0);
|
||||||
tfile->flags |= TUN_FASYNC;
|
tfile->flags |= TUN_FASYNC;
|
||||||
} else
|
} else
|
||||||
tfile->flags &= ~TUN_FASYNC;
|
tfile->flags &= ~TUN_FASYNC;
|
||||||
|
|
|
@ -2122,7 +2122,7 @@ static int __tty_fasync(int fd, struct file *filp, int on)
|
||||||
type = PIDTYPE_PGID;
|
type = PIDTYPE_PGID;
|
||||||
} else {
|
} else {
|
||||||
pid = task_pid(current);
|
pid = task_pid(current);
|
||||||
type = PIDTYPE_PID;
|
type = PIDTYPE_TGID;
|
||||||
}
|
}
|
||||||
get_pid(pid);
|
get_pid(pid);
|
||||||
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
|
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
|
||||||
|
|
34
fs/fcntl.c
34
fs/fcntl.c
|
@ -116,7 +116,7 @@ int f_setown(struct file *filp, unsigned long arg, int force)
|
||||||
struct pid *pid = NULL;
|
struct pid *pid = NULL;
|
||||||
int who = arg, ret = 0;
|
int who = arg, ret = 0;
|
||||||
|
|
||||||
type = PIDTYPE_PID;
|
type = PIDTYPE_TGID;
|
||||||
if (who < 0) {
|
if (who < 0) {
|
||||||
/* avoid overflow below */
|
/* avoid overflow below */
|
||||||
if (who == INT_MIN)
|
if (who == INT_MIN)
|
||||||
|
@ -143,7 +143,7 @@ EXPORT_SYMBOL(f_setown);
|
||||||
|
|
||||||
void f_delown(struct file *filp)
|
void f_delown(struct file *filp)
|
||||||
{
|
{
|
||||||
f_modown(filp, NULL, PIDTYPE_PID, 1);
|
f_modown(filp, NULL, PIDTYPE_TGID, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t f_getown(struct file *filp)
|
pid_t f_getown(struct file *filp)
|
||||||
|
@ -171,11 +171,11 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
|
||||||
|
|
||||||
switch (owner.type) {
|
switch (owner.type) {
|
||||||
case F_OWNER_TID:
|
case F_OWNER_TID:
|
||||||
type = PIDTYPE_MAX;
|
type = PIDTYPE_PID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case F_OWNER_PID:
|
case F_OWNER_PID:
|
||||||
type = PIDTYPE_PID;
|
type = PIDTYPE_TGID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case F_OWNER_PGRP:
|
case F_OWNER_PGRP:
|
||||||
|
@ -206,11 +206,11 @@ static int f_getown_ex(struct file *filp, unsigned long arg)
|
||||||
read_lock(&filp->f_owner.lock);
|
read_lock(&filp->f_owner.lock);
|
||||||
owner.pid = pid_vnr(filp->f_owner.pid);
|
owner.pid = pid_vnr(filp->f_owner.pid);
|
||||||
switch (filp->f_owner.pid_type) {
|
switch (filp->f_owner.pid_type) {
|
||||||
case PIDTYPE_MAX:
|
case PIDTYPE_PID:
|
||||||
owner.type = F_OWNER_TID;
|
owner.type = F_OWNER_TID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PIDTYPE_PID:
|
case PIDTYPE_TGID:
|
||||||
owner.type = F_OWNER_PID;
|
owner.type = F_OWNER_PID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -785,20 +785,25 @@ void send_sigio(struct fown_struct *fown, int fd, int band)
|
||||||
read_lock(&fown->lock);
|
read_lock(&fown->lock);
|
||||||
|
|
||||||
type = fown->pid_type;
|
type = fown->pid_type;
|
||||||
if (type == PIDTYPE_MAX) {
|
if (type == PIDTYPE_PID)
|
||||||
group = 0;
|
group = 0;
|
||||||
type = PIDTYPE_PID;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fown->pid;
|
pid = fown->pid;
|
||||||
if (!pid)
|
if (!pid)
|
||||||
goto out_unlock_fown;
|
goto out_unlock_fown;
|
||||||
|
|
||||||
|
if (type <= PIDTYPE_TGID) {
|
||||||
|
rcu_read_lock();
|
||||||
|
p = pid_task(pid, PIDTYPE_PID);
|
||||||
|
send_sigio_to_task(p, fown, fd, band, group);
|
||||||
|
rcu_read_unlock();
|
||||||
|
} else {
|
||||||
read_lock(&tasklist_lock);
|
read_lock(&tasklist_lock);
|
||||||
do_each_pid_task(pid, type, p) {
|
do_each_pid_task(pid, type, p) {
|
||||||
send_sigio_to_task(p, fown, fd, band, group);
|
send_sigio_to_task(p, fown, fd, band, group);
|
||||||
} while_each_pid_task(pid, type, p);
|
} while_each_pid_task(pid, type, p);
|
||||||
read_unlock(&tasklist_lock);
|
read_unlock(&tasklist_lock);
|
||||||
|
}
|
||||||
out_unlock_fown:
|
out_unlock_fown:
|
||||||
read_unlock(&fown->lock);
|
read_unlock(&fown->lock);
|
||||||
}
|
}
|
||||||
|
@ -821,10 +826,8 @@ int send_sigurg(struct fown_struct *fown)
|
||||||
read_lock(&fown->lock);
|
read_lock(&fown->lock);
|
||||||
|
|
||||||
type = fown->pid_type;
|
type = fown->pid_type;
|
||||||
if (type == PIDTYPE_MAX) {
|
if (type == PIDTYPE_PID)
|
||||||
group = 0;
|
group = 0;
|
||||||
type = PIDTYPE_PID;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fown->pid;
|
pid = fown->pid;
|
||||||
if (!pid)
|
if (!pid)
|
||||||
|
@ -832,11 +835,18 @@ int send_sigurg(struct fown_struct *fown)
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
|
if (type <= PIDTYPE_TGID) {
|
||||||
|
rcu_read_lock();
|
||||||
|
p = pid_task(pid, PIDTYPE_PID);
|
||||||
|
send_sigurg_to_task(p, fown, group);
|
||||||
|
rcu_read_unlock();
|
||||||
|
} else {
|
||||||
read_lock(&tasklist_lock);
|
read_lock(&tasklist_lock);
|
||||||
do_each_pid_task(pid, type, p) {
|
do_each_pid_task(pid, type, p) {
|
||||||
send_sigurg_to_task(p, fown, group);
|
send_sigurg_to_task(p, fown, group);
|
||||||
} while_each_pid_task(pid, type, p);
|
} while_each_pid_task(pid, type, p);
|
||||||
read_unlock(&tasklist_lock);
|
read_unlock(&tasklist_lock);
|
||||||
|
}
|
||||||
out_unlock_fown:
|
out_unlock_fown:
|
||||||
read_unlock(&fown->lock);
|
read_unlock(&fown->lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -546,7 +546,7 @@ lease_setup(struct file_lock *fl, void **priv)
|
||||||
if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa))
|
if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa))
|
||||||
*priv = NULL;
|
*priv = NULL;
|
||||||
|
|
||||||
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
|
__f_setown(filp, task_pid(current), PIDTYPE_TGID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct lock_manager_operations lease_manager_ops = {
|
static const struct lock_manager_operations lease_manager_ops = {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
|
#include <linux/sched/signal.h>
|
||||||
#include <linux/dnotify.h>
|
#include <linux/dnotify.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
|
@ -353,7 +354,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
|
__f_setown(filp, task_pid(current), PIDTYPE_TGID, 0);
|
||||||
|
|
||||||
error = attach_dn(dn, dn_mark, id, fd, filp, mask);
|
error = attach_dn(dn, dn_mark, id, fd, filp, mask);
|
||||||
/* !error means that we attached the dn to the dn_mark, so don't free it */
|
/* !error means that we attached the dn to the dn_mark, so don't free it */
|
||||||
|
|
Loading…
Add table
Reference in a new issue