[PATCH master] block: fix calling cdev_get_block_device with partitions

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Oct 9 23:38:34 PDT 2022


For partitions, cdev->priv references the parent block device.
Doing the pointer arithmetic in container_of will result in an
out-of-bounds access. Do what the rest of the code does
and access cdev->priv instead.

Fixes: 84173bf3d0cc ("block: set S_IFBLK for block devices instead of S_IFCHR")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/block.c b/common/block.c
index 19bb81df2c3d..a4cfd6e22771 100644
--- a/common/block.c
+++ b/common/block.c
@@ -366,7 +366,7 @@ struct block_device *cdev_get_block_device(struct cdev *cdev)
 	if (!cdev || cdev->ops != &block_ops)
 		return NULL;
 
-	return container_of(cdev, struct block_device, cdev);
+	return cdev->priv;
 }
 
 int blockdevice_register(struct block_device *blk)
-- 
2.30.2




More information about the barebox mailing list