Skip to contentSkip to conversation

block : Fix use-after-free Read in delete_partition

PATCH In review Anant Thazhemadam 2 participants 2 messages Sep 6, 2020 – Sep 7, 2020 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block : Fix use-after-free Read in delete_partition

A use-after-free read of the kobject member being casted out to the device structure containing it seems to be potentially possible due to unsafe casting using container_of (since an edge case such as when the ptr being casted might be NULL or problematic is not accounted for).
Using container_of_safe resolves this issue, with no obvious tradeoffs and without considerable expense.

---
 include/linux/device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/device.h +1 -1
index ca18da4768e3..aeb70b7a37e6 100644
@@ -643,7 +643,7 @@ struct device_link {
 
 static inline struct device *kobj_to_dev(struct kobject *kobj)
 {
-	return container_of(kobj, struct device, kobj);
+	return container_of_safe(kobj, struct device, kobj);
 }
 
 /**
Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Quoted 7 lines · Anant Thazhemadam

A use-after-free read of the kobject member being casted out to the device structure containing it seems to be potentially possible due to unsafe casting using container_of (since an edge case such as when the ptr being casted might be NULL or problematic is not accounted for).
Using container_of_safe resolves this issue, with no obvious tradeoffs and without considerable expense.

No, now every caller has to check for NULL, and that would mean that you now need to fix up hundreds of different places in the kernel.

Please fix the root cause that would cause NULL to be passed to this call in the block code, don't paper over the issue here.

thanks,

greg k-h
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees