Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1173438 > unrolled thread

[PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp

Started byPatrick Donnelly <batrick@batbytes.com>
First post2015-06-28 03:00 +0200
Last post2015-06-30 01:40 +0200
Articles 4 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp Patrick Donnelly <batrick@batbytes.com> - 2015-06-28 03:00 +0200
    [PATCH v2 2/2] tty: check tcsetpgrp p is a process group Patrick Donnelly <batrick@batbytes.com> - 2015-06-28 03:00 +0200
      Re: [PATCH v2 2/2] tty: check tcsetpgrp p is a process group Patrick Donnelly <batrick@batbytes.com> - 2015-06-29 03:30 +0200
    Re: [PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp Patrick Donnelly <batrick@batbytes.com> - 2015-06-30 01:40 +0200

#1173438 — [PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp

FromPatrick Donnelly <batrick@batbytes.com>
Date2015-06-28 03:00 +0200
Subject[PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp
Message-ID<pG96V-5r8-11@gated-at.bofh.it>
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/tty_io.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 57fc6ee..fbb55db 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -388,33 +388,39 @@ 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;
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
+	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;
+		goto out_irqunlock;
 	}
-	if (task_pgrp(current) == tty->pgrp)
-		goto out_unlock;
+	if (pgrp == tty->pgrp)
+		goto out_irqunlock;
 	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:
+out_irqunlock:
 	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+out_rcuunlock:
+	rcu_read_unlock();
 	return ret;
 }
 
-- 
Patrick Donnelly

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1173439 — [PATCH v2 2/2] tty: check tcsetpgrp p is a process group

FromPatrick Donnelly <batrick@batbytes.com>
Date2015-06-28 03:00 +0200
Subject[PATCH v2 2/2] tty: check tcsetpgrp p is a process group
Message-ID<pG96V-5r8-13@gated-at.bofh.it>
In reply to#1173438
This fixes a bug where a process can set the foreground process group to its
pid even if its pid is not a valid pgrp.

Signed-off-by: Patrick Donnelly <batrick@batbytes.com>
---
 drivers/tty/tty_io.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index fbb55db..01b4769 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2579,6 +2579,9 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
 	retval = -ESRCH;
 	if (!pgrp)
 		goto out_unlock;
+	retval = -EINVAL;
+	if (!pid_task(pgrp, PIDTYPE_PGID))
+		goto out_unlock;
 	retval = -EPERM;
 	if (session_of_pgrp(pgrp) != task_session(current))
 		goto out_unlock;
-- 
Patrick Donnelly

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1173602 — Re: [PATCH v2 2/2] tty: check tcsetpgrp p is a process group

FromPatrick Donnelly <batrick@batbytes.com>
Date2015-06-29 03:30 +0200
SubjectRe: [PATCH v2 2/2] tty: check tcsetpgrp p is a process group
Message-ID<pGw3v-4UX-7@gated-at.bofh.it>
In reply to#1173439
On Sun, Jun 28, 2015 at 12:07 PM, Peter Hurley <peter@hurleysoftware.com> wrote:
> On 06/27/2015 08:51 PM, Patrick Donnelly wrote:
>> This fixes a bug where a process can set the foreground process group to its
>> pid even if its pid is not a valid pgrp.
>>
>> Signed-off-by: Patrick Donnelly <batrick@batbytes.com>
>> ---
>>  drivers/tty/tty_io.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
>> index fbb55db..01b4769 100644
>> --- a/drivers/tty/tty_io.c
>> +++ b/drivers/tty/tty_io.c
>> @@ -2579,6 +2579,9 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
>>       retval = -ESRCH;
>>       if (!pgrp)
>>               goto out_unlock;
>> +     retval = -EINVAL;
>> +     if (!pid_task(pgrp, PIDTYPE_PGID))
>> +             goto out_unlock;
>
> This change implies that the sequence in session_of_pgrp() that specifically
> checks for pid_task(pgrp, PIDTYPE_PGID) == NULL is not doing anything
> useful. However, that hypothesis is directly contradicted by the
> comment above session_of_pgrp()
>
> "* This checks not only the pgrp, but falls back on the pid if no
>  * satisfactory pgrp is found. I dunno - gdb doesn't work correctly
>  * without this..."
>
> Regards,
> Peter Hurley
>
>>       retval = -EPERM;
>>       if (session_of_pgrp(pgrp) != task_session(current))
>>               goto out_unlock;
>>

Ah, missed that. Good catch! I guess this patch is no good since it
was already accounted for and it breaks gdb.

-- 
Patrick Donnelly
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1174144

FromPatrick Donnelly <batrick@batbytes.com>
Date2015-06-30 01:40 +0200
Message-ID<pGQOD-1cM-31@gated-at.bofh.it>
In reply to#1173438
Hi Peter,

On Sun, Jun 28, 2015 at 3:27 PM, Peter Hurley <peter@hurleysoftware.com> wrote:
> The label name changing is not really necessary and would reduce diff count.

I've removed the label changes in the next series. Thanks for the feedback.

> It would be nice to get the printk() out from the locks as well (in a follow-on
> patch?)

I don't follow what you're referring to. Is it these lines?

    if (!tty->pgrp) {
        printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");

-- 
Patrick Donnelly
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web