Skip to contentSkip to conversation

s390/pci: Fix leak of uninitialized kernel data in SCLP report

PATCH Applied Niklas Schnelle 4 participants 4 messages Aug 6 – Aug 23

Subsystems (2)
lore
Share & tools
lore

Niklas Schnelle

author maintainer
#0 lore raw

PATCH v2 1/1 s390/pci: Fix leak of uninitialized kernel data in SCLP report

While report_error_write() checks that the provided buffer is at least as large as the header struct, but not that it is large enough to contain the report with the length claimed by report->length. If user-space provides a short buffer, meaning a larger report->length than the actually written payload, up to around 4K of kernel data from past the kmalloc(len + 1) sized buffer allocated in kernfs_fop_write_iter() will leak into the SCLP report.

However, as the entity processing the SCLP is privileged and able to access at least the page including the report, this does not leak data that entity could not access but it is still an out of bounds read and a malformed error report that should be rejected.

Fixes 368704a65be8 ("s390/pci: add report_error attribute")

---
Changes in v2:
- Changed subsystem prefix to s390/pci
- Added Fixes tag and Cc stable
- Improved commit message
- Link to v1: https://lore.kernel.org/r/20260805-fix_pci_sclp_length_check-v1-1-d125cb415bc3@linux.ibm.com

---
 arch/s390/pci/pci_sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/pci/pci_sysfs.c +3 -0
index d98d97df792a..bbb76113a4d0 100644
@@ -153,6 +153,9 @@ static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
 	if (off || (count < sizeof(*report)))
 		return -EINVAL;
 
+	if (count < (report->length + sizeof(*report)))
+		return -EINVAL;
+
 	ret = sclp_pci_report(report, zdev->fh, zdev->fid);
 
 	return ret ? ret : count;

---
base-commit: 075b74841bd0065a3bda3440873c747938e69b68
change-id: 20260803-fix_pci_sclp_length_check-aa68495b1990

Best regards,

Signature · 1 line
Niklas Schnelle
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

While report_error_write() checks that the provided buffer is at least as large as the header struct, but not that it is large enough to contain the report with the length claimed by report->length. If user-space provides a short buffer, meaning a larger report->length than the actually written payload, up to around 4K of kernel data from past the kmalloc(len + 1) sized buffer allocated in kernfs_fop_write_iter() will leak into the SCLP report.

Quoted 8 lines

However, as the entity processing the SCLP is privileged and able to access at least the page including the report, this does not leak data that entity could not access but it is still an out of bounds read and a malformed error report that should be rejected.

Fixes 368704a65be8 ("s390/pci: add report_error attribute")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-fix_pci_sclp_length_check-v2-1-9ee9428e659f@linux.ibm.com?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Niklas Schnelle
Quoted 31 lines · Niklas Schnelle

While report_error_write() checks that the provided buffer is at least as large as the header struct, but not that it is large enough to contain the report with the length claimed by report->length. If user-space provides a short buffer, meaning a larger report->length than the actually written payload, up to around 4K of kernel data from past the kmalloc(len + 1) sized buffer allocated in kernfs_fop_write_iter() will leak into the SCLP report.

However, as the entity processing the SCLP is privileged and able to access at least the page including the report, this does not leak data that entity could not access but it is still an out of bounds read and a malformed error report that should be rejected.

Fixes 368704a65be8 ("s390/pci: add report_error attribute")

---
Changes in v2:
- Changed subsystem prefix to s390/pci
- Added Fixes tag and Cc stable
- Improved commit message
- Link to v1: https://lore.kernel.org/r/20260805-fix_pci_sclp_length_check-v1-1-d125cb415bc3@linux.ibm.com

---
 arch/s390/pci/pci_sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/pci/pci_sysfs.c +0 -0
index d98d97df792a..bbb76113a4d0 100644

arch/s390/pci/pci_sysfs.c static ssize_t report_error_write(struct file *filp, struct kobject *kobj, · line 161

Quoted 9 lines
arch/s390/pci/pci_sysfs.c +3 -0
@@ -153,6 +153,9 @@ static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
 	if (off || (count < sizeof(*report)))
 		return -EINVAL;
 
+	if (count < (report->length + sizeof(*report)))
+		return -EINVAL;
+
 	ret = sclp_pci_report(report, zdev->fh, zdev->fid);
 
 	return ret ? ret : count;

Looks good to me.

Signature · 4 lines
Best Regards, Benjamin Block        /        Linux on IBM Z Kernel Development
IBM Deutschland Research & Development GmbH    /   https://www.ibm.com/privacy
Vors. Aufs.-R.: Wolfgang Wendt         /        Geschäftsführung: David Faller
Sitz der Ges.: Ehningen     /     Registergericht: AmtsG Stuttgart, HRB 243294
maintainer Applied
#3 lore raw
In reply to Niklas Schnelle
Quoted 22 lines · Niklas Schnelle

While report_error_write() checks that the provided buffer is at least as large as the header struct, but not that it is large enough to contain the report with the length claimed by report->length. If user-space provides a short buffer, meaning a larger report->length than the actually written payload, up to around 4K of kernel data from past the kmalloc(len + 1) sized buffer allocated in kernfs_fop_write_iter() will leak into the SCLP report.

However, as the entity processing the SCLP is privileged and able to access at least the page including the report, this does not leak data that entity could not access but it is still an out of bounds read and a malformed error report that should be rejected.

Fixes 368704a65be8 ("s390/pci: add report_error attribute")

---
Changes in v2:
- Changed subsystem prefix to s390/pci
- Added Fixes tag and Cc stable
- Improved commit message
- Link to v1: https://lore.kernel.org/r/20260805-fix_pci_sclp_length_check-v1-1-d125cb415bc3@linux.ibm.com

Quoted 3 lines
---
 arch/s390/pci/pci_sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

Applied, thank you!