From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: martin.petersen@oracle.com
Cc: Pengpeng Hou <pengpeng@iscas.ac.cn>,
James.Bottomley@HansenPartnership.com, aradford@gmail.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] scsi: 3w-9xxx: bound firmware error strings
Date: Wed, 15 Jul 2026 16:46:51 +0800 [thread overview]
Message-ID: <20260715084652.47248-2-pengpeng@iscas.ac.cn> (raw)
In-Reply-To: <20260715084652.47248-1-pengpeng@iscas.ac.cn>
The controller response header stores the description and optional firmware
error string in its fixed 98-byte err_specific_desc field.
twa_aen_queue_event() used strlen() to find the second string before
forcing the final byte to NUL, while twa_fill_sense() used the same
unbounded layout directly.
If a response does not contain a terminator, strlen() can scan past
the field.
If the first string reaches the last field byte, adding one also forms a
pointer past the array.
Terminate the field before parsing it and use a shared helper that treats a
full first string as having no optional second string. This keeps both AEN
and sense reporting paths within the response field.
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/scsi/3w-9xxx.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 9b93a2440af8..b2462ee43008 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -149,6 +149,24 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id);
static char *twa_string_lookup(twa_message_type *table, unsigned int aen_code);
+/*
+ * The firmware field contains two NUL-terminated strings in one fixed-size
+ * array. Make the last byte a terminator before finding the optional second
+ * string, and never form a pointer one byte past the array.
+ */
+static const char *twa_error_string(TW_Command_Apache_Header *header)
+{
+ size_t description_len;
+
+ header->err_specific_desc[sizeof(header->err_specific_desc) - 1] = '\0';
+ description_len = strnlen(header->err_specific_desc,
+ sizeof(header->err_specific_desc));
+ if (description_len == sizeof(header->err_specific_desc) - 1)
+ return "";
+
+ return &header->err_specific_desc[description_len + 1];
+}
+
/* Functions */
/* Show some statistics about the card */
@@ -376,7 +394,7 @@ static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_H
TW_Event *event;
unsigned short aen;
char host[16];
- char *error_str;
+ const char *error_str;
tw_dev->aen_count++;
@@ -404,10 +422,9 @@ static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_H
tw_dev->error_sequence_id++;
/* Check for embedded error string */
- error_str = &(header->err_specific_desc[strlen(header->err_specific_desc)+1]);
-
- header->err_specific_desc[sizeof(header->err_specific_desc) - 1] = '\0';
- event->parameter_len = strlen(header->err_specific_desc);
+ error_str = twa_error_string(header);
+ event->parameter_len = strnlen(header->err_specific_desc,
+ sizeof(header->err_specific_desc));
memcpy(event->parameter_data, header->err_specific_desc, event->parameter_len + (error_str[0] == '\0' ? 0 : (1 + strlen(error_str))));
if (event->severity != TW_AEN_SEVERITY_DEBUG)
printk(KERN_WARNING "3w-9xxx:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n",
@@ -992,12 +1009,12 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
TW_Command_Full *full_command_packet;
unsigned short error;
int retval = 1;
- char *error_str;
+ const char *error_str;
full_command_packet = tw_dev->command_packet_virt[request_id];
/* Check for embedded error string */
- error_str = &(full_command_packet->header.err_specific_desc[strlen(full_command_packet->header.err_specific_desc) + 1]);
+ error_str = twa_error_string(&full_command_packet->header);
/* Don't print error for Logical unit not supported during rollcall */
error = le16_to_cpu(full_command_packet->header.status_block.error);
--
2.43.0
next prev parent reply other threads:[~2026-07-15 8:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 8:46 [PATCH v2 0/2] scsi: 3ware: " Pengpeng Hou
2026-07-15 8:46 ` Pengpeng Hou [this message]
2026-07-15 8:46 ` [PATCH v2 2/2] scsi: 3w-sas: " Pengpeng Hou
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=20260715084652.47248-2-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=James.Bottomley@HansenPartnership.com \
--cc=aradford@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox