Blame SOURCES/0001-sff-8636-Fix-parsing-of-Page-03h-in-IOCTL-path.patch

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