Skip to content

Commit 5e54d73

Browse files
authored
Merge pull request #228 from truenas/NAS-137525-25.10-RC.1
NAS-137525 / 25.10-RC.1 / ses: fix NULL dereference accessing sysfs during enclosure removal (by ixhamza)
2 parents 82c46f3 + b950fac commit 5e54d73

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/scsi/ses.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,13 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
11071107
edev->poll_task = NULL;
11081108
}
11091109

1110+
/* enclosure_unregister() sets ->cb to NULL callbacks, preventing any
1111+
* further SES driver calls. It removes enclosure sysfs entries,
1112+
* eliminating the race window. edev remains valid as we hold a ref;
1113+
* it will be freed in enclosure_release() via our put_device() below.
1114+
*/
1115+
enclosure_unregister(edev);
1116+
11101117
ses_dev = edev->scratch;
11111118
edev->scratch = NULL;
11121119

@@ -1118,8 +1125,8 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
11181125
if (edev->components)
11191126
kfree(edev->component[0].scratch);
11201127

1128+
/* Drop last reference from enclosure_find() */
11211129
put_device(&edev->edev);
1122-
enclosure_unregister(edev);
11231130
}
11241131

11251132
static void ses_intf_remove(struct device *cdev)

0 commit comments

Comments
 (0)