Skip to contentSkip to conversation

scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()

PATCH Applied Ian Rogers 2 participants 2 messages Nov 19 – Nov 21

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 scsi: lpfc: Fix format string and OOB copy in lpfc_read_object()

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")
---
 drivers/scsi/lpfc/lpfc_sli.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/scsi/lpfc/lpfc_sli.c +5 -3
index 9173263c87f9..26c9f5721340 100644
@@ -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]);
 
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
maintainer Applied
#1 lore raw

Ian,

Quoted 4 lines

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!

Signature · 1 line
Martin K. Petersen