Skip to contentSkip to conversation

drivers/net/usb/hso.c: prevent reading uninitialized memory

PATCH Applied Dan Rosenberg 4 participants 7 messages Sep 15, 2010 – Sep 17, 2010

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

PATCH v2 1/1 drivers/net/usb/hso.c: prevent reading uninitialized memory

Fixed formatting (tabs and line breaks).

The TIOCGICOUNT device ioctl allows unprivileged users to read uninitialized stack memory, because the "reserved" member of the serial_icounter_struct struct declared on the stack in hso_get_count() is not altered or zeroed before being copied back to the user. This patch takes care of it.

drivers/net/usb/hso.c +2 -0
@@ -1653,6 +1653,8 @@ static int hso_get_count(struct hso_seri
 	struct uart_icount cnow;
 	struct hso_tiocmget  *tiocmget = serial->tiocmget;
 
+	memset(&icount, 0, sizeof(struct serial_icounter_struct));
+
 	if (!tiocmget)
 		 return -ENOENT;
 	spin_lock_irq(&serial->serial_lock);
#1 lore raw
Quoted 13 lines · Dan Rosenberg

Fixed formatting (tabs and line breaks).

The TIOCGICOUNT device ioctl allows unprivileged users to read uninitialized stack memory, because the "reserved" member of the serial_icounter_struct struct declared on the stack in hso_get_count() is not altered or zeroed before being copied back to the user. This patch takes care of it.

drivers/net/usb/hso.c static int hso_get_count(struct hso_seri · line 1657

Quoted 5 lines
drivers/net/usb/hso.c +2 -0
@@ -1653,6 +1653,8 @@ static int hso_get_count(struct hso_seri
 	struct uart_icount cnow;
 	struct hso_tiocmget  *tiocmget = serial->tiocmget;
 
+	memset(&icount, 0, sizeof(struct serial_icounter_struct));
+

Move the above to after the spinlocks.

-- Steve

Quoted 4 lines
drivers/net/usb/hso.c +0 -0
 	if (!tiocmget)
 		 return -ENOENT;
 	spin_lock_irq(&serial->serial_lock);
#2 lore raw

->tiocmget;

Quoted 5 lines

drivers/net/usb/hso.c static int hso_get_count(struct hso_seri · line 1657

Quoted 3 lines
drivers/net/usb/hso.c +2 -0
+	memset(&icount, 0, sizeof(struct serial_icounter_struct));
+

Move the above to after the spinlocks.

Why - its a local variable ?

Easier to write

	struct serial_icounter_struct icount = { 0 };

though

#3 lore raw
Quoted 7 lines · Alan Cox

->tiocmget;

Quoted 5 lines

drivers/net/usb/hso.c static int hso_get_count(struct hso_seri · line 1657

Quoted 3 lines
drivers/net/usb/hso.c +2 -0
+	memset(&icount, 0, sizeof(struct serial_icounter_struct));
+

Move the above to after the spinlocks.

Quoted 7 lines

Why - its a local variable ?

Easier to write

	struct serial_icounter_struct icount = { 0 };

though

True, but if we want to micro-optimize, moving it after the spinlocks means we do no zero initialization in the tiocmget == 0. Although gcc may be smart enough to realize that too.

-- Steve

#4 lore raw
Quoted 12 lines · On Thu, 16 Sep 2010 12:52:40 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 11 lines · Alan Cox

->tiocmget;

Quoted 5 lines

drivers/net/usb/hso.c static int hso_get_count(struct hso_seri · line 1657

Quoted 3 lines
drivers/net/usb/hso.c +2 -0
+	memset(&icount, 0, sizeof(struct serial_icounter_struct));
+

Move the above to after the spinlocks.

Why - its a local variable ?

Easier to write

Quoted 7 lines
Quoted 3 lines
	struct serial_icounter_struct icount = { 0 };

though

True, but if we want to micro-optimize, moving it after the spinlocks means we do no zero initialization in the tiocmget == 0. Although gcc may be smart enough to realize that too.

If you want to micro-optimise it you can enumerate the cases that tiocmget can be NULL in that driver..

#5 lore raw
Quoted 2 lines · Alan Cox

If you want to micro-optimise it you can enumerate the cases that tiocmget can be NULL in that driver..

Heh, I think that's going a bit too far. Of course mico-optimizations usually make the system go faster, but not enough to show out of the noise, and micro-optimizations most of the time just make the code harder to understand and more error prone.

A lot of the patches in this patch set could just do the:

	struct foo bar = { 0 };

This would let gcc optimize what needs to be done, and avoids a function call to memset.

-- Steve

maintainer Applied
#6 lore raw
In reply to Dan Rosenberg

From: Dan Rosenberg <[email protected]>
Date: Wed, 15 Sep 2010 17:43:28 -0400

Quoted 9 lines

Fixed formatting (tabs and line breaks).

The TIOCGICOUNT device ioctl allows unprivileged users to read uninitialized stack memory, because the "reserved" member of the serial_icounter_struct struct declared on the stack in hso_get_count() is not altered or zeroed before being copied back to the user. This patch takes care of it.

Applied.