mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] block: fix calling cdev_get_block_device with partitions
@ 2022-10-10  6:38 Ahmad Fatoum
  2022-10-10  7:14 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-10-10  6:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH master] block: fix calling cdev_get_block_device with partitions
  2022-10-10  6:38 [PATCH master] block: fix calling cdev_get_block_device with partitions Ahmad Fatoum
@ 2022-10-10  7:14 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-10-10  7:14 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Oct 10, 2022 at 08:38:34AM +0200, Ahmad Fatoum wrote:
> 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@pengutronix.de>
> ---
>  common/block.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> 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
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-10  7:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10  6:38 [PATCH master] block: fix calling cdev_get_block_device with partitions Ahmad Fatoum
2022-10-10  7:14 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox