1f2507
From bb89624c1a62de701f87d7deb669e40586c920d2 Mon Sep 17 00:00:00 2001
1f2507
From: Ido Schimmel <idosch@nvidia.com>
1f2507
Date: Tue, 14 Sep 2021 14:27:34 +0300
1f2507
Subject: [PATCH 01/35] sff-8636: Fix parsing of Page 03h in IOCTL path
1f2507
1f2507
The offset of Page 03h compared to the base address of the Lower Memory
1f2507
is 512 bytes. However, all the offsets to the page start at address 128,
1f2507
which is the address that separates Lower and Upper memory (see Figure
1f2507
6-1 in SFF-8636). Therefore, reading these offsets compared to the start
1f2507
of Page 03h results in incorrect memory accesses as can be seen in the
1f2507
output below.
1f2507
1f2507
Instead, pass Page 03h with the correct offset.
1f2507
1f2507
This is a temporary solution until SFF-8636 is refactored to use a
1f2507
memory map for parsing.
1f2507
1f2507
Before patch:
1f2507
1f2507
 # ethtool -m swp13
1f2507
 ...
1f2507
 Laser bias current high alarm threshold   : 16.448 mA
1f2507
 Laser bias current low alarm threshold    : 16.500 mA
1f2507
 Laser bias current high warning threshold : 16.480 mA
1f2507
 Laser bias current low warning threshold  : 61.538 mA
1f2507
 Laser output power high alarm threshold   : 1.2576 mW / 1.00 dBm
1f2507
 Laser output power low alarm threshold    : 1.0321 mW / 0.14 dBm
1f2507
 Laser output power high warning threshold : 2.1318 mW / 3.29 dBm
1f2507
 Laser output power low warning threshold  : 2.0530 mW / 3.12 dBm
1f2507
 Module temperature high alarm threshold   : 0.00 degrees C / 32.00 degrees F
1f2507
 Module temperature low alarm threshold    : 0.00 degrees C / 32.00 degrees F
1f2507
 Module temperature high warning threshold : 0.00 degrees C / 32.00 degrees F
1f2507
 Module temperature low warning threshold  : 0.00 degrees C / 32.00 degrees F
1f2507
 Module voltage high alarm threshold       : 0.2377 V
1f2507
 Module voltage low alarm threshold        : 2.5701 V
1f2507
 Module voltage high warning threshold     : 2.8276 V
1f2507
 Module voltage low warning threshold      : 2.6982 V
1f2507
 Laser rx power high alarm threshold       : 0.8224 mW / -0.85 dBm
1f2507
 Laser rx power low alarm threshold        : 0.8224 mW / -0.85 dBm
1f2507
 Laser rx power high warning threshold     : 0.8224 mW / -0.85 dBm
1f2507
 Laser rx power low warning threshold      : 0.8224 mW / -0.85 dBm
1f2507
1f2507
After patch:
1f2507
1f2507
 # ethtool -m swp13
1f2507
 ...
1f2507
 Laser bias current high alarm threshold   : 8.500 mA
1f2507
 Laser bias current low alarm threshold    : 5.492 mA
1f2507
 Laser bias current high warning threshold : 8.000 mA
1f2507
 Laser bias current low warning threshold  : 6.000 mA
1f2507
 Laser output power high alarm threshold   : 3.4673 mW / 5.40 dBm
1f2507
 Laser output power low alarm threshold    : 0.0724 mW / -11.40 dBm
1f2507
 Laser output power high warning threshold : 1.7378 mW / 2.40 dBm
1f2507
 Laser output power low warning threshold  : 0.1445 mW / -8.40 dBm
1f2507
 Module temperature high alarm threshold   : 80.00 degrees C / 176.00 degrees F
1f2507
 Module temperature low alarm threshold    : -10.00 degrees C / 14.00 degrees F
1f2507
 Module temperature high warning threshold : 70.00 degrees C / 158.00 degrees F
1f2507
 Module temperature low warning threshold  : 0.00 degrees C / 32.00 degrees F
1f2507
 Module voltage high alarm threshold       : 3.5000 V
1f2507
 Module voltage low alarm threshold        : 3.1000 V
1f2507
 Module voltage high warning threshold     : 3.4650 V
1f2507
 Module voltage low warning threshold      : 3.1350 V
1f2507
 Laser rx power high alarm threshold       : 3.4673 mW / 5.40 dBm
1f2507
 Laser rx power low alarm threshold        : 0.0467 mW / -13.31 dBm
1f2507
 Laser rx power high warning threshold     : 1.7378 mW / 2.40 dBm
1f2507
 Laser rx power low warning threshold      : 0.0933 mW / -10.30 dBm
1f2507
1f2507
The following AddressSanitizer report is fixed:
1f2507
1f2507
==44670==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x617000000320 at pc 0x00000047ad93 bp 0x7ffcb4dc0070 sp 0x7ffcb4dc0068
1f2507
READ of size 1 at 0x617000000320 thread T0
1f2507
    #0 0x47ad92 in sff8636_dom_parse qsfp.c:683
1f2507
    #1 0x47c5d6 in sff8636_show_dom qsfp.c:771
1f2507
    #2 0x47d21f in sff8636_show_all qsfp.c:870
1f2507
    #3 0x42130b in do_getmodule ethtool.c:4908
1f2507
    #4 0x42a38a in main ethtool.c:6383
1f2507
    #5 0x7f500bf421e1 in __libc_start_main (/lib64/libc.so.6+0x281e1)
1f2507
    #6 0x40258d in _start (ethtool+0x40258d)
1f2507
1f2507
0x617000000320 is located 16 bytes to the right of 656-byte region [0x617000000080,0x617000000310)
1f2507
allocated by thread T0 here:
1f2507
    #0 0x7f500c2d6527 in __interceptor_calloc (/lib64/libasan.so.6+0xab527)
1f2507
    #1 0x420d8c in do_getmodule ethtool.c:4859
1f2507
    #2 0x42a38a in main ethtool.c:6383
1f2507
    #3 0x7f500bf421e1 in __libc_start_main (/lib64/libc.so.6+0x281e1)
1f2507
1f2507
SUMMARY: AddressSanitizer: heap-buffer-overflow qsfp.c:683 in sff8636_dom_parse
1f2507
1f2507
Fixes: fc47fdb7c364 ("ethtool: Refactor human-readable module EEPROM output for new API")
1f2507
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
1f2507
---
1f2507
 qsfp.c | 2 +-
1f2507
 1 file changed, 1 insertion(+), 1 deletion(-)
1f2507
1f2507
diff --git a/qsfp.c b/qsfp.c
1f2507
index 644fe148a5aa..e84226bc1554 100644
1f2507
--- a/qsfp.c
1f2507
+++ b/qsfp.c
1f2507
@@ -867,7 +867,7 @@ void sff8636_show_all(const __u8 *id, __u32 eeprom_len)
1f2507
 		(id[SFF8636_ID_OFFSET] == SFF8024_ID_QSFP_PLUS) ||
1f2507
 		(id[SFF8636_ID_OFFSET] == SFF8024_ID_QSFP28)) {
1f2507
 		sff6836_show_page_zero(id);
1f2507
-		sff8636_show_dom(id, id + SFF8636_PAGE03H_OFFSET, eeprom_len);
1f2507
+		sff8636_show_dom(id, id + 3 * 0x80, eeprom_len);
1f2507
 	}
1f2507
 }
1f2507
 
1f2507
-- 
1f2507
2.35.1
1f2507