Bug in serial driver in 2.1.125 (patch included)

Matthias.Fengler@dresdner-bank.com
Thu, 22 Oct 1998 11:20:26 +0100


A non-privileged user should be able to set or reset the ASYNC_SPD_* flags
on a serial port, but he actually isn't. setserial (or TIOC[SG]SERIAL) will
allow him to change these settings and will also return those changed values
afterwards even though the kernel won't use these values for the port.
Setting the custom divisor works fine, so once root has set the
ASYNC_SPD_CUST flag a normal user can specify the divisor, but is unable to
reset the port to plain 38400 baud by resetting ASYNC_SPD_CUST.

For some reason (can anybody tell me why?) these flags are held in two
different places within the async_struct (flags and state->flags) and happen
to diverge for a non-root user.

Here's a small patch that fixes the problem:

--- serial.c.orig Tue Sep 1 19:32:13 1998
+++ serial.c Thu Oct 22 11:21:54 1998
@@ -32,6 +32,10 @@
* 4/98: Added changes to support the ARM architecture proposed by
* Russell King
*
+ * 10/98: Fixed bug in set_serial_info to allow non-privileged user
+ * to set/reset ASYNC_SPD_* flags
+ * Matthias Fengler <mfengler@iname.com>
+ *
* This module exports the following rs232 io functions:
*
* int rs_init(void);
@@ -1653,6 +1657,8 @@
return -EPERM;
state->flags = ((state->flags & ~ASYNC_USR_MASK) |
(new_serial.flags & ASYNC_USR_MASK));
+ info->flags = ((info->flags & ~ASYNC_USR_MASK) |
+ (new_serial.flags & ASYNC_USR_MASK));
state->custom_divisor = new_serial.custom_divisor;
goto check_and_exit;
}

And here is another small patch that allows root to set/reset ASYNC_SPD_VHI
and ASYNC_SPD_WARP. In this particular case a non-privileged user CAN
set/reset these flags, but root can't.
There is obviously one bit missing in the ASYNC_FLAGS mask that controls
those higher baud rates (230 kbps, 460 kbps). This bit is present in the
ASYNC_USR_MASK.

--- serial.h.orig Sat Apr 18 07:04:44 1998
+++ serial.h Thu Oct 22 11:30:33 1998
@@ -87,7 +87,7 @@

#define ASYNC_LOW_LATENCY 0x2000 /* Request low latency behaviour */

-#define ASYNC_FLAGS 0x2FFF /* Possible legal async flags */
+#define ASYNC_FLAGS 0x3FFF /* Possible legal async flags */
#define ASYNC_USR_MASK 0x3430 /* Legal flags that non-privileged
* users can set or reset */

Please let these patches go into 2.1.126

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/