* [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()
@ 2026-11-19 17:05 Ian Rogers
2026-11-21 1:56 ` Martin K. Petersen
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2026-11-19 17:05 UTC (permalink / raw)
To: Justin Tee, Paul Ely, James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, llvm, Elkin Cruz, Ian Rogers
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@google.com>
---
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]);
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()
2026-11-19 17:05 [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object() Ian Rogers
@ 2026-11-21 1:56 ` Martin K. Petersen
0 siblings, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2026-11-21 1:56 UTC (permalink / raw)
To: Ian Rogers
Cc: Justin Tee, Paul Ely, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, linux-kernel, llvm, Elkin Cruz
Ian,
> 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:
Applied to 7.5/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()
@ 2026-11-20 20:49 Paul Ely
0 siblings, 0 replies; 3+ messages in thread
From: Paul Ely @ 2026-11-20 20:49 UTC (permalink / raw)
To: irogers, linux-scsi, linux-kernel, Nigel Kirkland, mkp,
James E.J. Bottomley
[-- Attachment #1: Type: text/plain, Size: 3392 bytes --]
From: Ian Rogers <irogers@google.com>
To: Justin Tee <justin.tee@broadcom.com>,
Paul Ely <paul.ely@broadcom.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Elkin Cruz <elkin@google.com>,
Ian Rogers <irogers@google.com>
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@google.com> (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@google.com>
---
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@broadcom.com>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5453 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 1:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:05 [PATCH] scsi: lpfc: Fix format string and OOB copy in lpfc_read_object() Ian Rogers
2026-11-21 1:56 ` Martin K. Petersen
2026-11-20 20:49 Paul Ely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®