Bug 11408

Summary: (patch queued) another possible buffer-overflow bug in applicom.c
Product: Drivers Reporter: Zvonimir Rakamaric (zrakamar)
Component: Flash/Memory Technology DevicesAssignee: Alan (alan)
Status: CLOSED CODE_FIX    
Severity: normal CC: eugeneteo, zrakamar
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.26 Subsystem:
Regression: --- Bisected commit-id:

Description Zvonimir Rakamaric 2008-08-22 15:07:22 UTC
Hi,

first of all, I appreciate your quick response regarding the bug related to the same file (applicom.c) I submitted recently (Bug #11397). If you ever get to taking a closer look and maybe fixing that one, here is another one from the same file.

Problem Description:

Here is the part of code from applicom.c (function ac_ioctl) showing what I think is a possible buffer-overflow bug:

.....
  IndexCard = adgl->num_card-1;
	 
  if(cmd != 0 && cmd != 6 &&
      ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
    static int warncount = 10;
    if (warncount) {
      printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
      warncount--;
    }
    kfree(adgl);
    return -EINVAL;
  }

  switch (cmd) {
		
  case 0:
    pmem = apbs[IndexCard].RamIO;
....


Explanation:

If cmd == 0 (or cmd == 6) then IndexCard is not going to be checked for size in this if statement:
  if(cmd != 0 && cmd != 6 &&
      ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {

which means that when we hit this case:
  case 0:
    pmem = apbs[IndexCard].RamIO;

it is possible that IndexCard >= MAX_BOARD and we have a buffer overflow.

There is a possibility, however, that there is an implicit, complex invariant that whenever cmd == 0 or cmd == 6, IndexCard is never going to be out of bounds and therefore doesn't have to be checked. Then this bug wouldn't happen, but I think this is still a pretty bas coding practice.

Any explanation would be greatly appreciated.

Thanks!
-- Zvonimir
Comment 1 Alan 2008-09-23 03:21:55 UTC
Grabbing to fix
Comment 2 Alan 2008-10-02 06:22:27 UTC
Patch Queued
Comment 3 Alan 2008-10-16 06:24:46 UTC
Merged into git tree for 2.6.28