From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452551; b=N6ZsxvQLYzCSeNG1kDm/zNqSyp8C2WtZ41tWh1bMukSb/SchWwdMuAH5sUpXAVoIrzOy coAVHBqE0HUhPytVEuBSsf+g/8AeJMQjDv0s5ikQadfAiJRDeTpPz9saEWVzxowsAjnmJ 2nw7u1FwA3F8nugHkN8Rz7WacW9a/YShZP68DC9cYRyM8u5J+o1LJbBtOVDrIkNkKlnzQ dD0UFGyHnFjNVN7zCArFNlCr128h887U1K5j3NdMj+KPgbfoI3aGn4mtikDKkRK5V2tek Xhj2C5Sdv0uuIWy3/eb07K9OZDw6YG6KLRjZByjQv/ZfeFHXW8Kud+gMaKdxjCdp3DQ== 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=n2A1ph9Y33IU/qlQFMF5w8vbzTAqsww1LlUQAcgvpZWwKM12JUHRCBjNmA9ymI3ClSrR fVxzy3HcGMSy5coc68Q1Aawybb5/1wMG1VTMD46y5aB2yF6Vl44cRBdgiTVf43kHbEPVi Ushv+zcydbxBN3uqnqXW0WaPt2zUsWrhtj7P2BgAWQIqnmhVEVT0OtHXIJdXUX249pNaW v0cKztuhGRbE8L+Gx56qi2EUERsEFaaduKcpKiVFcsuWvu8MYH5xd+CI/ua9mE15x0I2y tPImxbrVIv6Xoj95WIKrxkYhHnK+Pw1zPEUlfl8vcs5NBaFoH1srH/K6axBE6oinEvA== 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=rMzPz4pQ; arc=none smtp.remote-ip=74.125.82.177 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 398B9606A322 for ; Sat, 5 Dec 2026 06:35:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 398B9606A322 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=rMzPz4pQ Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-387609bc451so544392eec.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=vger.kernel.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=rMzPz4pQ19tN1kvlAZJUCLxmnihi6upilCH9C2c2MNjz8hOFyx4q7KSioJw0TRQiu6 KF93STG8wM2uxsy+p0VQ2sxeeBfgRmQWzdxGLAXaNl31QQ/S0zakb87Tmy+pq4WPSuu6 3Sxv8XSlTnwjwozVYnUhEasL5/O6fws5UgcdORTMHQLyKl/JN6Ap96aTeLsvjCfTDQp6 gAVO9hQW1nYQuO7rtGsLE8pJl3dpOviLr+9lH8jmyADnrMZQFz/F72/bcY6vGYq9nMWA y3qvugaVSse7QOSowxtQgrFlE3I1+6ScXCvjV/ofwEpgzAlIID0E+iCrs/SbMU/clJYp PP9g== 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=p69Q2Mkxh+U0Qwy+XsNk5LIlkcZpIAPZgaSiEmngX94q/d/lCMnWDBKvVWp4vyxGFu 1kAChsdnywoy3NZ95k5rcwbD1yHka5/21O9s+3drx0NuI6fDIHO2IbxcgazHczoXBKkI VKiM8GCgngUGYze8Z2o/yJIr8l0YP55TBxb37pP40vM2psOu7NP0hrdq02IGjNVd6gSu qLpbhGQ/ge37/z/s1FLM7u9kpRprR2DKY5jQDyLtWZ48AjkojovVmPbtIWUsG3EsHpuB 4FP1NQfgQpFUyRy8GHu6aiYmhSw+ycWUOEDkX+3kjVP3XV5Cv4cju/hfnVcpiC7HXOLm Apkw== X-Forwarded-Encrypted: i=1; AL+hErHLG52Oh/0D3Gov82ZJVmkY0jveozEZ7Akqvokt9oNxapLU/Bhl09hx3k8qIlAc5qvqYyB874oDcWSW7ck=@vger.kernel.org X-Gm-Message-State: AB4q+uGbeW0WFxnLLGQy1vkd9vf6KJU6JV4RIJdt0lmtcQkfkSfgYF3P 5dXyuGX7SweFeUEf/e6AY8sDipPQx7Dl5Cw86YzjwZQu5TLh4kfS4FlK X-Gm-Gg: AZFdTZepYzyJhB9dsNuq4WwvEuY1eapEkKyDo0ni5YSDwmxtg7JdRIsXU+yajMbZ6wD cV5+BnP+h4SLqKMEqU5EVXwjYkJPUgdgpvb2M3m8wXkHOXhfzfjw7NuBQd2cc+WPlWwx9Zpi7Uu ozJSNDTfb6O2vfvfkDLUwKOOoqo8zx/gyW24koH30vN1n4XeS1fDSckb5G7tsWbgQgDdLEPqXxr eaKNvHTYNOWF0uEGnf0wyTdhP17sICWJthsa4mW02tEhJF0+MxMhyySlaV3qcOpiXMAe2oaYiq5 Ld8j26xoq+99Ss72Xzgl4JSZfgn3qLxUrtm7QmRjD9XzlcjqM9TkKpsG2TzStdw4XGeLGRVHSyj iFLiYfxLM+NuTPWfmqv8eY1aIPyPNO691J6aN+PqDdUDOyvLs3Fh1b535z5FoB73Dka3Hc+B+pP IuaMWx5UR5NURRaduu4zwW6VU1OGEy9YVovj89ZvDdnN6h3ivjn9VT432rfPIAH0TtGiu+EVPG3 IazyXS4CRF6rDx3J3axKahfI5KE+zt1dWbuQoF6lULDYI9A6Qd37kgOsd63khsWDV+CuyPSrOg8 M+bFD4RR2Q1TByMMw56FfAIYDrKysznJFRz/gzn4WmmXutGTKOKDhfUsxldHeq/7sFs= 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: linux-kernel@vger.kernel.org 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