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, and gather the pid with task_tgid.  As the intent of
PIDTYPE_PID was a thread group level owner.

Signed-off-by: "Eric W. Biederman" <[email protected]>
---
 drivers/net/tun.c           |  2 +-
 drivers/tty/tty_io.c        |  4 ++--
 fs/fcntl.c                  | 20 ++++++++------------
 fs/locks.c                  |  2 +-
 fs/notify/dnotify/dnotify.c |  3 ++-
 5 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a192a017cc68..4219735a5418 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3216,7 +3216,7 @@ static int tun_chr_fasync(int fd, struct file *file, int 
on)
                goto out;
 
        if (on) {
-               __f_setown(file, task_pid(current), PIDTYPE_PID, 0);
+               __f_setown(file, task_tgid(current), PIDTYPE_TGID, 0);
                tfile->flags |= TUN_FASYNC;
        } else
                tfile->flags &= ~TUN_FASYNC;
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index aba59521ad48..cec58c53b0c4 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2121,8 +2121,8 @@ static int __tty_fasync(int fd, struct file *filp, int on)
                        pid = tty->pgrp;
                        type = PIDTYPE_PGID;
                } else {
-                       pid = task_pid(current);
-                       type = PIDTYPE_PID;
+                       pid = task_tgid(current);
+                       type = PIDTYPE_TGID;
                }
                get_pid(pid);
                spin_unlock_irqrestore(&tty->ctrl_lock, flags);
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 12273b6ea56d..cf10909cfa0a 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -116,7 +116,7 @@ int f_setown(struct file *filp, unsigned long arg, int 
force)
        struct pid *pid = NULL;
        int who = arg, ret = 0;
 
-       type = PIDTYPE_PID;
+       type = PIDTYPE_TGID;
        if (who < 0) {
                /* avoid overflow below */
                if (who == INT_MIN)
@@ -143,7 +143,7 @@ EXPORT_SYMBOL(f_setown);
 
 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)
@@ -171,11 +171,11 @@ static int f_setown_ex(struct file *filp, unsigned long 
arg)
 
        switch (owner.type) {
        case F_OWNER_TID:
-               type = PIDTYPE_MAX;
+               type = PIDTYPE_PID;
                break;
 
        case F_OWNER_PID:
-               type = PIDTYPE_PID;
+               type = PIDTYPE_TGID;
                break;
 
        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);
        owner.pid = pid_vnr(filp->f_owner.pid);
        switch (filp->f_owner.pid_type) {
-       case PIDTYPE_MAX:
+       case PIDTYPE_PID:
                owner.type = F_OWNER_TID;
                break;
 
-       case PIDTYPE_PID:
+       case PIDTYPE_TGID:
                owner.type = F_OWNER_PID;
                break;
 
@@ -785,10 +785,8 @@ void send_sigio(struct fown_struct *fown, int fd, int band)
        read_lock(&fown->lock);
 
        type = fown->pid_type;
-       if (type == PIDTYPE_MAX) {
+       if (type == PIDTYPE_PID)
                group = 0;
-               type = PIDTYPE_PID;
-       }
 
        pid = fown->pid;
        if (!pid)
@@ -821,10 +819,8 @@ int send_sigurg(struct fown_struct *fown)
        read_lock(&fown->lock);
 
        type = fown->pid_type;
-       if (type == PIDTYPE_MAX) {
+       if (type == PIDTYPE_PID)
                group = 0;
-               type = PIDTYPE_PID;
-       }
 
        pid = fown->pid;
        if (!pid)
diff --git a/fs/locks.c b/fs/locks.c
index db7b6917d9c5..dd5f012887ca 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -546,7 +546,7 @@ lease_setup(struct file_lock *fl, void **priv)
        if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa))
                *priv = NULL;
 
-       __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
+       __f_setown(filp, task_tgid(current), PIDTYPE_TGID, 0);
 }
 
 static const struct lock_manager_operations lease_manager_ops = {
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index e2bea2ac5dfb..47b650b81b07 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -19,6 +19,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/sched/signal.h>
 #include <linux/dnotify.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
@@ -353,7 +354,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned 
long arg)
                goto out;
        }
 
-       __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
+       __f_setown(filp, task_tgid(current), PIDTYPE_TGID, 0);
 
        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 */
-- 
2.17.1

Reply via email to