s390/cio: Fix NULL dereference in ccw_device_get_util_str()
Subsystems (2)
Vineeth Vijayan
maintainerPATCH 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.
--- drivers/s390/cio/device_ops.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/s390/cio/device_ops.c +2 -0
@@ -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
[email protected]
AI reviewSashiko 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")Signed-off-by Vineeth Vijayan <[email protected]>
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
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")Signed-off-by Vineeth Vijayan <[email protected]>
Signature · 2 lines
Peter Oberparleiter Linux on IBM Z Development - IBM Germany R&D
Vineeth Vijayan
maintainerQuoted 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")Signed-off-by Vineeth Vijayan <[email protected]>Reviewed-by Peter Oberparleiter <[email protected]>
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!