From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49752606A32F for ; Sat, 5 Dec 2026 06:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=OibgFhl7; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=YqBlmiXj DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=ZPqLyOyf6IybguwqJzHSMxQRQxNgkrcKM+chLv7PnFU=; b=OibgFhl75oPvHK o+i4gDGZCSlueH5QxjVtvLJ0S/Nd+uej+F0TUiuEzMroH77dvgaY2kCsiqlyM9M5Khe18PZYTHuXH 7Ix47rFhdsHxUli2Heqrx9yvPSmtmaZ5NjzCau+dyXXVKotRr0xuCvO3Daus2QZdBX5fFeO5iKS5l dfgRWsEmPcaLJgzGKIUMnRB1zJzpgILwO+oX6TcYiSoiYS8784O5GHrpa4cjJ+F/GDsRrTjbMCYnh bCv9x7ilL3kQSqkYHeQQgdOzImwrrF6Dz9xMwtTvk3HwFS5TVMfAGN/QW7otARIMEfvG5Z45Jv0SK DRMLH6kyVZPdqoIUqfRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZjND-000000024Ae-20NE; Sat, 05 Dec 2026 06:35:55 +0000 Received: from mail-dl1-x1233.google.com ([2607:f8b0:4864:20::1233]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZjN9-0000000248l-1Qud for linux-arm-kernel@lists.infradead.org; Sat, 05 Dec 2026 06:35:52 +0000 Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-18818daa3e7so1943383c88.0 for ; Fri, 04 Dec 2026 22:35:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452550; x=1797057350; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZPqLyOyf6IybguwqJzHSMxQRQxNgkrcKM+chLv7PnFU=; b=YqBlmiXjGbp2je6+qeflIJKRH7e6QeWqTPZY+EVcV0/v9RqBQws6hffw9sgNMHNDLp oKyoU7U0NruX9nxu9rv5Mgd/g/O5n6YhvRuIIxzZMC4FEHTXHydUqQhpUOujzMFEa0FW mp+cZx6/3tCkn0gAYpQccpoNRy0q2Yaa9KWpvmAcM3FvkhUtJdIvcXtabKq31oGt29UM 3CcogOrD4gr4lWRHrzvtP6Uy+0Q33AHMTtj93ZYTsVVkwubCiL6Uyjd8g6zed0/SQXn2 IfrHaS66NAxOFNAWYGMRhaRYJhN1/1eEgaKdJmSJB3cUsOhxeR0bWEqyF5fYshKIC3Fv fpiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452550; x=1797057350; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZPqLyOyf6IybguwqJzHSMxQRQxNgkrcKM+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ixKmmKMMWWT1tdzxQOZSzUYncgnGYXgGJalJ+WcQUwmLMFnsIp07b70sls MVNZVqufn0urzp4OoFjQyB/lQl+TfhpvPatEedYAnxF+xSFy4LyxF6mQUj8fd+n7INVd5nqMpFg xesc07y7/grV+bowLqLZmeFHgOCpMSYEn2V1vL6ggRhndmn24Sp3YSry6slb4blXmTU= X-Received: by 2002:a05:7301:4d02:b0:36c:a3ae:936e with SMTP id 5a478bee46e88-38742cf7cfdmr6769679eec.5.1796452550298; Fri, 04 Dec 2026 22:35:50 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875218c602sm20884183eec.7.2026.12.04.22.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:35:49 -0800 (PST) From: Praneeth Balasubramanian To: Jiri Slaby , Greg Kroah-Hartman , Frank Li , Sascha Hauer Cc: Praneeth Balasubramanian , Pengutronix Kernel Team , Fabio Estevam , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Date: Fri, 4 Dec 2026 22:35:36 -0800 Message-Id: <20261205063536.2519566-5-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261205063536.2519566-1-praneethb2002@gmail.com> References: <20261205063536.2519566-1-praneethb2002@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_223551_383369_AFE8E53C X-CRM114-Status: GOOD ( 12.85 ) X-Spam-Score: -1.8 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 mxser_set_serial_info() updates the termios without holding tty->termios_rwsem. It calls tty_encode_baud_rate() which writes c_ispeed and c_ospeed and rewrites the CBAUD bits of c_cflag. It also reads the termios in mxser_change_speed() and mxser_activate(). A concurrent TCSETS or TCSETS2 on the same tty stores the whole termios under termios_rwsem in tty_set_termios(). The TIOCSSERIAL path takes no termios_rwsem. The two writers can interleave. The whole-struct store can land between the speed stores and leave c_cflag, c_ispeed and c_ospeed disagreeing with each other. Take termios_rwsem for write at the top of mxser_set_serial_info(). Take it before port->mutex. serial_core takes termios_rwsem before port->mutex in uart_set_info_user() and both lock classes are global. The same order here avoids a lockdep inversion. Nothing inside the critical section takes termios_rwsem itself. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I do not have this hardware. drivers/tty/mxser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 281c599a12f2..a761dd9f3c71 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -982,6 +982,7 @@ static int mxser_set_serial_info(struct tty_struct *tty, if (tty_io_error(tty)) return -EIO; + guard(rwsem_write)(&tty->termios_rwsem); guard(mutex)(&port->mutex); if (ss->irq != info->board->irq || ss->port != info->ioaddr) -- 2.25.1