[PATCH 2/2] scsi: esas2r: bound owner-only binary sysfs reads

From: Junyoung Jang

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


The live_nvram and hw binary sysfs attributes have mode 0600. Their
read callbacks ignore count and copy a fixed amount into the kernfs
buffer. A short read allocates a smaller buffer, so either copy can
write past it when the callback succeeds.

Bound both copies by count. Because both attributes declare size 0 and
have always ignored off, keep ignoring off so write-then-read exchanges
on the same fd, such as hw commands, continue to work without a seek,
and leave read_hw()'s per-read HBA command execution unchanged.

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 | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index ad5de07d1e14..d462b2fde10e 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -133,7 +133,7 @@ static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
char *buf, loff_t off, size_t count)
{
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
- int length = min_t(size_t, sizeof(struct esas2r_sas_nvram), PAGE_SIZE);
+ size_t length = min(sizeof(*a->nvram), count);

memcpy(buf, a->nvram, length);
return length;
@@ -176,7 +176,7 @@ static ssize_t read_hw(struct file *file, struct kobject *kobj,
char *buf, loff_t off, size_t count)
{
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
- int length = min_t(size_t, sizeof(struct atto_ioctl), PAGE_SIZE);
+ size_t length = min_t(size_t, sizeof(struct atto_ioctl), PAGE_SIZE);

if (!a->local_atto_ioctl)
return -ENOMEM;
@@ -184,8 +184,8 @@ static ssize_t read_hw(struct file *file, struct kobject *kobj,
if (handle_hba_ioctl(a, a->local_atto_ioctl) != IOCTL_SUCCESS)
return -ENOMEM;

+ length = min(length, count);
memcpy(buf, a->local_atto_ioctl, length);
-
return length;
}

--
2.43.0