Staging: bcm: Add size maximum size restrictions for IOCTL_IDLE_REQ
authorKevin McKinney <klmckinney1@gmail.com>
Sun, 18 Sep 2011 22:34:47 +0000 (18:34 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 19 Sep 2011 17:46:17 +0000 (10:46 -0700)
In the first alteration, the MAX_CNTL_PKT_SIZE is the
maximum size of the control packet in ->Adapter->txctlpacket[]
which is defined in InitAdapter(). This caps the size of
kmalloc memory allocation. In the second change, this max
cap fixes a potential memory corruption bug when subsequent
memset and memcpy calls are invoked.

Signed-off-by: Kevin McKinney <klmckinney1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/bcm/Bcmchar.c
drivers/staging/bcm/Misc.c

index 1905a83b33856ba37b534c4e4f6c0ad80b8b7ff2..4c433538397780f66a2343dea9afa0918987177b 100644 (file)
@@ -690,6 +690,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
                if (IoBuffer.InputLength < sizeof(struct link_request))
                        return -EINVAL;
 
+               if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
+                       return -EINVAL;
+
                pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
                if (!pvBuffer)
                        return -ENOMEM;
index c5b3a3666bc7973436e0137342c05d20523b457a..9da94086987f22c07b6b80cc65c7b2655e066407 100644 (file)
@@ -421,6 +421,10 @@ INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
                                pLeader->PLength = pktlen;
                        }
                }
+
+               if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
+                       return -EINVAL;
+
                memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
                BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
                *(PLEADER)ctrl_buff=*pLeader;