From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452551; b=Fog9g3IAwifWXQ1MaG8rj+J7aswgBhh5gDqPBC6lv9d6/dCvRgt2A3WMB4ixFMYf0xMO Gew4a42CH+SDxojkjeDuNXGwWl3IQST0TbsgChktB84xZ0ynWtFghu+0/Vuowh261Nx1A zX12QqnU9LDCERLNt4TRqnVNf4kXQzlL0xijzBO0cKt+5JQfOCCwHFYyVzgfzBo4VRWmd fKvh5Clb2ODFtbtfjEqIOWPiQjLVnyekbPUquieafniwDPmTaIHZ1PLVBIDvB6L95IXir +u5kicjhEq1t+xRJ4l3ncUlFGy+DR70MjEAvOCBkWukxElpKR4YQipT+FrnMJHlxwQQ== 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=o/D5AbEADHQV1NxwEPI04dEl2kWbDeylVUfm/83srPx9yOpeFnTgMwBW3WxyGCgMUoFG mdufwaD0WTvSJHEtc3o7PBXlTu54ThvKsfZC1ulQG22c28+Dh9XroDwYMrMXEfjJTghHA EYW/Mztko2g9VTMWPg4qBPOuZh5hvrGBm4GYC93Jvms9bQN0hZLiy2hNm7wECkhtGdUur WuUL1/8LgZP//nsFkMSBZfOpT3DX5Aj4Pu5PsZFVXopFD7AdMgkV9FqTGy2FibMIBRgEy pecRa+I6NVUOtvygJ2tO47z7HskmxZGG1hjFm7eOeUXaFpbsd3pqw9Rg479t1X5wEyA== 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.171 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 43957606A6A5 for ; Sat, 5 Dec 2026 06:35:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43957606A6A5 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-f171.google.com with SMTP id 5a478bee46e88-386c336eab8so3476157eec.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=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=W05GA5S1oHmt5yJl/yBZ9xcbe/eaPakuMOBkFy9lwr7ZoVdaW0d7/uji9zF3OPwTRO LJW2vxW1A4CJKQvHnmY6Vh/isHgf42nOnDuRfTM1k0H2aUEnGg59vHVdWetSk5sKHYOv 50hzV5uBf5zLmUbe0Krdj71H/eGfX1eIF/TA+GDSaMOIaCOVz444MFmy/GhQCnwBYaKe fTHhqqcEn5C52bVTVrND1XSMFn1xT29TUFQ86Ae+wNoBIfVNf0C2WKwOZ2SLMvj2xue1 RKRq4BFNuYbH5E3aPBfKvEM1ZrfQu3Z+hB4HqftD2/Dql/0kkoHd8e8SVRCOTxLsUjA9 PBHA== X-Forwarded-Encrypted: i=1; AL+hErGoilvjzFfmJOeAWsoVePrd20JWLdysp7n+zWyDIwk8L9d+mD5TmXvFWREgaRJMKjCQRKS6zWcpueJASng=@vger.kernel.org X-Gm-Message-State: AB4q+uEYD3UHvLzdygPgq+vEHkaweZE8vGCfyDsaJGXooAtrJYvSaP8C UXUmg9APhAc0GCkZyw5J2cOq3kvhQuTci6HF9J0tN6P8EULi90EmDgb/ X-Gm-Gg: AZFdTZfSjXvNzlN9j+Zw9I3uAXmsMeAhSeoADBy/MGjVIIsyHCYFzQLtDcVxHcfc0It Ie503Lp457Jv1CL9t2Ncu59CXP4HwYgss8/6qmZ+BjnlGIz10Yr9vNcvha4mLBQXro0t+TPOZMJ QQeYafjyHCPdOxP1xqvhIWC4W8YIM6/pmHZ2ijBEsBkZ04oZ1p4PyiJg4ndE1kcHbEekfuJqYBE hUtxgeh8J6m5axq+2MAfoQfISHt9bL9eWU2PkxNvwNSXyXsPGIt9OvgSRjU2/X/8HXA0CiiYu6h BCIx6Cx1ylQ5pR0k8w7nJPsEuaudlF7lYu4ehzhYG3+f3jl0S42RBb9kHoQJOztDK66bfFSr8I/ QobJt97Bh4lb7niPzFWaamBpw6ThbwK5AEKUC/RCgQ146zhicMPg8tm5/cF7D1LH63JKrc5EPim JOYe/rxOteiDG3rLTDK5+lhsaP89F9h6KU2fd3TjfeGT46214fsq816HcVhN0nFsHPxgBUrse/F aihknXmMUltalqW08GQSKz05/+OneacSBXN5EmxP4d+9oLGmj8jCSpd8nLOEKVnVY93+f5hge5v UXg+SvsNQnFuh5CImrTIEwkfebeWfWWHWwk6OlXI4FrNJZeB84AV/p5Xbcy/v54SARc= 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-serial@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