staging: rtlwifi: rtl8822b: fix a missing check of alloc_skb
authorKangjie Lu <kjlu@umn.edu>
Sat, 22 Dec 2018 22:58:06 +0000 (16:58 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Jan 2019 15:08:28 +0000 (16:08 +0100)
__netdev_alloc_skb() return NULl when it fails. skb_put() further uses
it even when the allocation fails, leading to NULL pointer dereference.
The fix inserts a check for the return value of __netdev_alloc_skb().

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtlwifi/rtl8822be/fw.c

index a403966148143cd052aff46a97be47e4c7c84436..f061dd1382aa102e53ac532844c8e2c9959ae568 100644 (file)
@@ -486,6 +486,8 @@ bool rtl8822b_halmac_cb_write_data_h2c(struct rtl_priv *rtlpriv, u8 *buf,
 
        /* without GFP_DMA, pci_map_single() may not work */
        skb = __netdev_alloc_skb(NULL, size, GFP_ATOMIC | GFP_DMA);
+       if (!skb)
+               return false;
        memcpy((u8 *)skb_put(skb, size), buf, size);
 
        return _rtl8822be_send_bcn_or_cmd_packet(rtlpriv->hw, skb, H2C_QUEUE);