summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorStefan Fritsch <sf@cvs.openbsd.org>2019-09-05 08:41:21 +0000
committerStefan Fritsch <sf@cvs.openbsd.org>2019-09-05 08:41:21 +0000
commitbade57a60d0669bbbe8226777ecd5bc3924ae378 (patch)
tree52a2fa671c1c1391ee0551058160300dc0614ed4 /sys/dev
parentb85107df67ac2711bfee1dd109441d331188469b (diff)
em: Fix potential endless loop
If the NIC is in some error state (seen on a i219LM when em_read_phy_reg_ex() returns at "MDI Error"), it can happen that we loop endlessly because the loop variable is modified again somewhere down in the call stack. Use a separate variable to make the attach fail with "Hardware Initialization Failed" instead of hanging. yes deraadt@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_em_hw.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/dev/pci/if_em_hw.c b/sys/dev/pci/if_em_hw.c
index 77adfe5707b..8f2bdd63ab0 100644
--- a/sys/dev/pci/if_em_hw.c
+++ b/sys/dev/pci/if_em_hw.c
@@ -31,7 +31,7 @@
*******************************************************************************/
-/* $OpenBSD: if_em_hw.c,v 1.102 2018/04/29 08:47:10 sf Exp $ */
+/* $OpenBSD: if_em_hw.c,v 1.103 2019/09/05 08:41:20 sf Exp $ */
/*
* if_em_hw.c Shared functions for accessing and configuring the MAC
*/
@@ -5810,7 +5810,12 @@ em_detect_gig_phy(struct em_hw *hw)
}
/* Read the PHY ID Registers to identify which PHY is onboard. */
- for (hw->phy_addr = 1; (hw->phy_addr < 4); hw->phy_addr++) {
+ for (int i = 1; i < 4; i++) {
+ /*
+ * hw->phy_addr may be modified down in the call stack,
+ * we can't use it as loop variable.
+ */
+ hw->phy_addr = i;
ret_val = em_match_gig_phy(hw);
if (ret_val == E1000_SUCCESS)
return E1000_SUCCESS;