Re: [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()
From: Paul Ely
Date: Fri Nov 20 2026 - 15:50:53 EST
From: Ian Rogers <irogers@xxxxxxxxxx>
To: Justin Tee <justin.tee@xxxxxxxxxxxx>,
Paul Ely <paul.ely@xxxxxxxxxxxx>,
"James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>,
"Martin K. Petersen" <mkp@xxxxxxxxxx>
Cc: linux-scsi@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx,
llvm@xxxxxxxxxxxxxxx, Elkin Cruz <elkin@xxxxxxxxxx>,
Ian Rogers <irogers@xxxxxxxxxx>
Subject: [PATCH] scsi: lpfc: Fix format string and OOB copy in
lpfc_read_object()
Date: Thu, 19 Nov 2026 09:05:00 -0800 [thread overview]
Message-ID: <20261119170500.1514537-1-irogers@xxxxxxxxxx> (raw)
In lpfc_read_object(), rd_object_name is a 26-element u32 array (104
bytes, LPFC_OBJ_NAME_SZ) populated from rdobject via scnprintf() without a
"%s" format string, and then copied to the SLI-4 mailbox request with:
for (j = 0; j < strlen(rdobject); j++)
read_object->u.request.rd_object_name[j] =
cpu_to_le32(rd_object_name[j]);
Because the loop bound uses strlen(rdobject) (byte count, unbounded) to
index 32-bit dword arrays of length 26, any object path of 27 bytes or
longer reads past the end of rd_object_name on the stack and overwrites
rd_object_cnt, rd_object_hbuf[], and adjacent mailbox memory. Passing
rdobject directly as the format string also evaluates any '%' characters
as printf specifiers.
Format rdobject with "%s", capture the bounded byte length returned by
scnprintf(), and iterate over DIV_ROUND_UP(len, sizeof(u32)) dwords.
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. Verified with an ASan/UBSan C reproducer for short, '%'-bearing,
and >104-byte object names, and build-tested with LLVM=1 W=1 and
-Wformat-security; not tested on Emulex Fibre Channel hardware.
Fixes: 72df8a452883 ("scsi: lpfc: Add support for cm enablement buffer")
Fixes: 59936430e6a6 ("scsi: lpfc: Fix CPU to/from endian warnings
introduced by ELS processing")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
drivers/scsi/lpfc/lpfc_sli.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 9173263c87f9..26c9f5721340 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -22259,11 +22259,12 @@ lpfc_read_object(struct lpfc_hba *phba, char
*rdobject, uint32_t *datap,
{
struct lpfc_mbx_read_object *read_object;
LPFC_MBOXQ_t *mbox;
- int rc, length, eof, j, byte_cnt = 0;
+ int rc, length, eof, byte_cnt = 0;
uint32_t shdr_status, shdr_add_status;
union lpfc_sli4_cfg_shdr *shdr;
struct lpfc_dmabuf *pcmd;
u32 rd_object_name[LPFC_MBX_OBJECT_NAME_LEN_DW] = {0};
+ size_t len, j;
mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
if (!mbox)
@@ -22283,8 +22284,9 @@ lpfc_read_object(struct lpfc_hba *phba, char
*rdobject, uint32_t *datap,
memset((void *)read_object->u.request.rd_object_name, 0,
LPFC_OBJ_NAME_SZ);
- scnprintf((char *)rd_object_name, sizeof(rd_object_name), rdobject);
- for (j = 0; j < strlen(rdobject); j++)
+ len = scnprintf((char *)rd_object_name, sizeof(rd_object_name), "%s",
+ rdobject);
+ for (j = 0; j < DIV_ROUND_UP(len, sizeof(u32)); j++)
read_object->u.request.rd_object_name[j] =
cpu_to_le32(rd_object_name[j]);
Tested in the lab and ran it through a different AI scan. Both clean.
Thanks!
Reviewed-by: Paul Ely <pely@xxxxxxxxxxxx>
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature