From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 302BB20EB; Mon, 14 Oct 2024 14:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728916869; cv=none; b=WWS3YMipFxlYDm+Usmrlyt1h4Qop+Rw8CHHMO9Q8tG+3rOKeVvKFlZAfTU7MXaA2p30Sp2RP7EqrI7vPRwHEGB3psk3D88Ak5V7/8CTjNFe4VfXMxB4lssYoOvEPgQ01dfLZNIOD4I7wVvvAvR2Z7n3l4uCSEEm4QnU4jIXcyTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728916869; c=relaxed/simple; bh=n1pkWZfK0Ofiee/0eiZmY28apug4tG4eRloKjHgjRgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIR+8g7Cp70G2CyjogJe/skXJHDlnmRzvAOID0FXnesoIxfG9Z2N0ajw6/Pdl0D+R41CHJfTZ5M1jSU+vR8AOvZGc/uJP4GDicBeawGyZwIy7SOV3yPUiN9lgXzYw0OjV2mPNUzfLBoRCbn8GVjtt++G2NJGIlwnOP0Xzjk0E78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=u3BGtPA4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="u3BGtPA4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93993C4CEC7; Mon, 14 Oct 2024 14:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728916869; bh=n1pkWZfK0Ofiee/0eiZmY28apug4tG4eRloKjHgjRgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3BGtPA4YhkRQGjcr3/aDRAznZhSA8W0K9E0sWC7cZN/X//l5qNC59Tk5kzgkEYMt RPE13XMvY6WMC4nCKP1ubIT2ORY22naa/Uwyq9rMnkn3fEhIUMqf8T6GxXO+ZUUX5o untNZ+1mP0dGa/qhjH9kyi6n69KdF+HVfKS52eP4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Jiri Slaby (SUSE)" , Peter Hurley , Sasha Levin Subject: [PATCH 6.6 088/213] serial: protect uart_port_dtr_rts() in uart_shutdown() too Date: Mon, 14 Oct 2024 16:19:54 +0200 Message-ID: <20241014141046.409041137@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141042.954319779@linuxfoundation.org> References: <20241014141042.954319779@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Slaby (SUSE) [ Upstream commit 602babaa84d627923713acaf5f7e9a4369e77473 ] 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) Cc: Peter Hurley Cc: Greg Kroah-Hartman Link: https://lore.kernel.org/r/20240805102046.307511-3-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 5d5570bebfeb6..8ff0efac6aa0d 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -374,14 +374,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.43.0