On 31.10.26 15:06, Simon Glass wrote: > Hi Frieder, > > On 2026-10-29T16:23:07+11:00, Frieder Schrempf <[email protected]> wrote: >> bootstd: rauc: Free the boot script of a failed boot attempt >> >> The RAUC bootmeth loads the boot script when booting, not when reading >> the bootflow. If the boot fails, the bootflow keeps its private data and >> can be booted again, for example with another 'bootflow boot'. Each >> attempt then loads the script into a new buffer and adds another image >> to the bootflow, but the previous buffer, image list entry and subdir >> are never freed. 'bootstd images' lists one more copy of boot.scr after >> every attempt. >> >> Free what a previous attempt loaded before loading the script again, >> in the same way as bootflow_free(). Also check the strdup() of the >> subdir. >> >> Fixes: 7e5c2c782fb9 ("bootstd: Add implementation for bootmeth rauc") >> Assisted-by: LLM >> Signed-off-by: Frieder Schrempf <[email protected]> >> >> boot/bootmeth_rauc.c | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) > >> diff --git a/boot/bootmeth_rauc.c b/boot/bootmeth_rauc.c >> @@ -305,6 +306,15 @@ static int distro_rauc_load_boot_script(struct bootflow >> *bflow, >> + /* Drop the boot script of a previous, failed boot attempt */ >> + free(bflow->buf); >> + bflow->buf = NULL; >> + free(bflow->subdir); >> + bflow->subdir = NULL; >> + alist_for_each(img, &bflow->images) >> + free(img->fname); >> + alist_empty(&bflow->images); > > The search loop below only runs while bflow->state != BOOTFLOWST_FILE, > so this reset only works if the previous attempt got as far as a > successful bootmeth_alloc_file(). If bootmeth_try_file() succeeds but > bootmeth_alloc_file() then fails with -E2BIG (or fs_read_alloc() > fails), the state stays at BOOTFLOWST_FILE. On the next attempt the > loop is skipped and bootmeth_alloc_file() is called with the stale > fname and size from the previous slot, even though bootmeth_setup_fs() > now points at a different partition. Please can you also put the state > back to BOOTFLOWST_READY here?
Yes, I will fix this in v2. > > The image-freeing duplicates bootflow_free(), so should be in a helper > in bootflow.c which both can call. That would also fix the commit > message's claim to do this 'in the same way as bootflow_free()', which > is not quite true: bootflow_free() only frees buf when > BOOTFLOWF_STATIC_BUF is clear (although that flag is never set on this > path). Ok, sure. > > A test which boots the same bootflow twice and checks the image count > would be good, perhaps as a follow-up. I will have a look, if I can add a test for this in v2. Thanks!
