Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752653AbbF1PXS (ORCPT ); Sun, 28 Jun 2015 11:23:18 -0400 Received: from mail-qg0-f43.google.com ([209.85.192.43]:35743 "EHLO mail-qg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbbF1PXK (ORCPT ); Sun, 28 Jun 2015 11:23:10 -0400 Message-ID: <5590115A.3000201@hurleysoftware.com> Date: Sun, 28 Jun 2015 11:23:06 -0400 From: Peter Hurley User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Patrick Donnelly CC: Greg Kroah-Hartman , Jiri Slaby , open list Subject: Re: [PATCH v2 1/2] tty: add missing rcu_read_lock for task_pgrp References: <1435439824-3975-1-git-send-email-batrick@batbytes.com> <1435452689-25390-1-git-send-email-batrick@batbytes.com> In-Reply-To: <1435452689-25390-1-git-send-email-batrick@batbytes.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2078 Lines: 72 On 06/27/2015 08:51 PM, Patrick Donnelly wrote: > 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. kill_pgrp() obtains tasklist_lock, so I don't see an unsafe deref. > Signed-off-by: Patrick Donnelly > --- > 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; > } > > -- 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/