[PATCH 1/2] scsi: esas2r: bound default_nvram reads to the requested count

From: Junyoung Jang

Date: Thu Dec 03 2026 - 08:55:41 EST


The default_nvram sysfs binary attribute is readable by all users.
For a one-byte read, kernfs requests a one-byte heap allocation and
passes count=1 to read_default_nvram(). The callback ignores count
and off. esas2r_nvram_get_defaults() writes the entire 256-byte NVRAM
structure into that buffer, corrupting memory beyond the allocation.

Reproduced in QEMU without physical ATTO hardware by registering
bin_attr_default_nvram on a dummy SCSI host. A 1-byte read as UID 1000
triggered a 256-byte KASAN slab-out-of-bounds write in
esas2r_nvram_get_defaults().

Build the defaults in a zero-initialized local structure and use
memory_read_from_buffer() to return only the requested bytes at the
requested offset.

An in-house LLM-based agent assisted with discovery and patch
preparation.

Fixes: 26780d9e12ed ("[SCSI] esas2r: ATTO Technology ExpressSAS 6G SAS/SATA RAID Adapter Driver")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>
---
drivers/scsi/esas2r/esas2r_main.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index ada278c24c51..ad5de07d1e14 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -41,6 +41,8 @@
* USA.
*/

+#include <linux/string.h>
+
#include "esas2r.h"

MODULE_DESCRIPTION(ESAS2R_DRVR_NAME ": " ESAS2R_LONGNAME " driver");
@@ -162,10 +164,11 @@ static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
char *buf, loff_t off, size_t count)
{
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
+ struct esas2r_sas_nvram nvram = {};

- esas2r_nvram_get_defaults(a, (struct esas2r_sas_nvram *)buf);
+ esas2r_nvram_get_defaults(a, &nvram);

- return sizeof(struct esas2r_sas_nvram);
+ return memory_read_from_buffer(buf, count, &off, &nvram, sizeof(nvram));
}

static ssize_t read_hw(struct file *file, struct kobject *kobj,
--
2.43.0