Skip to content

Commit fc6f716

Browse files
michichkuba-moo
authored andcommitted
i40e: prevent crash on probe if hw registers have invalid values
The hardware provides the indexes of the first and the last available queue and VF. From the indexes, the driver calculates the numbers of queues and VFs. In theory, a faulty device might say the last index is smaller than the first index. In that case, the driver's calculation would underflow, it would attempt to write to non-existent registers outside of the ioremapped range and crash. I ran into this not by having a faulty device, but by an operator error. I accidentally ran a QE test meant for i40e devices on an ice device. The test used 'echo i40e > /sys/...ice PCI device.../driver_override', bound the driver to the device and crashed in one of the wr32 calls in i40e_clear_hw. Add checks to prevent underflows in the calculations of num_queues and num_vfs. With this fix, the wrong device probing reports errors and returns a failure without crashing. Fixes: 838d41d ("i40e: clear all queues and interrupts") Signed-off-by: Michal Schmidt <mschmidt@redhat.com> Reviewed-by: Simon Horman <horms@kernel.org> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel) Link: https://lore.kernel.org/r/20231011233334.336092-2-jacob.e.keller@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f50ee3a commit fc6f716

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/net/ethernet/intel/i40e/i40e_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ void i40e_clear_hw(struct i40e_hw *hw)
10821082
I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
10831083
j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
10841084
I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1085-
if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1085+
if (val & I40E_PFLAN_QALLOC_VALID_MASK && j >= base_queue)
10861086
num_queues = (j - base_queue) + 1;
10871087
else
10881088
num_queues = 0;
@@ -1092,7 +1092,7 @@ void i40e_clear_hw(struct i40e_hw *hw)
10921092
I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
10931093
j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
10941094
I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1095-
if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1095+
if (val & I40E_PF_VT_PFALLOC_VALID_MASK && j >= i)
10961096
num_vfs = (j - i) + 1;
10971097
else
10981098
num_vfs = 0;

0 commit comments

Comments
 (0)