From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452550; b=jvXLNmle9Nnq+hVq4Eeib01jVmd7awVY6V1YN4cyMg9VIcvcIvd8sd9+2nPvu0t22/YZ U25ahsNfu4fj14ClZydNEcNevCjgvs7g2d0q+zNC2Kwcs3bJqehHcoBXst45pLDJ1vGsV 9lZVaTz5yE3m46d4Jd5+RAE2KR1p6hBd9F10HzSvrwPlhVsFlNjIXqdSzOVzDku6TeJCc /B+WbX7VYqHgXtb1wFosChHC0MiHl19vANSaWggHOfGAtGVSB3N315t3Oc4I2/9IISUGo ujryLAhpnzzNmd2fJGLxWxT0xKue269iWahZfbkviE48Mn5Z6TFQmbu5UImfKOlyO9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452550; 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=2qUgm3mLqogWOOXE6EFh4JUZ2Lpbw+wSILMCe/Sj0ek=; b=DeSmo1ng5a5Nn/OkZUb7l3R5X4hQFjzs6Mz+2jsVMG+C1AgrUNdxIyn0TWRkga6WOr5S msqFD/PklrOSf96YtqwIabSxIInOYneA0dVeiurxOojeKovDM6flYGsLFxthhPk/bUmsO pTy+rx4ESGqXsRuA+h4qB+dTVdpIBiM2Wme+4GvgbpmrcRA6aZwnWI+S8kunQ4zwSbQhG MJ+RwwtWI8LcNPqNOn9oVRlpqfXAT+lta+D2Iq1cAs7/JbutO6uqDfmdOA0tWriIW9p6T lAsYprGyQTz4JGkqONFy3nvKabeZQ5FVEDUwb6eLngT4ls5Uq7J0M3Oy+zftCE3WMLg== 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=xbKn7m7P; arc=none smtp.remote-ip=74.125.82.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 5B10B606A684 for ; Sat, 5 Dec 2026 06:35:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B10B606A684 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=xbKn7m7P Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-33fb4680717so7777eec.1 for ; Fri, 04 Dec 2026 22:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452549; x=1797057349; 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=2qUgm3mLqogWOOXE6EFh4JUZ2Lpbw+wSILMCe/Sj0ek=; b=xbKn7m7P37RQp+riPw7BBw9AUPJnjXcijmX02azEEGZvLEYkgGTbX1FYHHw9UT8DSz MSg9wuskNKq+WSoPEH1UNnky53zjRZRXCmgBrNbMrsLvonO2BNuo2rI/1JY1aDmx0UB0 VMyppNJmIMR7pY+TrmPtjQg9F9NF9txcsJHfMw0RSnPTyDyXK5UK0hT4YFvQOKlPLknM 4+NZYhZHb4NbfwkQ7aBnvdc5McFkS2skXJmsJV3cRAQVrC0FtJh+/pRJt8G8tW+nJP9l L7sb9qw+JMOfkkH3E/v402BS5rXMMk7/y6WysExm1NyIHQn8qW68o98rhiJNVDLOmnf/ ZI6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452549; x=1797057349; 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=2qUgm3mLqogWOOXE6EFh4JUZ2Lpbw+wSILMCe/Sj0ek=; b=QlYIFreaor87oeRWb516mcEYMcLRoLIx5NkYOYkgGCEny0WWUaanvUsdDcPmbnO4sW lUGzJTfKLjC9a0604+qMrBqpMuXy9tFyROEvEMNmir21XpVwQLeSZQ83SHlmLkAQEcLN SLRbByrsfMCDGKgYMW4AkMv0yP6W/NiLsvTMEh49r5zFpzSGUp/wJ6tjqeeGTXPgW6TX ZoG+A8EmpUVedKZFev4a/D2niHqIfIeCX5jjHaT+eLN90U7OK9kN9AVEBEmDu4G8dwdM RYo4bEGuf9u4FMV+Z8ZOT8RJKYMDIZBr0p/9bBQq/SacyLdW9lmlQvsmt7h+BsD9ApJ9 omYQ== X-Forwarded-Encrypted: i=1; AL+hErE979wjpIPx+wF9HU+bvqXXgVk4lKkNcZH7e5rXoogJfsMzBFofqqgQhGaNDAU5T0GGfJiWh/I=@vger.kernel.org X-Gm-Message-State: AB4q+uH4Vs1iKaXZqQYPQ0obWsSzvcR+YWFZXLfzrEc+WPpnC2R2nvT3 XlEj4/rWmqos9kfESaFg42C4anlTYn1DbrDf1ZIRluJwvQUIDhJfbzzR X-Gm-Gg: AZFdTZcAnGP5/uTOxf7AsQ9889nZ6GC8Ook4GORfpMtDGN0KUViyaDv2bLUcmhb0lqH XIF7Jm1M9ugAQRhpBScllzpM6IX/K+43ppbjEvclAv9MAk7v6iSkFf/wQANv2A6N/P/SxBLqR7V r/7STf5Pt5zyziXVFZElYqr8w/11D5r16HIijNFrgZZ1CiXX3dra1tXUckAnh208gq4JFT8AJEu fzsKH0OYg+mdc8ct4L8sOCRk4KNs1JLrGixEJxHDFA0cfy59Cpah70+JyYWmMa9yVZAOmlcX03a 3ehmo1D2X5R+LqVtTw84GYIm5bP6M0qO9FEgJd687dKt1MPbQ4rDHi++o7udmZK1VlEwDMjI+S7 Poc/INXSaAmU2gsC0o49sBGZ8GB8zJuJwjfB8ISjX0i/rAQ+6Wmiz1knWYslvOcQcqLb+cjNSKw qnfM+NJcsB3wKE2CVyHOcEUW+vEXHROqNCW0jubkIo4cSl1JT3NH7GSt5lBhUNF2DtqTdVDwiD+ ou/xW6jCraGmjMPi2Dl+JlbLO4YEgEVUk26LVdnwEBUl3pLk74fi8GsgaIDXbT4aM6FzKXSGxuY G2TxWAMun2Em3yw37+TtoIeX2/7EkuKhf6ZumTEhvq7zHSL781e5pXj+oevmKtrPNZE= X-Received: by 2002:a05:7300:33a8:b0:386:cf0c:8482 with SMTP id 5a478bee46e88-387521448d8mr4072244eec.24.1796452549507; Fri, 04 Dec 2026 22:35:49 -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.48 (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: Richard Genoud , Greg Kroah-Hartman , Jiri Slaby , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea Cc: Praneeth Balasubramanian , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/4] tty: atmel_serial: take the port lock in console write Date: Fri, 4 Dec 2026 22:35:35 -0800 Message-Id: <20261205063536.2519566-4-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: stable@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 atmel_console_write() touches the PDC and USART TX control registers and the tx_stopped flag without holding the port lock. atmel_stop_tx() and atmel_start_tx() run under the lock. So the console can race with a TCXONC ioctl or another path that stops the transmitter. The comment that says interrupts are disabled on entry does not hold on PREEMPT_RT. There legacy consoles are printed from a kthread, and con->write runs in task context with interrupts enabled. If atmel_stop_tx() runs while the console is between its PDC_TXTEN snapshot and the TXTEN restore, the console re-enables a transmitter that was just stopped and writes back a stale PDC_TXTEN value. The port ends up in an inconsistent state and serial output can stall. Take the port lock for the whole callback so the register accesses are serialized against the other paths. Drop the stale comment. Follow the pl011 pattern: skip the lock when a sysrq is being handled on the port, since atmel_rx_chars() calls uart_handle_sysrq_char() under the port lock, and use a trylock when an oops is in progress. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: 39d4c922b596 ("atmel_serial: fix uart/console concurrent access") Cc: stable@vger.kernel.org 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. James Hilliard's serial port lock series (v14, 2026-12-04) changes other functions in atmel_serial.c, not atmel_console_write(). The two may need a rebase against each other. drivers/tty/serial/atmel_serial.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index c3880259e3bc..7446c956262a 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -2560,15 +2560,21 @@ static void atmel_console_putchar(struct uart_port *port, unsigned char ch) atmel_uart_write_char(port, ch); } -/* - * Interrupts are disabled on entering - */ static void atmel_console_write(struct console *co, const char *s, u_int count) { struct uart_port *port = &atmel_ports[co->index].uart; struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); unsigned int status, imr; unsigned int pdc_tx; + unsigned long flags; + int locked = 1; + + if (port->sysrq) + locked = 0; + else if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); /* * First, save IMR and then disable interrupts @@ -2601,6 +2607,9 @@ static void atmel_console_write(struct console *co, const char *s, u_int count) /* set interrupts back the way they were */ atmel_uart_writel(port, ATMEL_US_IER, imr); + + if (locked) + uart_port_unlock_irqrestore(port, flags); } /* -- 2.25.1