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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220830072956.3630-3-ilpo.jarvinen@linux.intel.com>
Date:   Tue, 30 Aug 2022 10:29:54 +0300
From:   Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jirislaby@...nel.org>,
        linux-serial@...r.kernel.org,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        linux-kernel@...r.kernel.org
Cc:     Lino Sanfilippo <LinoSanfilippo@....de>,
        Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
        Andy Shevchenko <andy.shevchenko@...il.com>
Subject: [PATCH v2 2/4] serial: add helpers to copy serial_rs485 from/to userspace

Due to the padding fields, the copying will need to do a bit more than
usual.

Move padding clearing into the helper that copies back to userspace.

Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
---
 drivers/tty/serial/serial_core.c | 41 +++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 8834414a0b2f..4a4ed619ee71 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1375,10 +1375,6 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4
 	rs485->flags &= supported_flags;
 
 	uart_sanitize_serial_rs485_delays(port, rs485);
-
-	/* Return clean padding area to userspace */
-	memset(rs485->padding0, 0, sizeof(rs485->padding0));
-	memset(rs485->padding1, 0, sizeof(rs485->padding1));
 }
 
 static void uart_set_rs485_termination(struct uart_port *port,
@@ -1407,6 +1403,28 @@ int uart_rs485_config(struct uart_port *port)
 }
 EXPORT_SYMBOL_GPL(uart_rs485_config);
 
+static int serial_rs485_from_user(struct serial_rs485 *rs485,
+				  const struct serial_rs485 __user *rs485_user)
+{
+	if (copy_from_user(rs485, rs485_user, sizeof(*rs485)))
+		return -EFAULT;
+
+	return 0;
+}
+
+static int serial_rs485_to_user(struct serial_rs485 __user *rs485_user,
+				struct serial_rs485 *rs485)
+{
+	/* Return clean padding area to userspace */
+	memset(rs485->padding0, 0, sizeof(rs485->padding0));
+	memset(rs485->padding1, 0, sizeof(rs485->padding1));
+
+	if (copy_to_user(rs485_user, rs485, sizeof(*rs485)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static int uart_get_rs485_config(struct uart_port *port,
 			 struct serial_rs485 __user *rs485_user)
 {
@@ -1417,10 +1435,7 @@ static int uart_get_rs485_config(struct uart_port *port,
 	rs485 = port->rs485;
 	spin_unlock_irqrestore(&port->lock, flags);
 
-	if (copy_to_user(rs485_user, &rs485, sizeof(rs485)))
-		return -EFAULT;
-
-	return 0;
+	return serial_rs485_to_user(rs485_user, &rs485);
 }
 
 static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port,
@@ -1433,8 +1448,9 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port,
 	if (!port->rs485_config)
 		return -ENOTTY;
 
-	if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
-		return -EFAULT;
+	ret = serial_rs485_from_user(&rs485, rs485_user);
+	if (ret)
+		return ret;
 
 	ret = uart_check_rs485_flags(port, &rs485);
 	if (ret)
@@ -1450,10 +1466,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port,
 	if (ret)
 		return ret;
 
-	if (copy_to_user(rs485_user, &port->rs485, sizeof(port->rs485)))
-		return -EFAULT;
-
-	return 0;
+	return serial_rs485_to_user(rs485_user, &port->rs485);
 }
 
 static int uart_get_iso7816_config(struct uart_port *port,
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ