scsi: qla2xxx: Format SFP EEPROM vendor strings with %.*s
Subsystems (2)
PATCH 1/1 scsi: qla2xxx: Format SFP EEPROM vendor strings with %.*s
In qla2xxx_print_sfp_info(), the verbose logging path passes the 16-byte SFF-8472 transceiver EEPROM fields a0->vendor_name and a0->vendor_pn directly as the format string argument to snprintf(). Per SFF-8472, these ASCII fields are space-padded rather than NUL-terminated, and their bytes originate from pluggable SFP optics over I2C; any '%' byte in EEPROM data or a corrupted I2C read is interpreted as a printf format specifier with no variadic arguments supplied.
Format a0->vendor_name and a0->vendor_pn directly in ql_dbg() using "%.*s" bounded by sizeof(), matching the non-verbose ql_dbg() call immediately above in the same function.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wformat-security enabled; fix and changelog drafted with an AI coding assistant. Build-tested under LLVM=1 W=1 and -Wformat-security; not tested on QLogic Fibre Channel hardware.
--- drivers/scsi/qla2xxx/qla_init.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/scsi/qla2xxx/qla_init.c +4 -6
@@ -4126,15 +4126,13 @@ static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)if (!(ql2xextended_error_logging & ql_dbg_verbose))return ; -memset (str,0 ,STR_LEN ); -snprintf (str,SFF_VEN_NAME_LEN +1 , a0->vendor_name);ql_dbg (ql_dbg_init, vha,0x015a , -"SFP MFG Name: %s\n" , str); +"SFP MFG Name: %.*s\n" , + (int )sizeof (a0->vendor_name), a0->vendor_name); -memset (str,0 ,STR_LEN ); -snprintf (str,SFF_PART_NAME_LEN +1 , a0->vendor_pn);ql_dbg (ql_dbg_init, vha,0x015c , -"SFP Part Name: %s\n" , str); +"SFP Part Name: %.*s\n" , + (int )sizeof (a0->vendor_pn), a0->vendor_pn);/* media */ memset (str,0 ,STR_LEN );
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] scsi: qla2xxx: stack buffer…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] scsi: qla2xxx: stack buffer overflow in qla2xxx_print_sfp_info() [1]
--
commit fc46a24e989dac1a4fa69f172af87de567da0070
Author: Ian Rogers <[email protected]>
scsi: qla2xxx: Format SFP EEPROM vendor strings with %.*s
This commit replaces snprintf() calls that passed SFP EEPROM vendor name and part number fields directly as format strings in qla2xxx_print_sfp_info() with "%.*s" formatting in ql_dbg().
Quoted 14 lines
drivers/scsi/qla2xxx/qla_init.c +2
-3@@ -4126,15 +4126,13 @@ static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)if (!(ql2xextended_error_logging & ql_dbg_verbose))return ; -memset (str,0 ,STR_LEN ); -snprintf (str,SFF_VEN_NAME_LEN +1 , a0->vendor_name);ql_dbg (ql_dbg_init, vha,0x015a , -"SFP MFG Name: %s\n" , str); +"SFP MFG Name: %.*s\n" , + (int )sizeof (a0->vendor_name), a0->vendor_name);
drivers/scsi/qla2xxx/qla_init.c static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) · line 4138
Quoted 10 lines
drivers/scsi/qla2xxx/qla_init.c +2
-3-memset (str,0 ,STR_LEN ); -snprintf (str,SFF_PART_NAME_LEN +1 , a0->vendor_pn);ql_dbg (ql_dbg_init, vha,0x015c , -"SFP Part Name: %s\n" , str); +"SFP Part Name: %.*s\n" , + (int )sizeof (a0->vendor_pn), a0->vendor_pn);/* media */ memset (str,0 ,STR_LEN );
[Severity: Critical]
This problem wasn't introduced by this patch, but can the media block immediately below overflow str[] [1]?
drivers/scsi/qla2xxx/qla_init.c:
#define PRINT_FIELD(_field, _flag, _str) { \
if (a0->_field & _flag) {\
if (p) {\
strcat(ptr, "|");\
ptr++;\
leftover--;\
} \
len = snprintf(ptr, leftover, "%s", _str); \
p = 1;\
leftover -= len;\
ptr += len; \
} \
}drivers/scsi/qla2xxx/qla_init.c:qla2xxx_print_sfp_info() {
...
/* media */
memset(str, 0, STR_LEN);
ptr = str;
leftover = STR_LEN;
p = len = 0;
PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
...
}str[] is 64 bytes (STR_LEN), while the seven media strings and their "|" separators total 83 characters plus the NUL terminator. Because snprintf() returns the length that would have been written rather than the truncated length, when all seven FC_MED_* bits are set in a0->fc_med_cc9, the sixth PRINT_FIELD() drives leftover negative and advances ptr past the end of str[], and the seventh writes out-of-bounds on the stack via strcat() and triggers WARN_ON_ONCE() in vsnprintf().
[1] https://sashiko.dev/#/bug/linux-684c2982-ba32-44da-bc9c-910dc2c357ef
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1