drivers/net/niu.c: possible array overflows
Subsystems (2)
The Coverity checker spotted the following in drivers/net/niu.c:
<-- snip -->
...
static int __devinit niu_pci_probe_sprom(struct niu *np) {
...
val = nr64(ESPC_MOD_STR_LEN);
niudbg(PROBE, "SPROM: MOD_STR_LEN[%llu]\n",
(unsigned long long) val);
if (val > 8 * 4)
return -EINVAL;
for (i = 0; i < val; i += 4) {
u64 tmp = nr64(ESPC_NCR(5 + (i / 4)));
np->vpd.model[i + 3] = (tmp >> 0) & 0xff;
np->vpd.model[i + 2] = (tmp >> 8) & 0xff;
np->vpd.model[i + 1] = (tmp >> 16) & 0xff;
np->vpd.model[i + 0] = (tmp >> 24) & 0xff;
}
np->vpd.model[val] = '\0';
val = nr64(ESPC_BD_MOD_STR_LEN);
niudbg(PROBE, "SPROM: BD_MOD_STR_LEN[%llu]\n",
(unsigned long long) val);
if (val > 4 * 4)
return -EINVAL;
for (i = 0; i < val; i += 4) {
u64 tmp = nr64(ESPC_NCR(14 + (i / 4)));
np->vpd.board_model[i + 3] = (tmp >> 0) & 0xff;
np->vpd.board_model[i + 2] = (tmp >> 8) & 0xff;
np->vpd.board_model[i + 1] = (tmp >> 16) & 0xff;
np->vpd.board_model[i + 0] = (tmp >> 24) & 0xff;
}
np->vpd.board_model[val] = '\0';...
<-- snip -->
Check where the '\0's get written if "val" has the maximum non-EINVAL value.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedDavid Miller
maintainerFrom: Adrian Bunk <[email protected]>
Date: Sun, 14 Oct 2007 19:50:24 +0200
Quoted 1 line
The Coverity checker spotted the following in
drivers/net/niu.c:
Thanks for the report Adrian, I'll fix it like this:
commit 503211a947ab13fb44d920f78f1e19057efc277f
Author: David S. Miller <[email protected]> Date: Mon Oct 15 01:36:24 2007 -0700
[NIU]: Fix write past end of array in niu_pci_probe_sprom().
Noticed by Coverity checker and reported by Adrian Bunk.
Signed-off-by David S. Miller <[email protected]>
drivers/net/niu.c +2 -2
@@ -6213,7 +6213,7 @@ static int __devinit niu_pci_probe_sprom(struct niu *np) val =nr64 (ESPC_MOD_STR_LEN );niudbg (PROBE ,"SPROM: MOD_STR_LEN[%llu]\n" , (unsigned long long ) val); -if (val >8 *4 ) +if (val >=8 *4 )return -EINVAL ;for (i =0 ; i < val; i +=4 ) {
@@ -6229,7 +6229,7 @@ static int __devinit niu_pci_probe_sprom(struct niu *np) val =nr64 (ESPC_BD_MOD_STR_LEN );niudbg (PROBE ,"SPROM: BD_MOD_STR_LEN[%llu]\n" , (unsigned long long ) val); -if (val >4 *4 ) +if (val >=4 *4 )return -EINVAL ;for (i =0 ; i < val; i +=4 ) {