iavf: fix dereference of null rx_buffer pointer
authorColin Ian King <colin.king@canonical.com>
Wed, 19 Jun 2019 14:30:44 +0000 (15:30 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jul 2019 05:28:34 +0000 (07:28 +0200)
[ Upstream commit 9fe06a51287b2d41baef7ece94df34b5abf19b90 ]

A recent commit efa14c3985828d ("iavf: allow null RX descriptors") added
a null pointer sanity check on rx_buffer, however, rx_buffer is being
dereferenced before that check, which implies a null pointer dereference
bug can potentially occur.  Fix this by only dereferencing rx_buffer
until after the null pointer check.

Addresses-Coverity: ("Dereference before null check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/intel/i40evf/i40e_txrx.c

index 7368b0dc3af8ffc70c6ce29d1fc2224fc33af532..4afdabbe95e8f90a4729ce3c02b940e89d4c5feb 100644 (file)
@@ -1117,7 +1117,7 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
                                          struct i40e_rx_buffer *rx_buffer,
                                          unsigned int size)
 {
-       void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
+       void *va;
 #if (PAGE_SIZE < 8192)
        unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2;
 #else
@@ -1127,6 +1127,7 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
        struct sk_buff *skb;
 
        /* prefetch first cache line of first page */
+       va = page_address(rx_buffer->page) + rx_buffer->page_offset;
        prefetch(va);
 #if L1_CACHE_BYTES < 128
        prefetch(va + L1_CACHE_BYTES);
@@ -1181,7 +1182,7 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,
                                      struct i40e_rx_buffer *rx_buffer,
                                      unsigned int size)
 {
-       void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
+       void *va;
 #if (PAGE_SIZE < 8192)
        unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2;
 #else
@@ -1191,6 +1192,7 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,
        struct sk_buff *skb;
 
        /* prefetch first cache line of first page */
+       va = page_address(rx_buffer->page) + rx_buffer->page_offset;
        prefetch(va);
 #if L1_CACHE_BYTES < 128
        prefetch(va + L1_CACHE_BYTES);