[PATCH v3 8/9] fs: Report errors for out-of-bounds protect operations
Sascha Hauer
s.hauer at pengutronix.de
Tue Jun 17 00:56:41 PDT 2025
On Thu, Jun 12, 2025 at 08:58:11AM +0200, Oleksij Rempel wrote:
> The protect() function previously masked errors for out-of-bounds
> requests. It would either return success for offsets already beyond
> file/partition size or clamp the count for ranges extending beyond the
> boundary. This behavior was introduced by commit 6815e0d05480 ("fs:
> limit flash erase and protect to the partiton boundary") to address SPI
> flash wrap-around issues.
>
> This masking prevented shell commands from reporting failures for
> invalid ranges, which could mislead users and scripts. For example,
> underlying driver errors like -EINVAL from NVMEM were not propagated.
>
> This patch modifies protect() to return appropriate error codes (-ENXIO
> or -EINVAL) for such out-of-bounds conditions, instead of silently
> succeeding or clamping.
>
> Fixes: 6815e0d05480 ("fs: limit flash erase and protect to the partiton boundary")
> Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> ---
> fs/fs.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/fs.c b/fs/fs.c
> index 7bc94d7b9e6c..dd6af3cef874 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -652,9 +652,9 @@ int protect(int fd, size_t count, loff_t offset, int prot)
> if (IS_ERR(f))
> return -errno;
> if (offset >= f->f_size)
> - return 0;
> - if (count > f->f_size - offset)
> - count = f->f_size - offset;
> + return errno_set(-ENXIO);
> + if (!count || count > f->f_size - offset)
> + return errno_set(-EINVAL);
This breaks the saveenv command which does a
ret = protect(envfd, ~0, 0, 0);
to unprotect the environment sector. Try on a board with environment in
SPI flash.
Sascha
--
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 |
More information about the barebox
mailing list