From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Subject: [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region
Date: Fri, 4 Dec 2026 22:35:34 -0800 [thread overview]
Message-ID: <20261205063536.2519566-3-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063536.2519566-1-praneethb2002@gmail.com>
men_z135_config_port() sets the port type and ignores the return value
of men_z135_request_port(). The port type is also set in probe. So the
port stays registered even when the memory request fails, for example
when mcb_request_mem() returns -EBUSY because the region is already
claimed.
serial core calls release_port for any port with a known type. After
a failed request uart->mem is still NULL, and men_z135_release_port()
passes it to mcb_release_mem(), which dereferences it. When ioremap()
fails instead, men_z135_request_port() releases the region itself but
leaves uart->mem set. A later release_port then releases the same
region a second time.
Set uart->mem only once the region is requested and mapped. In
men_z135_release_port(), release the region only if uart->mem is set,
and clear it afterwards.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 37f0679964fa ("tty: serial: men_z135_uart.c: use mcb memory region size instead of hardcoded one")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
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/serial/men_z135_uart.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
index 861b783cec3d..2eddac1da37e 100644
--- a/drivers/tty/serial/men_z135_uart.c
+++ b/drivers/tty/serial/men_z135_uart.c
@@ -726,7 +726,10 @@ static void men_z135_release_port(struct uart_port *port)
iounmap(port->membase);
port->membase = NULL;
- mcb_release_mem(uart->mem);
+ if (uart->mem) {
+ mcb_release_mem(uart->mem);
+ uart->mem = NULL;
+ }
}
static int men_z135_request_port(struct uart_port *port)
@@ -740,13 +743,13 @@ static int men_z135_request_port(struct uart_port *port)
return PTR_ERR(mem);
port->mapbase = mem->start;
- uart->mem = mem;
port->membase = ioremap(mem->start, resource_size(mem));
if (port->membase == NULL) {
mcb_release_mem(mem);
return -ENOMEM;
}
+ uart->mem = mem;
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2026-12-05 6:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261205063536.2519566-1-praneethb2002@gmail.com>
2026-12-05 6:35 ` [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond() Praneeth Balasubramanian
2026-12-05 6:35 ` Praneeth Balasubramanian [this message]
2026-12-05 6:35 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205063536.2519566-3-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox