public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] tools: open FIT image for reading as O_RDONLY instead of O_RDWR
@ 2024-03-20 13:08 Ahelenia Ziemiańska
  2024-03-20 15:59 ` Dragan Simic
  0 siblings, 1 reply; 5+ messages in thread
From: Ahelenia Ziemiańska @ 2024-03-20 13:08 UTC (permalink / raw)
  To: Tom Rini, u-boot

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

The only usage of the fd is for the single read() below;
this prevented
	mkimage -f auto -A arm64 \
		-T kernel -C lz4 -d Image-6.6.15.lz4 \
		-b mt8173-elm-hana-6.6.15.dtb outf
when the inputs were unwriteable.

Link: https://bugs.debian.org/1063097
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
 tools/fit_image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/fit_image.c b/tools/fit_image.c
index beef1fa8..0fccfbb4 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -137,7 +137,7 @@ static int fdt_property_file(struct image_tool_params *params,
 	int ret;
 	int fd;
 
-	fd = open(fname, O_RDWR | O_BINARY);
+	fd = open(fname, O_RDONLY | O_BINARY);
 	if (fd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			params->cmdname, fname, strerror(errno));
-- 
2.39.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] tools: open FIT image for reading as O_RDONLY instead of O_RDWR
  2024-03-20 13:08 [PATCH] tools: open FIT image for reading as O_RDONLY instead of O_RDWR Ahelenia Ziemiańska
@ 2024-03-20 15:59 ` Dragan Simic
  2024-03-21 18:31   ` [PATCH v2] tools: open FIT image read-only Ahelenia Ziemiańska
  0 siblings, 1 reply; 5+ messages in thread
From: Dragan Simic @ 2024-03-20 15:59 UTC (permalink / raw)
  To: Ahelenia Ziemiańska; +Cc: Tom Rini, u-boot

Hello Ahelenia,

Please see my comments below.

On 2024-03-20 14:08, Ahelenia Ziemiańska wrote:
> The only usage of the fd is for the single read() below;
> this prevented
> 	mkimage -f auto -A arm64 \
> 		-T kernel -C lz4 -d Image-6.6.15.lz4 \
> 		-b mt8173-elm-hana-6.6.15.dtb outf
> when the inputs were unwriteable.

s/unwriteable/unwritable/

Also, the patch subject could be moved to the patch description,
and the following could be used instead, as the subject:

     tools: open FIT image read-only

> 
> Link: https://bugs.debian.org/1063097
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>

Looking good to me.  Opening the file read-only is also good
from the standpoint of using least privilege to perform the
required operation.

With the small nitpicks above,

Reviewed-by: Dragan Simic <dsimic@manjaro.org>

> ---
>  tools/fit_image.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/fit_image.c b/tools/fit_image.c
> index beef1fa8..0fccfbb4 100644
> --- a/tools/fit_image.c
> +++ b/tools/fit_image.c
> @@ -137,7 +137,7 @@ static int fdt_property_file(struct
> image_tool_params *params,
>  	int ret;
>  	int fd;
> 
> -	fd = open(fname, O_RDWR | O_BINARY);
> +	fd = open(fname, O_RDONLY | O_BINARY);
>  	if (fd < 0) {
>  		fprintf(stderr, "%s: Can't open %s: %s\n",
>  			params->cmdname, fname, strerror(errno));

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

* [PATCH v2] tools: open FIT image read-only
  2024-03-20 15:59 ` Dragan Simic
@ 2024-03-21 18:31   ` Ahelenia Ziemiańska
  2024-04-04 16:44     ` Dragan Simic
  2024-04-10 17:43     ` Tom Rini
  0 siblings, 2 replies; 5+ messages in thread
From: Ahelenia Ziemiańska @ 2024-03-21 18:31 UTC (permalink / raw)
  To: Tom Rini, u-boot

[-- Attachment #1: Type: text/plain, Size: 961 bytes --]

Open for reading as O_RDONLY instead of O_RDWR:
the only usage of the fd is for the single read() below;
this prevented
	mkimage -f auto -A arm64 \
		-T kernel -C lz4 -d Image-6.6.15.lz4 \
		-b mt8173-elm-hana-6.6.15.dtb outf
when the inputs were unwritable.

Link: https://bugs.debian.org/1063097
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Dragan Simic <dsimic@manjaro.org>
---
 tools/fit_image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/fit_image.c b/tools/fit_image.c
index beef1fa8..0fccfbb4 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -137,7 +137,7 @@ static int fdt_property_file(struct image_tool_params *params,
 	int ret;
 	int fd;
 
-	fd = open(fname, O_RDWR | O_BINARY);
+	fd = open(fname, O_RDONLY | O_BINARY);
 	if (fd < 0) {
 		fprintf(stderr, "%s: Can't open %s: %s\n",
 			params->cmdname, fname, strerror(errno));
-- 
2.39.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] tools: open FIT image read-only
  2024-03-21 18:31   ` [PATCH v2] tools: open FIT image read-only Ahelenia Ziemiańska
@ 2024-04-04 16:44     ` Dragan Simic
  2024-04-10 17:43     ` Tom Rini
  1 sibling, 0 replies; 5+ messages in thread
From: Dragan Simic @ 2024-04-04 16:44 UTC (permalink / raw)
  To: Ahelenia Ziemiańska; +Cc: Tom Rini, u-boot

Hello all,

Just a brief reminder about merging this patch.  It looks fine to me.


On 2024-03-21 19:31, Ahelenia Ziemiańska wrote:
> Open for reading as O_RDONLY instead of O_RDWR:
> the only usage of the fd is for the single read() below;
> this prevented
> 	mkimage -f auto -A arm64 \
> 		-T kernel -C lz4 -d Image-6.6.15.lz4 \
> 		-b mt8173-elm-hana-6.6.15.dtb outf
> when the inputs were unwritable.
> 
> Link: https://bugs.debian.org/1063097
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
> Reviewed-by: Dragan Simic <dsimic@manjaro.org>
> ---
>  tools/fit_image.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/fit_image.c b/tools/fit_image.c
> index beef1fa8..0fccfbb4 100644
> --- a/tools/fit_image.c
> +++ b/tools/fit_image.c
> @@ -137,7 +137,7 @@ static int fdt_property_file(struct
> image_tool_params *params,
>  	int ret;
>  	int fd;
> 
> -	fd = open(fname, O_RDWR | O_BINARY);
> +	fd = open(fname, O_RDONLY | O_BINARY);
>  	if (fd < 0) {
>  		fprintf(stderr, "%s: Can't open %s: %s\n",
>  			params->cmdname, fname, strerror(errno));

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

* Re: [PATCH v2] tools: open FIT image read-only
  2024-03-21 18:31   ` [PATCH v2] tools: open FIT image read-only Ahelenia Ziemiańska
  2024-04-04 16:44     ` Dragan Simic
@ 2024-04-10 17:43     ` Tom Rini
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Rini @ 2024-04-10 17:43 UTC (permalink / raw)
  To: u-boot, Ahelenia Ziemiańska

On Thu, 21 Mar 2024 19:31:54 +0100, Ahelenia Ziemiańska wrote:

> Open for reading as O_RDONLY instead of O_RDWR:
> the only usage of the fd is for the single read() below;
> this prevented
> 	mkimage -f auto -A arm64 \
> 		-T kernel -C lz4 -d Image-6.6.15.lz4 \
> 		-b mt8173-elm-hana-6.6.15.dtb outf
> when the inputs were unwritable.
> 
> [...]

Applied to u-boot/master, thanks!

-- 
Tom



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

end of thread, other threads:[~2024-04-10 17:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-20 13:08 [PATCH] tools: open FIT image for reading as O_RDONLY instead of O_RDWR Ahelenia Ziemiańska
2024-03-20 15:59 ` Dragan Simic
2024-03-21 18:31   ` [PATCH v2] tools: open FIT image read-only Ahelenia Ziemiańska
2024-04-04 16:44     ` Dragan Simic
2024-04-10 17:43     ` Tom Rini

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