diff mbox series

ubi, write: fix invalid envsize ptr to UBI_IOCVOLUP

Message ID 20200519194517.966347-1-mk@mkio.de
State Accepted
Headers show
Series ubi, write: fix invalid envsize ptr to UBI_IOCVOLUP | expand

Commit Message

Markus Klotzbuecher May 19, 2020, 7:45 p.m. UTC
The UBI_IOCVOLUP ioctl expects a __s64*, however the struct
uboot_flash_env.envsize is of type size_t, which depending on the
architecture may be only 4 bytes long and cause the ioctl to read a
bogus size value. This fixes this by converting the size_t envsize to
a int64_t and passing a ptr to that to the ioctl.

Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
---
 src/uboot_env.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stefano Babic May 19, 2020, 9:15 p.m. UTC | #1
On 19.05.20 21:45, Markus Klotzbuecher wrote:
> The UBI_IOCVOLUP ioctl expects a __s64*, however the struct
> uboot_flash_env.envsize is of type size_t, which depending on the
> architecture may be only 4 bytes long and cause the ioctl to read a
> bogus size value. This fixes this by converting the size_t envsize to
> a int64_t and passing a ptr to that to the ioctl.
> 
> Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
> ---
>  src/uboot_env.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/uboot_env.c b/src/uboot_env.c
> index 4de1deb..f9ffeda 100644
> --- a/src/uboot_env.c
> +++ b/src/uboot_env.c
> @@ -677,7 +677,8 @@ devwrite_out:
>  
>  static int ubi_update_volume(struct uboot_flash_env *dev)
>  {
> -	return ioctl(dev->fd, UBI_IOCVOLUP, &dev->envsize);
> +	int64_t envsize = dev->envsize;
> +	return ioctl(dev->fd, UBI_IOCVOLUP, &envsize);
>  }
>  
>  static int ubiwrite(struct uboot_flash_env *dev, void *data)
> 

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/src/uboot_env.c b/src/uboot_env.c
index 4de1deb..f9ffeda 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -677,7 +677,8 @@  devwrite_out:
 
 static int ubi_update_volume(struct uboot_flash_env *dev)
 {
-	return ioctl(dev->fd, UBI_IOCVOLUP, &dev->envsize);
+	int64_t envsize = dev->envsize;
+	return ioctl(dev->fd, UBI_IOCVOLUP, &envsize);
 }
 
 static int ubiwrite(struct uboot_flash_env *dev, void *data)