* [PATCH 1/2] scsi: esas2r: bound default_nvram reads to the requested count
2026-12-03 13:55 [PATCH 0/2] scsi: esas2r: bound binary sysfs reads Junyoung Jang
@ 2026-12-03 13:55 ` Junyoung Jang
2026-12-03 13:55 ` [PATCH 2/2] scsi: esas2r: bound owner-only binary sysfs reads Junyoung Jang
1 sibling, 0 replies; 3+ messages in thread
From: Junyoung Jang @ 2026-12-03 13:55 UTC (permalink / raw)
To: Bradley Grove
Cc: Junyoung Jang, James E.J. Bottomley, Martin K. Petersen,
Gwanhyun Lee, linux-scsi, linux-kernel
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@vger.kernel.org
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 2/2] scsi: esas2r: bound owner-only binary sysfs reads
2026-12-03 13:55 [PATCH 0/2] scsi: esas2r: bound binary sysfs reads Junyoung Jang
2026-12-03 13:55 ` [PATCH 1/2] scsi: esas2r: bound default_nvram reads to the requested count Junyoung Jang
@ 2026-12-03 13:55 ` Junyoung Jang
1 sibling, 0 replies; 3+ messages in thread
From: Junyoung Jang @ 2026-12-03 13:55 UTC (permalink / raw)
To: Bradley Grove
Cc: Junyoung Jang, James E.J. Bottomley, Martin K. Petersen,
Gwanhyun Lee, linux-scsi, linux-kernel
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@vger.kernel.org
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread