Skip to contentSkip to conversation

s390/cio: Fix NULL dereference in ccw_device_get_util_str()

PATCH Applied Vineeth Vijayan 4 participants 5 messages Sep 22 – Sep 23

Subsystems (2)
lore
Share & tools
lore

Vineeth Vijayan

author maintainer
#0 lore raw

PATCH 1/1 s390/cio: Fix NULL dereference in ccw_device_get_util_str()

The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.
Add the missing NULL check before dereferencing the returned pointer.

Fixes 199652309a4d ("s390/cio: add helper to query utility strings per given ccw device")
---
 drivers/s390/cio/device_ops.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/s390/cio/device_ops.c +2 -0
index f2f7f8cba410..1f7e83fd5087 100644
@@ -517,6 +517,8 @@ u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx)
 	chp_id_init(&chpid);
 	chpid.id = sch->schib.pmcw.chpid[chp_idx];
 	chp = chpid_to_chp(chpid);
+	if (!chp)
+		return NULL;
 
 	util_str = kmalloc(sizeof(chp->desc_fmt3.util_str), GFP_KERNEL);
 	if (!util_str)
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.
Add the missing NULL check before dereferencing the returned pointer.

Fixes 199652309a4d ("s390/cio: add helper to query utility strings per given ccw device")

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

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Vineeth Vijayan
Quoted 3 lines · Vineeth Vijayan

The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.

Actually as I understand it, it is the other way around: the registry (css->chps) still contains the entry, but the PMCW CHPID list contains 0 due a cleared SCHIB. Therefore the lookup will return NULL, unless by chance a CHPID 0 exists.

Quoted 5 lines

Add the missing NULL check before dereferencing the returned pointer.

Fixes 199652309a4d ("s390/cio: add helper to query utility strings per given ccw device")
Signature · 2 lines
Peter Oberparleiter
Linux on IBM Z Development - IBM Germany R&D
author maintainer
#3 lore raw
Quoted 10 lines · Peter Oberparleiter
Quoted 3 lines · Vineeth Vijayan

The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.

Actually as I understand it, it is the other way around: the registry (css->chps) still contains the entry, but the PMCW CHPID list contains 0 due a cleared SCHIB. Therefore the lookup will return NULL, unless by chance a CHPID 0 exists.

mm..This is also a possibility. But we are not clearing SCHIB here. We still cache the old unpredictable value to sch->schib. And then based on this, we try to read some index of registry which could be a NULL.

Quoted 9 lines
Quoted 5 lines

Add the missing NULL check before dereferencing the returned pointer.

Fixes 199652309a4d ("s390/cio: add helper to query utility strings per given ccw device")
maintainer Applied
#4 lore raw
In reply to Vineeth Vijayan

drivers/s390/cio/device_ops.c u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx) · line 523

Quoted 9 lines · Vineeth Vijayan

The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.
Add the missing NULL check before dereferencing the returned pointer.

drivers/s390/cio/device_ops.c +2 -0
+	if (!chp)
+		return NULL;
 
 	util_str = kmalloc(sizeof(chp->desc_fmt3.util_str), GFP_KERNEL);

The context diff is confusing; as if this would be the to be fixed bug :) But ok, just a few lines below chp is indeed dereferenced.

Applied, thanks!