mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Junrui Luo <moonafterrain@outlook.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" <martin.petersen@oracle.com>,
	 James Smart <james.smart@emulex.com>,
	 James Bottomley <James.Bottomley@suse.de>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Yuhao Jiang <danisjiang@gmail.com>,
	stable@vger.kernel.org,  Junrui Luo <moonafterrain@outlook.com>
Subject: [PATCH] scsi: lpfc: fix heap overflow in lpfc_bsg_diag_loopback_run()
Date: Wed, 22 Apr 2026 17:18:02 +0800	[thread overview]
Message-ID: <SYBPR01MB7881DCD912ADB83C9D290F7AAF2D2@SYBPR01MB7881.ausprd01.prod.outlook.com> (raw)

lpfc_bsg_diag_loopback_run() allocates dataout as a staging buffer
before copying loopback test data into DMA segments. When the
user-supplied payload size exceeds 64KB, the allocation is capped at
64KB while sg_copy_to_buffer() and the subsequent memcpy loop operate
on the full payload (up to 80 * 4096 bytes).

This leads to a heap buffer overflow with user-controlled data.

Fix by allocating full_size in the large-size path, consistent with the
small-size path and with diag_cmd_data_alloc().

Fixes: 3b5dd52aaffd ("[SCSI] lpfc 8.3.8: (BSG4) Add new vendor specific BSG Commands")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
 drivers/scsi/lpfc/lpfc_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 7406dfa60016..83fef256f324 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -3111,7 +3111,7 @@ lpfc_bsg_diag_loopback_run(struct bsg_job *job)
 		if (size <= (64 * 1024))
 			total_mem = full_size;
 		else
-			total_mem = 64 * 1024;
+			total_mem = full_size;
 	} else
 		/* Allocate memory for ioctl data */
 		total_mem = BUF_SZ_4K;

---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260422-fixes-4b4edb0b7e88

Best regards,
-- 
Junrui Luo <moonafterrain@outlook.com>


             reply	other threads:[~2026-04-22  9:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22  9:18 Junrui Luo [this message]
2026-04-22 13:28 ` James Bottomley
2026-04-23  7:45   ` Junrui Luo

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=SYBPR01MB7881DCD912ADB83C9D290F7AAF2D2@SYBPR01MB7881.ausprd01.prod.outlook.com \
    --to=moonafterrain@outlook.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=James.Bottomley@suse.de \
    --cc=danisjiang@gmail.com \
    --cc=james.smart@emulex.com \
    --cc=justin.tee@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=paul.ely@broadcom.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®