lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240704082658.189577-1-islituo@gmail.com>
Date: Thu,  4 Jul 2024 16:26:58 +0800
From: Tuo Li <islituo@...il.com>
To: gregkh@...uxfoundation.org,
	jirislaby@...nel.org
Cc: baijiaju1990@...il.com,
	linux-kernel@...r.kernel.org,
	linux-serial@...r.kernel.org,
	Tuo Li <islituo@...il.com>
Subject: [PATCH] tty: n_gsm: fix a possible data race in gsmtty_open

In the function gsmtty_open(), the counter port->count is updated without
holding the lock port->lock, which may lead to a data race.

This possible data race is found by an experimental static analysis tool.
This tool analyzes the locking APIs to deduce locking rules about which
variable should be protected by which lock. And then the tool checks
whether a given variable access violates the deduced locking rules, to
detect data races. The above possible data race is reported, when the tool
analyzes the source code of Linux 6.2.

Referring to the function tty_port_open() in tty_port.c:
  spin_lock_irq(&port->lock);
  ++port->count;
  spin_unlock_irq(&port->lock);
    
we add a lock/unlock pair to protect the access to port->count, to fix
this possible data race.

Fixes: 86176ed90545 ("TTY: n_gsm, use tty_port_install")
Signed-off-by: Tuo Li <islituo@...il.com>
---
 drivers/tty/n_gsm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index be35f7334ecd..b709f1a6bd2d 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -4307,7 +4307,9 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
 	struct gsm_dlci *dlci = tty->driver_data;
 	struct tty_port *port = &dlci->port;
 
+	spin_lock_irq(&port->lock);
 	port->count++;
+	spin_unlock_irq(&port->lock);
 	tty_port_tty_set(port, tty);
 
 	dlci->modem_rx = 0;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ