From: Earl Chew <earl.chew@yahoo.ca>
To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
jirislaby@kernel.org
Cc: peter@hurleysoftware.com, earl.chew@yahoo.ca
Subject: [PATCH 3/3] tty: Move task_pgrp() after tty->ctrl.lock for consistency
Date: Thu, 31 Aug 2023 18:50:31 -0700 [thread overview]
Message-ID: <20230901015030.2469062-4-earl.chew@yahoo.ca> (raw)
In-Reply-To: <20230831143645.2298799-1-earl_chew@yahoo.com>
Refactor __tty_check_change_locked() for consistency
with __proc_set_tty() which calls task_pgrp() after
tty->ctrl.lock is acquired.
In addition, spin_lock_irqsave() can block, while
task_pgrp() cannot block. Fetching the process
group immediately before it is used reduces the
window for inconsistency, and improves clarity.
Signed-off-by: Earl Chew <earl.chew@yahoo.ca>
---
drivers/tty/tty_jobctrl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index 462fdf7b2..b4d37cad9 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -43,13 +43,13 @@ static int __tty_check_change_locked(struct tty_struct *tty, int sig,
if (current->signal->tty != tty)
return 0;
- rcu_read_lock();
- pgrp = task_pgrp(current);
-
if (!ctrl_lock)
spin_lock_irqsave(&tty->ctrl.lock, flags);
tty_pgrp = tty->ctrl.pgrp;
+ rcu_read_lock();
+ pgrp = task_pgrp(current);
+
if (tty_pgrp && pgrp != tty_pgrp) {
if (is_ignored(sig)) {
if (sig == SIGTTIN)
@@ -62,9 +62,9 @@ static int __tty_check_change_locked(struct tty_struct *tty, int sig,
ret = -ERESTARTSYS;
}
}
+ rcu_read_unlock();
if (!ctrl_lock)
spin_unlock_irqrestore(&tty->ctrl.lock, flags);
- rcu_read_unlock();
if (!tty_pgrp)
tty_warn(tty, "sig=%d, tty->pgrp == NULL!\n", sig);
--
2.39.1
prev parent reply other threads:[~2023-09-01 1:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230831143645.2298799-1-earl_chew@yahoo.com>
2023-09-01 1:50 ` [PATCH 0/3] tty: Fix tiocspgrp() related races Earl Chew
2023-09-28 13:06 ` [PATCH v2 " Earl Chew
2023-09-28 13:38 ` Greg KH
2023-09-28 13:06 ` [PATCH v2 1/3] tty: Fix __tty_check_change() and tiocspgrp() race Earl Chew
2023-09-28 13:06 ` [PATCH v2 2/3] tty: Serialise racing tiocspgrp() callers Earl Chew
2023-09-29 6:07 ` kernel test robot
2023-09-28 13:06 ` [PATCH v2 3/3] tty: Move task_pgrp() after tty->ctrl.lock for consistency Earl Chew
2023-09-01 1:50 ` [PATCH 1/3] tty: Fix __tty_check_change() and tiocspgrp() race Earl Chew
2023-09-01 1:50 ` [PATCH 2/3] tty: Serialise racing tiocspgrp() callers Earl Chew
2023-09-01 16:09 ` kernel test robot
2023-09-01 17:14 ` kernel test robot
2023-09-28 21:00 ` kernel test robot
2023-09-01 1:50 ` Earl Chew [this message]
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=20230901015030.2469062-4-earl.chew@yahoo.ca \
--to=earl.chew@yahoo.ca \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@hurleysoftware.com \
/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
all inboxes | Powered by JetHome®