mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: esas2r: Enforce minimum header length bound in esas2r_write_fw()
@ 2026-11-25 22:19 Elkin Cruz
  0 siblings, 0 replies; only message in thread
From: Elkin Cruz @ 2026-11-25 22:19 UTC (permalink / raw)
  To: Bradley Grove, James E.J. Bottomley, Martin K. Petersen
  Cc: linux-scsi, Christian Brauner, linux-kernel, llvm, irogers,
	Elkin Cruz, stable

esas2r_write_fw() is reachable via EXPRESS_IOCTL_RW_FIRMWARE on
/proc/scsi/esas2r/ATTONode (created with mode 0444 and no capability
check).

In esas2r_write_fw(), the driver validates that the input buffer count is
at least min_size and caps header->length at 1 MiB, but does not ensure
that header->length is at least sizeof(struct esas2r_flash_img) on
FI_ACT_DOWN and FI_ACT_UP transfers, nor does it bound the header cache
memcpy() to min_size for FI_VERSION_0 headers.

If a caller supplies a non-zero header->length smaller than
sizeof(struct esas2r_flash_img) for FI_ACT_DOWN or FI_ACT_UP,
allocate_fw_buffers() allocates a DMA buffer smaller than
a->firmware.header, causing subsequent memcpy() and do_fm_api() calls in
esas2r_write_fw() and esas2r_read_fw() to read and write past the end of
a->firmware.data. Meanwhile, FI_ACT_UPSZ queries upload sizes directly on
a->firmware.header without allocating a->firmware.data, so header->length
may legitimately be zero for FI_ACT_UPSZ.

Require header->length >= sizeof(*header) for non-FI_ACT_UPSZ commands
and zero-pad a->firmware.header when copying min_size bytes from buf.

Fixes: 26780d9e12ed ("[SCSI] esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---

I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).

Thanks,
Elkin

 drivers/scsi/esas2r/esas2r_ioctl.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index 901c5d40cda8..4a4489a2485b 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -1708,7 +1708,9 @@ int esas2r_write_fw(struct esas2r_adapter *a, const char *buf, long off,
 		/* Make sure the size is reasonable. */
 		length = header->length;
 
-		if (length > 1024 * 1024) {
+		if (length > 1024 * 1024 ||
+		    (header->action != FI_ACT_UPSZ &&
+		     length < sizeof(*header))) {
 			esas2r_debug(
 				"esas2r_write_fw: hosed, length %d  fi_version %d",
 				length, header->fi_version);
@@ -1729,15 +1731,15 @@ int esas2r_write_fw(struct esas2r_adapter *a, const char *buf, long off,
 			 * Store the command, so there is context on subsequent
 			 * calls.
 			 */
-			memcpy(&a->firmware.header,
-			       buf,
-			       sizeof(*header));
+			memset(&a->firmware.header, 0,
+			       sizeof(a->firmware.header));
+			memcpy(&a->firmware.header, buf, min_size);
 		} else if (header->action == FI_ACT_UP
 			   ||  header->action == FI_ACT_UPSZ) {
 			/* Save the command, result will be picked up on read */
-			memcpy(&a->firmware.header,
-			       buf,
-			       sizeof(*header));
+			memset(&a->firmware.header, 0,
+			       sizeof(a->firmware.header));
+			memcpy(&a->firmware.header, buf, min_size);
 
 			a->firmware.state = FW_COMMAND_ST;
 
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25 22:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 22:19 [PATCH] scsi: esas2r: Enforce minimum header length bound in esas2r_write_fw() Elkin Cruz

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®