* [PATCH] Fix array overflow in parport_serial.c @ 2008-11-20 16:35 Takashi Iwai 2008-11-21 22:16 ` Andrew Morton 0 siblings, 1 reply; 3+ messages in thread From: Takashi Iwai @ 2008-11-20 16:35 UTC (permalink / raw) To: linux-kernel; +Cc: Andrew Morton The netmos_9xx5_combo type assumes that PCI SSID provides always the correct value for the number of parallel and serial ports, but there are indeed broken devices with wrong numbers, which may result in Oops. This patch simply adds the check of the array range. Reference: Novell bnc#447067 https://bugzilla.novell.com/show_bug.cgi?id=447067 Signed-off-by: Takashi Iwai <tiwai@suse.de> --- diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index e2e95b3..101ed49 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -70,6 +70,8 @@ static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc * parallel ports and <S> is the number of serial ports. */ card->numports = (dev->subsystem_device & 0xf0) >> 4; + if (card->numports > ARRAY_SIZE(card->addr)) + card->numports = ARRAY_SIZE(card->addr); return 0; } ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix array overflow in parport_serial.c 2008-11-20 16:35 [PATCH] Fix array overflow in parport_serial.c Takashi Iwai @ 2008-11-21 22:16 ` Andrew Morton 2008-11-22 9:56 ` Takashi Iwai 0 siblings, 1 reply; 3+ messages in thread From: Andrew Morton @ 2008-11-21 22:16 UTC (permalink / raw) To: Takashi Iwai; +Cc: linux-kernel On Thu, 20 Nov 2008 17:35:20 +0100 Takashi Iwai <tiwai@suse.de> wrote: > Subject: [PATCH] Fix array overflow in parport_serial.c Please prefer titles in the form subsystem identifer: what was done to it I renamed this one to parport_serial: fix array overflow > Date: Thu, 20 Nov 2008 17:35:20 +0100 > User-Agent: Wanderlust/2.12.0 (Your Wildest Dreams) SEMI/1.14.6 (Maruoka) > FLIM/1.14.7 (Sanj__) APEL/10.6 Emacs/22.3 > (x86_64-suse-linux-gnu) MULE/5.0 (SAKAKI) > > The netmos_9xx5_combo type assumes that PCI SSID provides always the > correct value for the number of parallel and serial ports, but there > are indeed broken devices with wrong numbers, which may result in > Oops. > > This patch simply adds the check of the array range. > > Reference: Novell bnc#447067 > https://bugzilla.novell.com/show_bug.cgi?id=447067 > > Signed-off-by: Takashi Iwai <tiwai@suse.de> > > --- > diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c > index e2e95b3..101ed49 100644 > --- a/drivers/parport/parport_serial.c > +++ b/drivers/parport/parport_serial.c > @@ -70,6 +70,8 @@ static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc > * parallel ports and <S> is the number of serial ports. > */ > card->numports = (dev->subsystem_device & 0xf0) >> 4; > + if (card->numports > ARRAY_SIZE(card->addr)) hm. ARRAY_SIZE returns an unsigned type so we don't have to worry about negative values when doing comparisons like this. Not that card->numports could be negative anyway, but it's always nice to set readers' minds at rest.. > + card->numports = ARRAY_SIZE(card->addr); > return 0; > } Should we emit some kind of warning when this is detected? I guess not, if we're sure that there will never be a situation in which users find that some of their ports don't work? ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix array overflow in parport_serial.c 2008-11-21 22:16 ` Andrew Morton @ 2008-11-22 9:56 ` Takashi Iwai 0 siblings, 0 replies; 3+ messages in thread From: Takashi Iwai @ 2008-11-22 9:56 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel At Fri, 21 Nov 2008 14:16:21 -0800, Andrew Morton wrote: > > On Thu, 20 Nov 2008 17:35:20 +0100 > Takashi Iwai <tiwai@suse.de> wrote: > > > Subject: [PATCH] Fix array overflow in parport_serial.c > > Please prefer titles in the form > > subsystem identifer: what was done to it > > I renamed this one to > > parport_serial: fix array overflow Yep, better. Thanks. > > Date: Thu, 20 Nov 2008 17:35:20 +0100 > > User-Agent: Wanderlust/2.12.0 (Your Wildest Dreams) SEMI/1.14.6 (Maruoka) > > FLIM/1.14.7 (Sanj__) APEL/10.6 Emacs/22.3 > > (x86_64-suse-linux-gnu) MULE/5.0 (SAKAKI) > > > > The netmos_9xx5_combo type assumes that PCI SSID provides always the > > correct value for the number of parallel and serial ports, but there > > are indeed broken devices with wrong numbers, which may result in > > Oops. > > > > This patch simply adds the check of the array range. > > > > Reference: Novell bnc#447067 > > https://bugzilla.novell.com/show_bug.cgi?id=447067 > > > > Signed-off-by: Takashi Iwai <tiwai@suse.de> > > > > --- > > diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c > > index e2e95b3..101ed49 100644 > > --- a/drivers/parport/parport_serial.c > > +++ b/drivers/parport/parport_serial.c > > @@ -70,6 +70,8 @@ static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc > > * parallel ports and <S> is the number of serial ports. > > */ > > card->numports = (dev->subsystem_device & 0xf0) >> 4; > > + if (card->numports > ARRAY_SIZE(card->addr)) > > hm. ARRAY_SIZE returns an unsigned type so we don't have to worry > about negative values when doing comparisons like this. Not that > card->numports could be negative anyway, but it's always nice to set > readers' minds at rest.. I think changing numports to unsigned is the easiest way. > > + card->numports = ARRAY_SIZE(card->addr); > > return 0; > > } > > > Should we emit some kind of warning when this is detected? I guess > not, if we're sure that there will never be a situation in which users > find that some of their ports don't work? I thought of that, too, but wanted to make the change minimum. Besides that, I'm not sure whether netmos_parallel_init() really works as its description. It changes numports, but it doesn't change the addr[]. In cards[], only one item is defined, thus all of the reset point BAR 0. I made the patch just to fix the oops, but this code should be fixed in a better way, anyway. thanks, Takashi ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-22 9:56 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-11-20 16:35 [PATCH] Fix array overflow in parport_serial.c Takashi Iwai 2008-11-21 22:16 ` Andrew Morton 2008-11-22 9:56 ` Takashi Iwai
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.