All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: qla2xxx: Format SFP EEPROM vendor strings with %.*s
Date: Thu, 19 Nov 2026 17:12:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-223648@kernel.org> (raw)
In-Reply-To: <20261119170511.1515433-1-irogers@google.com>

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 <irogers@google.com>

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().

> diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
> index ccb039d97353b..77504cfc07411 100644
> --- a/drivers/scsi/qla2xxx/qla_init.c
> +++ b/drivers/scsi/qla2xxx/qla_init.c
> @@ -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);

[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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119170511.1515433-1-irogers@google.com?part=1

      reply	other threads:[~2026-11-19 17:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 17:05 [PATCH] scsi: qla2xxx: Format SFP EEPROM vendor strings with %.*s Ian Rogers
2026-11-19 17:12 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-223648@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.