Re: [PATCH 4/4] bareboximd: make the '-c' option work again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 28 Oct 2021 08:45:19 +0200
Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> wrote:


Hi Ahmad!

> On 28.10.21 03:28, Antony Pavlov wrote:
> > bareboximd with the '-c' option craches while
> > trying to alter an image file, e.g.:
> > 
> >     barebox$ git describe
> >     v2021.10.0-125-gd136ec5ac6
> >     barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
> >     ...
> >     barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
> >     ...
> >     images built:
> >     barebox-nxp-imx8mm-evk.img
> >     barebox-prt-prt8mm.img
> >     barebox-nxp-imx8mn-evk.img
> >     barebox-nxp-imx8mp-evk.img
> >     barebox-nxp-imx8mq-evk.img
> >     barebox-zii-imx8mq-dev.img
> >     barebox-phytec-phycore-imx8mq.img
> >     barebox$ ./scripts/bareboximd images/barebox-phytec-phycore-imx8mq.img
> >     build: #1 Thu Oct 28 01:11:07 UTC 2021
> >     buildsystem version:
> >     crc32: 0x00000000
> >     release: 2021.10.0-00125-gd136ec5ac6
> >     barebox$ ./scripts/bareboximd -c images/barebox-phytec-phycore-imx8mq.img
> >     Segmentation fault (core dumped)
> > 
> > The problem is that the bareboximd uses mmap() on an image file
> > in read-only mode.
> > 
> > Signed-off-by: Antony Pavlov <antonynpavlov@xxxxxxxxx>
> > ---
> >  scripts/bareboximd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
> > index c3dcb4dcf0..fe0d274380 100644
> > --- a/scripts/bareboximd.c
> > +++ b/scripts/bareboximd.c
> > @@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t
> >  		goto close;
> >  	}
> >  
> > -	buf = mmap(NULL, max_size, PROT_READ, MAP_SHARED, fd, 0);
> > +	buf = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> 
> I think this here only works incidentally, by failing and then doing a malloc. See mmap(2):
> 
> Errors: EACCES    MAP_SHARED was requested and PROT_WRITE is set, but fd is  not  open 
>                   in  read/write  (O_RDWR)  mode.
> 
> Correct would be MAP_PRIVATE. I sent a patch to that effect yesterday:
> https://lore.barebox.org/barebox/20211027060150.28184-1-a.fatoum@xxxxxxxxxxxxxx/T/#u

Aghh! I have not seen your patch :(

> 
> >  	if (buf == MAP_FAILED ) {
> >  		buf = malloc(max_size);
> >  		if (!buf) {
> > 
> 
> 
> -- 
> 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 |


-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux