drivers/net/usb/hso.c: prevent reading uninitialized memory
Subsystems (4)
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_seristruct 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);
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_structstruct declared on the stack inhso_get_count()is not altered or zeroed before being copied back to the user. This patch takes care of it.Signed-off-by Dan Rosenberg <[email protected]>
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_seristruct 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
-0if (!tiocmget)return -ENOENT ;spin_lock_irq (&serial->serial_lock);
->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
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
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..
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
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_structstruct declared on the stack inhso_get_count()is not altered or zeroed before being copied back to the user. This patch takes care of it.Signed-off-by Dan Rosenberg <[email protected]>
Applied.