public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>,
	Peter Hurley <peter@hurleysoftware.com>
Subject: [PATCH 02/13] serial: protect uart_port_dtr_rts() in uart_shutdown() too
Date: Mon,  5 Aug 2024 12:20:35 +0200	[thread overview]
Message-ID: <20240805102046.307511-3-jirislaby@kernel.org> (raw)
In-Reply-To: <20240805102046.307511-1-jirislaby@kernel.org>

Commit af224ca2df29 (serial: core: Prevent unsafe uart port access, part
3) added few uport == NULL checks. It added one to uart_shutdown(), so
the commit assumes, uport can be NULL in there. But right after that
protection, there is an unprotected "uart_port_dtr_rts(uport, false);"
call. That is invoked only if HUPCL is set, so I assume that is the
reason why we do not see lots of these reports.

Or it cannot be NULL at this point at all for some reason :P.

Until the above is investigated, stay on the safe side and move this
dereference to the if too.

I got this inconsistency from Coverity under CID 1585130. Thanks.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/tty/serial/serial_core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 61c7e1268957..3afe77f05abf 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -407,14 +407,16 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
 		/*
 		 * Turn off DTR and RTS early.
 		 */
-		if (uport && uart_console(uport) && tty) {
-			uport->cons->cflag = tty->termios.c_cflag;
-			uport->cons->ispeed = tty->termios.c_ispeed;
-			uport->cons->ospeed = tty->termios.c_ospeed;
-		}
+		if (uport) {
+			if (uart_console(uport) && tty) {
+				uport->cons->cflag = tty->termios.c_cflag;
+				uport->cons->ispeed = tty->termios.c_ispeed;
+				uport->cons->ospeed = tty->termios.c_ospeed;
+			}
 
-		if (!tty || C_HUPCL(tty))
-			uart_port_dtr_rts(uport, false);
+			if (!tty || C_HUPCL(tty))
+				uart_port_dtr_rts(uport, false);
+		}
 
 		uart_port_shutdown(port);
 	}
-- 
2.46.0


  parent reply	other threads:[~2024-08-05 10:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-05 10:20 [PATCH 00/13] tty: random fixes and cleanups Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 01/13] tty: simplify tty_dev_name_to_number() using guard(mutex) Jiri Slaby (SUSE)
2024-08-05 14:25   ` Ilpo Järvinen
2024-08-05 10:20 ` Jiri Slaby (SUSE) [this message]
2024-08-05 10:20 ` [PATCH 03/13] serial: don't use uninitialized value in uart_poll_init() Jiri Slaby (SUSE)
2024-08-05 14:28   ` Ilpo Järvinen
2024-08-05 15:46     ` Doug Anderson
2024-08-08  7:34       ` Jiri Slaby
2024-08-08  7:44         ` Greg Kroah-Hartman
2024-08-08  9:15         ` Ilpo Järvinen
2024-08-05 15:43   ` Doug Anderson
2024-08-05 10:20 ` [PATCH 04/13] serial: remove quot_frac from serial8250_do_set_divisor() Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 05/13] serial: use guards for simple mutex locks Jiri Slaby (SUSE)
2024-08-05 17:57   ` kernel test robot
2024-08-05 18:09   ` kernel test robot
2024-08-07 11:15   ` Greg KH
2024-08-05 10:20 ` [PATCH 06/13] mxser: remove stale comment Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 07/13] mxser: remove doubled sets of close times Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 08/13] mctp: serial: propagage new tty types Jiri Slaby (SUSE)
2024-08-06  4:51   ` Jeremy Kerr
2024-08-08 10:35     ` Jiri Slaby
2024-08-05 10:20 ` [PATCH 09/13] 6pack: remove sixpack::rbuff Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 10/13] 6pack: drop sixpack::mtu Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 11/13] 6pack: drop sixpack::buffsize Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 12/13] 6pack: remove global strings Jiri Slaby (SUSE)
2024-08-05 10:20 ` [PATCH 13/13] 6pack: propagage new tty types Jiri Slaby (SUSE)
2024-08-07 11:14 ` [PATCH 00/13] tty: random fixes and cleanups Greg KH

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=20240805102046.307511-3-jirislaby@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@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