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