libertas_tf: prevent underflow in process_cmdrequest()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 14 Aug 2018 09:07:48 +0000 (12:07 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2018 19:08:30 +0000 (11:08 -0800)
[ Upstream commit 3348ef6a6a126706d6a73ed40c18d8033df72783 ]

If recvlength is less than MESSAGE_HEADER_LEN (4) we would end up
corrupting memory.

Fixes: c305a19a0d0a ("libertas_tf: usb specific functions")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/wireless/marvell/libertas_tf/if_usb.c

index e92fc50..789337e 100644 (file)
@@ -605,9 +605,10 @@ static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff,
 {
        unsigned long flags;
 
-       if (recvlength > LBS_CMD_BUFFER_SIZE) {
+       if (recvlength < MESSAGE_HEADER_LEN ||
+           recvlength > LBS_CMD_BUFFER_SIZE) {
                lbtf_deb_usbd(&cardp->udev->dev,
-                            "The receive buffer is too large\n");
+                            "The receive buffer is invalid: %d\n", recvlength);
                kfree_skb(skb);
                return;
        }