Message ID | 1284587008.6275.95.camel@dan |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
On Wed, Sep 15, 2010 at 05:43:28PM -0400, Dan Rosenberg wrote: > 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. > > Signed-off-by: Dan Rosenberg <dan.j.rosenberg@gmail.com> > > --- linux-2.6.35.4.orig/drivers/net/usb/hso.c 2010-08-26 19:47:12.000000000 -0400 > +++ linux-2.6.35.4/drivers/net/usb/hso.c 2010-09-14 21:26:18.477585183 -0400 > @@ -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 > if (!tiocmget) > return -ENOENT; > spin_lock_irq(&serial->serial_lock); > -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2010-09-16 at 18:07 +0100, Alan Cox wrote: > ->tiocmget; > > > > > > + 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 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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
->tiocmget; > > > > + 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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2010-09-16 at 18:47 +0100, Alan Cox wrote: > 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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 16 Sep 2010 12:52:40 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > On Thu, 2010-09-16 at 18:07 +0100, Alan Cox wrote: > > ->tiocmget; > > > > > > > > + 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 > > 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.. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Dan Rosenberg <drosenberg@vsecurity.com> Date: Wed, 15 Sep 2010 17:43:28 -0400 > 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. > > Signed-off-by: Dan Rosenberg <dan.j.rosenberg@gmail.com> Applied. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
--- linux-2.6.35.4.orig/drivers/net/usb/hso.c 2010-08-26 19:47:12.000000000 -0400 +++ linux-2.6.35.4/drivers/net/usb/hso.c 2010-09-14 21:26:18.477585183 -0400 @@ -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);
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. Signed-off-by: Dan Rosenberg <dan.j.rosenberg@gmail.com> -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html