Skip to contentSkip to conversation

/proc/tty/driver/* filtering for non CAP_SYS_RAWIO

PATCH New [email protected] 1 participant 1 message Jul 31, 2005

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 /proc/tty/driver/* filtering for non CAP_SYS_RAWIO

From: Daniel Smertnig <[email protected]>

Only give out non-sensitive information to CAP_SYS_RAWIO users in /proc/tty/driver/* and make it world-readable, as described in the kernel janitors TODO:

"go through all the tty/serial drivers and make sure they don't give out excessively useful information to non CAP_SYS_RAWIO users, then loosen permissions. [D: http://lkml.org/lkml/2005/1/17/94]"

Only port settings (irqs, baud rate, flow control configuration, ...) are given to ordinary users. Current port status (tx, rx, error counters, status flags, ...) is limited to CAP_SYS_RAWIO users.

The following files where checked (should be all serial drivers which implement the tty read_proc function):

arch/ia64/hp/sim/simserial.c
arch/xtensa/platform-iss/console.c
drivers/usb/serial/usb-serial.c
drivers/char/synclinkmp.c
drivers/char/istallion.c
drivers/char/amiserial.c
drivers/char/cyclades.c
drivers/char/stallion.c
drivers/char/pcmcia/synclink_cs.c
drivers/char/ip2main.c
drivers/char/synclink.c
drivers/isdn/capi/capi.c
drivers/serial/crisv10.c
drivers/serial/serial_core.c
drivers/serial/mcfserial.c
drivers/serial/68360serial.c
drivers/macintosh/macserial.c
drivers/net/wan/sdla_chdlc.c
net/irda/ircomm/ircomm_tty.c
net/bluetooth/rfcomm/tty.c

---
 drivers/char/amiserial.c          |   16 +++++++----
 drivers/char/cyclades.c           |   44 ++++++++++++++++++++-----------
 drivers/char/istallion.c          |    2 -
 drivers/char/pcmcia/synclink_cs.c |    5 +++
 drivers/char/stallion.c           |   53 ++++++++++++++++++++++----------------
 drivers/char/synclink.c           |    5 +++
 drivers/char/synclinkmp.c         |    4 ++
 drivers/serial/68360serial.c      |   16 +++++++----
 drivers/serial/crisv10.c          |    7 +++++
 drivers/serial/mcfserial.c        |    7 +++++
 drivers/serial/serial_core.c      |    2 -
 fs/proc/proc_tty.c                |    9 +-----
 net/irda/ircomm/ircomm_tty.c      |   50 +++++++++++++++++++----------------
 13 files changed, 140 insertions(+), 80 deletions(-)
drivers/char/amiserial.c +11 -5
Index: quilt/drivers/char/amiserial.c
===================================================================
@@ -1886,6 +1886,17 @@ static inline int line_info(char *buf, s
 		info->quot = 0;
 		info->tty = NULL;
 	}
+
+	if (info->quot) {
+		ret += sprintf(buf+ret, " baud:%d",
+			       state->baud_base / info->quot);
+	}
+
+	if (!capable(CAP_SYS_RAWIO)) {
+		strcat(buf, "\n");
+		return ret + 1;
+	}
+
 	local_irq_save(flags);
 	status = ciab.pra;
 	control = info ? info->MCR : status;
@@ -1904,11 +1915,6 @@ static inline int line_info(char *buf, s
 	if(!(status & SER_DCD))
 		strcat(stat_buf, "|CD");
 
-	if (info->quot) {
-		ret += sprintf(buf+ret, " baud:%d",
-			       state->baud_base / info->quot);
-	}
-
 	ret += sprintf(buf+ret, " tx:%d rx:%d",
 		      state->icount.tx, state->icount.rx);
 
drivers/char/cyclades.c +28 -16

56 lines not on this page · raw message

drivers/char/istallion.c +1 -1
Index: quilt/drivers/char/istallion.c
===================================================================
@@ -2510,7 +2510,7 @@ static int stli_portinfo(stlibrd_t *brdp
 	sp = pos;
 	sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
 
-	if ((brdp->state & BST_STARTED) && (rc >= 0)) {
+	if (capable(CAP_SYS_RAWIO) && (brdp->state & BST_STARTED) && (rc >= 0)) {
 		sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
 			(int) stli_comstats.rxtotal);
 
drivers/char/pcmcia/synclink_cs.c +5 -0
Index: quilt/drivers/char/pcmcia/synclink_cs.c
===================================================================
@@ -2873,6 +2873,11 @@ static inline int line_info(char *buf, M
 	ret = sprintf(buf, "%s:io:%04X irq:%d",
 		      info->device_name, info->io_base, info->irq_level);
 
+	if (!capable(CAP_SYS_RAWIO)) {
+		strcat(buf, "\n");
+		return ret + 1;
+	}
+
 	/* output current serial signal states */
 	spin_lock_irqsave(&info->lock,flags);
  	get_signals(info);
drivers/char/stallion.c +31 -22

59 lines not on this page · raw message

drivers/char/synclink.c +5 -0
Index: quilt/drivers/char/synclink.c
===================================================================
@@ -3554,6 +3554,11 @@ static inline int line_info(char *buf, s
 			info->irq_level, info->dma_level);
 	}
 
+	if (!capable(CAP_SYS_RAWIO)) {
+		strcat(buf, "\n");
+		return ret + 1;
+	}
+
 	/* output current serial signal states */
 	spin_lock_irqsave(&info->irq_spinlock,flags);
  	usc_get_serial_signals(info);
drivers/char/synclinkmp.c +4 -0
Index: quilt/drivers/char/synclinkmp.c
===================================================================
@@ -1424,6 +1424,10 @@ static inline int line_info(char *buf, S
 		info->irq_level,
 		info->max_frame_size );
 
+	if (!capable(CAP_SYS_RAWIO)) {
+		return ret;
+	}
+
 	/* output current serial signal states */
 	spin_lock_irqsave(&info->lock,flags);
  	get_signals(info);
drivers/serial/68360serial.c +11 -5
Index: quilt/drivers/serial/68360serial.c
===================================================================
@@ -2021,6 +2021,17 @@ static inline int line_info(char *buf, s
 		info->quot = 0;
 		info->tty = 0;
 	}
+
+	if (info->quot) {
+		ret += sprintf(buf+ret, " baud:%d",
+			       state->baud_base / info->quot);
+	}
+
+	if (!capable(CAP_SYS_RAWIO)) {
+		strcat(buf, "\n");
+		return ret + 1;
+	}
+
 	local_irq_disable();
 	status = serial_in(info, UART_MSR);
 	control = info ? info->MCR : serial_in(info, UART_MCR);
@@ -2041,11 +2052,6 @@ static inline int line_info(char *buf, s
 	if (status & UART_MSR_RI)
 		strcat(stat_buf, "|RI");
 
-	if (info->quot) {
-		ret += sprintf(buf+ret, " baud:%d",
-			       state->baud_base / info->quot);
-	}
-
 	ret += sprintf(buf+ret, " tx:%d rx:%d",
 		      state->icount.tx, state->icount.rx);
 
drivers/serial/crisv10.c +7 -0
Index: quilt/drivers/serial/crisv10.c
===================================================================
@@ -4731,6 +4731,13 @@ extern _INLINE_ int line_info(char *buf,
 		return ret;
 	}
 
+	ret += sprintf(buf+ret, " baud:%d", info->baud);
+
+	if (!capable(CAP_SYS_RAWIO)) {
+		strcat(buf, "\n");
+		return ret + 1;
+	}
+
 	stat_buf[0] = 0;
 	stat_buf[1] = 0;
 	if (!E100_RTS_GET(info))
drivers/serial/mcfserial.c +7 -0
Index: quilt/drivers/serial/mcfserial.c
===================================================================
@@ -1581,6 +1581,13 @@ int mcfrs_readproc(char *page, char **st
 		info = &mcfrs_table[i];
 		len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
 			i, (unsigned int) info->addr, info->irq, info->baud);
+
+		if (!capable(CAP_SYS_RAWIO)) {
+			strcat(page, "\n");
+			len++;
+			continue;
+		}
+
 		if (info->stats.rx || info->stats.tx)
 			len += sprintf((page + len), "tx:%d rx:%d ",
 			info->stats.tx, info->stats.rx);
drivers/serial/serial_core.c +1 -1
Index: quilt/drivers/serial/serial_core.c
===================================================================
@@ -1640,7 +1640,7 @@ static int uart_line_info(char *buf, str
 		return ret + 1;
 	}
 
-	if(capable(CAP_SYS_ADMIN))
+	if (capable(CAP_SYS_RAWIO))
 	{
 		spin_lock_irq(&port->lock);
 		status = port->ops->get_mctrl(port);
fs/proc/proc_tty.c +2 -7
Index: quilt/fs/proc/proc_tty.c
===================================================================
@@ -227,13 +227,8 @@ void __init proc_tty_init(void)
 	if (!proc_mkdir("tty", NULL))
 		return;
 	proc_tty_ldisc = proc_mkdir("tty/ldisc", NULL);
-	/*
-	 * /proc/tty/driver/serial reveals the exact character counts for
-	 * serial links which is just too easy to abuse for inferring
-	 * password lengths and inter-keystroke timings during password
-	 * entry.
-	 */
-	proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR | S_IXUSR, NULL);
+
+	proc_tty_driver = proc_mkdir("tty/driver", NULL);
 
 	create_proc_read_entry("tty/ldiscs", 0, NULL, tty_ldiscs_read_proc, NULL);
 	entry = create_proc_entry("tty/drivers", 0, NULL);
net/irda/ircomm/ircomm_tty.c +27 -23

65 lines not on this page · raw message

--