From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452551; b=r5xR9J8Hzc93O5ZkAN/xrBfZu0MSs9JgpsvzuCgFpS93tl5RvKUIngHuSB0Urw8L90fw uJ6hfKqr8tklerGN3gObemItyU+x8WD/zEBwhhq7US3tJh9JUn94PxSa10mAHBF6MYzkE qtdjD1kHLfc+JoaUlwYghZH5/p/ZZ8fMGvKGYJ3nF6KX/yg7qp4khMBXPCeqHYujTNXDH VCtxY07fgS7YsVIgPOOyKUYR9Luuy/r+/KjLkhNAbOrdCYdp8qbMdOZAVgLeBGG/g6c7w 60h7qxZ6VpOWUWPS0WvmQmn+h52IKrQDnOPpzwa2VvM9BeEhbcZduXOnR9D2+kAU4+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452551; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=ZPqLyOyf6IybguwqJzHSMxQRQxNgkrcKM+chLv7PnFU=; b=i3xKSPLA1N0DVJfSloMn+ALLfN06tmdLC0tW7veCgXVq15cOWkVn4o9i5M6rlCIsLSB/ suubn4l3B0vXvI2BkyaPJqozc3Lgli74A9p8huHErn/wRXjgTJKG0xJ0r+3UjxgQi0WId emx0Ja/NR5IqPBbavjpplf7V9zcwIh8XUGTByZaTbJCj7ErROoLrRFmJayQ2I6SDl7lsk 3C36fh12aqdFDBKzM/JPyDA+4qdsFBYpnLE4a/l5UcbCwHLYwFQpZESxRnpXn4nmby/qj OLWR4z2qEhauR+GyTrE0hDBNUme1Z+PbcMzIybx9ScMS/sRqwc8ojGLr9wOsWbuc4Tg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XwHb8qvt; arc=none smtp.remote-ip=74.125.82.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34B96606A693 for ; Sat, 5 Dec 2026 06:35:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34B96606A693 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XwHb8qvt Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-3869f03af6aso2089676eec.1 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.linux.dev; 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=XwHb8qvtFhhb9/Mc2zBngRHTG5QJ2HfNLpxYR/BpR/KgBwj+SwIXvO6AZainZ0OInO lx7xXC972BlIUzW4X8JvGFiLCO7LVWTvTx//5NB1G0cj8SgvsuO+UD6n/JXAtlAkXTSf WlWIlQdEjuN5xub+aB/d6nCn5EPp5BH0t7LutSh6pgVAxB7ruq3lEwvtle8A4DQIZyL3 Rd5fJHiLcSQsJmI0uVx7EDoxFWTsUAbs0fwKLfgFc7fCO37L9vk83y2ibo1J+p378b2D Cf514emtzAeMzQZGfNXtfMT0jJaaDY64dAmMKtrqArgwcgEYUJPQagXW7Q60jAw+WlBn H+/Q== 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+chLv7PnFU=; b=no5NPohxssDv1nEAymBJVHEdOxp5CzSrU9PbfQoM2jQEz6EYH5FolGa1xYmhdCr4KT dV86Ze4KYdPnEbykibNBgGYqyhVHy/tn7DdU5SfroIN10ZsdcvjEBeTcmhOx5l4qrFs2 rN7H32EDfFx4c81X5jD2Yc7unbE+iWTqPVzDHoeJBPtXmER0bLS3DZ4CvNH7YbljfdEG rQZLN0ecKmqFxa7/fivBdK+OmC5VH1buGJpiafTS8lbBo1J6DAIknP5mA5sJRD5Khh0E 5ubi5KQmqwdNPPWKQ/w+FlEhubhFJPCwdO6St5WdZpD7ComwhFTT2C62zkJAcS24ZB7G qKMQ== X-Forwarded-Encrypted: i=1; AL+hErHEMEgKYsLlUajhX6dM0/Ps8+3IA/ukUDIaP7gGxeNgqAaKWQla5VjUm4/H5jFybHlxCRQ=@lists.linux.dev X-Gm-Message-State: AB4q+uEC9n8uqitisbH9cqgUmHtkl1SYNsr2KC8Ei1tnoRmgBpOXjFCn rA1+ygcSxLJVqViu4KcugMC+Pu12oWY6FLJCgSN0KoyPNu3dN8T8VUoC X-Gm-Gg: AZFdTZfr6KrLbNYieWYdwRS7GElRWCSMTAn2jESasiuCm5JcphW0cR0TrFkndDo57UT haGk+JQGNWBQJJDPHn1e/nhHABIRZEZIFui+VAF/xr5Mc83Plwu3Yiz317tUlSGmPdibBzYJYiV 1JN0eHMG5hNd+yaz5ljP7qZSXRyfXwyW5hchmyVYMVgjWZO3WUhKZ/Jem95JUB2d/jKZg6jvVzf cp1W/C7ghT9FVg58NIl3K+qwNHcBodwEjBqfX+4OfZKlc9uE/3g0IqqYZE8LAWdQkP1r+fOmipi gZQJYn3JKaln1FZtIQqMNdlt6iRlvaFOm6r+HAwgj7GXbJnzpbOrfO7uIMiis6vawEdysWZAJjx T8VRb0x+OcV7evZA2uXdNFMV4h6Q1T1/pDa7BDnn8venjtzjOhMyq61DE05M7u0G4s3ZnYdoSJR hQUPiWK/FPX1niGpMW1AWxqcSH6vJIzC5O6YwBlyTwAlz+5ULMhlpchBjHmsw/LVhSwtx8cqxtb fWf1bfQPY6lus8kcdC36mb9VonXLaQ/OhGl1zQvRF5kLtUIWSLqevkIl9iXurLljpktGC97sZEX 9tFOCtf0vbbfTvsL4dycX/DQ0Dpek6aeutKORfItYmgn3/bP2KieE/2GQu4BnFBT1GU= 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-Mailing-List: imx@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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