From: Patrick Donnelly <batrick@batbytes.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.cz>,
linux-kernel@vger.kernel.org (open list)
Cc: Patrick Donnelly <batrick@batbytes.com>
Subject: [PATCH v4] tty: add missing rcu_read_lock for task_pgrp
Date: Sun, 12 Jul 2015 18:51:52 -0400 [thread overview]
Message-ID: <1436741512-992-1-git-send-email-batrick@batbytes.com> (raw)
In-Reply-To: <1435439824-3975-1-git-send-email-batrick@batbytes.com>
task_pgrp requires an rcu or tasklist lock to be obtained if the returned pid
is to be dereferenced, which kill_pgrp does. Obtain an RCU lock for the
duration of use.
Signed-off-by: Patrick Donnelly <batrick@batbytes.com>
---
drivers/tty/n_tty.c | 15 ++++++++++++---
drivers/tty/tty_io.c | 17 ++++++++++++-----
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index c9c27f6..de67b2c 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2137,6 +2137,8 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *,
static int job_control(struct tty_struct *tty, struct file *file)
{
+ struct pid *pgrp;
+
/* Job control check -- must be done at start and after
every sleep (POSIX.1 7.1.1.4). */
/* NOTE: not yet done after every sleep pending a thorough
@@ -2146,18 +2148,25 @@ static int job_control(struct tty_struct *tty, struct file *file)
current->signal->tty != tty)
return 0;
+ rcu_read_lock();
+ pgrp = task_pgrp(current);
+
spin_lock_irq(&tty->ctrl_lock);
if (!tty->pgrp)
printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
- else if (task_pgrp(current) != tty->pgrp) {
+ else if (pgrp != tty->pgrp) {
spin_unlock_irq(&tty->ctrl_lock);
- if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned())
+ if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned()) {
+ rcu_read_unlock();
return -EIO;
- kill_pgrp(task_pgrp(current), SIGTTIN, 1);
+ }
+ kill_pgrp(pgrp, SIGTTIN, 1);
+ rcu_read_unlock();
set_thread_flag(TIF_SIGPENDING);
return -ERESTARTSYS;
}
spin_unlock_irq(&tty->ctrl_lock);
+ rcu_read_unlock();
return 0;
}
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 57fc6ee..6bdfb98 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -388,33 +388,40 @@ EXPORT_SYMBOL_GPL(tty_find_polling_driver);
int tty_check_change(struct tty_struct *tty)
{
unsigned long flags;
+ struct pid *pgrp;
int ret = 0;
if (current->signal->tty != tty)
return 0;
+ rcu_read_lock();
+ pgrp = task_pgrp(current);
+
spin_lock_irqsave(&tty->ctrl_lock, flags);
if (!tty->pgrp) {
printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");
goto out_unlock;
}
- if (task_pgrp(current) == tty->pgrp)
+ if (pgrp == tty->pgrp)
goto out_unlock;
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+
if (is_ignored(SIGTTOU))
- goto out;
+ goto out_rcuunlock;
if (is_current_pgrp_orphaned()) {
ret = -EIO;
- goto out;
+ goto out_rcuunlock;
}
- kill_pgrp(task_pgrp(current), SIGTTOU, 1);
+ kill_pgrp(pgrp, SIGTTOU, 1);
+ rcu_read_unlock();
set_thread_flag(TIF_SIGPENDING);
ret = -ERESTARTSYS;
-out:
return ret;
out_unlock:
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+out_rcuunlock:
+ rcu_read_unlock();
return ret;
}
--
Patrick Donnelly
next prev parent reply other threads:[~2015-07-12 22:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-27 21:17 [PATCH 1/2] Add missing rcu_read_lock for task_pgrp Patrick Donnelly
2015-06-27 21:17 ` [PATCH 2/2] Check tcsetpgrp p is a process group Patrick Donnelly
2015-06-27 23:26 ` Greg Kroah-Hartman
2015-06-28 0:53 ` Patrick Donnelly
2015-06-27 23:27 ` Greg Kroah-Hartman
2015-06-27 23:25 ` [PATCH 1/2] Add missing rcu_read_lock for task_pgrp Greg Kroah-Hartman
2015-06-28 0:51 ` [PATCH v2 1/2] tty: add " Patrick Donnelly
2015-06-28 0:51 ` [PATCH v2 2/2] tty: check tcsetpgrp p is a process group Patrick Donnelly
2015-06-28 16:07 ` Peter Hurley
2015-06-29 1:27 ` Patrick Donnelly
2015-06-28 15:23 ` [PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp Peter Hurley
2015-06-28 17:20 ` Patrick Donnelly
2015-06-28 19:21 ` Peter Hurley
2015-06-28 19:27 ` Peter Hurley
2015-06-29 23:38 ` Patrick Donnelly
2015-06-29 23:59 ` [PATCH v3] " Patrick Donnelly
2015-07-09 2:07 ` Peter Hurley
2015-07-12 2:05 ` Peter Hurley
2015-07-12 22:42 ` Patrick Donnelly
2015-07-12 22:51 ` Patrick Donnelly [this message]
2015-07-13 0:35 ` [PATCH v4] " Peter Hurley
2015-07-20 9:26 ` Jiri Slaby
2015-07-20 19:40 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436741512-992-1-git-send-email-batrick@batbytes.com \
--to=batrick@batbytes.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).