mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath
@ 2023-05-08  7:46 Ahmad Fatoum
  2023-05-08  7:46 ` [PATCH master 2/2] block: refuse registering block devices with absurdly large blocks Ahmad Fatoum
  2023-05-08 13:18 ` [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-05-08  7:46 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

get_fsdevice_by_path will return NULL if no file system was mounted at
location. Returned pointer was dereferenced unconditionally, potentially
leading to null pointer dereference. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 65e4c661b9ce..368458cc54f8 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -240,6 +240,8 @@ struct cdev *get_cdev_by_mountpath(const char *path)
 	struct fs_device *fsdev;
 
 	fsdev = get_fsdevice_by_path(path);
+	if (!fsdev)
+		return NULL;
 
 	return fsdev->cdev;
 }
@@ -249,6 +251,8 @@ char *get_mounted_path(const char *path)
 	struct fs_device *fdev;
 
 	fdev = get_fsdevice_by_path(path);
+	if (!fdev)
+		return NULL;
 
 	return fdev->path;
 }
-- 
2.39.2




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

* [PATCH master 2/2] block: refuse registering block devices with absurdly large blocks
  2023-05-08  7:46 [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Ahmad Fatoum
@ 2023-05-08  7:46 ` Ahmad Fatoum
  2023-05-08 13:18 ` [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-05-08  7:46 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Block layer caching can't work if a block is bigger than BUFSIZE which
is used for the caching chunks. Instead of ending up with a rdbufsize
of 0, which leads to strange errors on device access, just refuse this
outright.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/block.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/common/block.c b/common/block.c
index 7f28b56419e2..c39269d3a692 100644
--- a/common/block.c
+++ b/common/block.c
@@ -388,6 +388,11 @@ int blockdevice_register(struct block_device *blk)
 	dev_dbg(blk->dev, "rdbufsize: %d blockbits: %d blkmask: 0x%08x\n",
 		blk->rdbufsize, blk->blockbits, blk->blkmask);
 
+	if (!blk->rdbufsize) {
+		pr_warn("block size of %u not supported\n", BLOCKSIZE(blk));
+		return -ENOSYS;
+	}
+
 	for (i = 0; i < 8; i++) {
 		struct chunk *chunk = xzalloc(sizeof(*chunk));
 		chunk->data = dma_alloc(BUFSIZE);
-- 
2.39.2




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

* Re: [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath
  2023-05-08  7:46 [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Ahmad Fatoum
  2023-05-08  7:46 ` [PATCH master 2/2] block: refuse registering block devices with absurdly large blocks Ahmad Fatoum
@ 2023-05-08 13:18 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-05-08 13:18 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, May 08, 2023 at 09:46:11AM +0200, Ahmad Fatoum wrote:
> get_fsdevice_by_path will return NULL if no file system was mounted at
> location. Returned pointer was dereferenced unconditionally, potentially
> leading to null pointer dereference. Fix this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  fs/fs.c | 4 ++++
>  1 file changed, 4 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 65e4c661b9ce..368458cc54f8 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -240,6 +240,8 @@ struct cdev *get_cdev_by_mountpath(const char *path)
>  	struct fs_device *fsdev;
>  
>  	fsdev = get_fsdevice_by_path(path);
> +	if (!fsdev)
> +		return NULL;
>  
>  	return fsdev->cdev;
>  }
> @@ -249,6 +251,8 @@ char *get_mounted_path(const char *path)
>  	struct fs_device *fdev;
>  
>  	fdev = get_fsdevice_by_path(path);
> +	if (!fdev)
> +		return NULL;
>  
>  	return fdev->path;
>  }
> -- 
> 2.39.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] 3+ messages in thread

end of thread, other threads:[~2023-05-08 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08  7:46 [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Ahmad Fatoum
2023-05-08  7:46 ` [PATCH master 2/2] block: refuse registering block devices with absurdly large blocks Ahmad Fatoum
2023-05-08 13:18 ` [PATCH master 1/2] fs: fail gracefully in get_mounted_path/get_cdev_by_mountpath Sascha Hauer

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