Hi Aristo,
On 2026-08-31T14:25:38, Aristo Chen <[email protected]> wrote:
> test: boot: Check that rauc rejects over-long slot names
>
> Boot the RAUC bootflow after setting BOOT_ORDER to a 33-character slot
> name, one more than fits the "BOOT_<slot>_LEFT" env-var name buffer. The
> boot must now fail with -ENAMETOOLONG.
>
> Before the previous commit the name overflowed the stack buffer; as no
> such variable exists the boot then failed with -ENOENT, hiding the
> overflow.
>
> Also check the accepted side of the boundary: a 32-character name, the
> longest that fits, must pass the length check and fail only with -ENOENT
> because its BOOT_<slot>_LEFT variable does not exist.
>
> Signed-off-by: Aristo Chen <[email protected]>
>
> test/boot/bootflow.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
Since the boundary is boot_left_name(), please exercise the scan path
too - distro_rauc_read_bootflow() calls it against
CONFIG_BOOTMETH_RAUC_BOOT_ORDER, which is what a user is most likely
to hit. The current test only reaches find_active_slot() via
BOOT_ORDER at boot time.
> + /*
> + * A 32-char slot name is the longest that fits. It must pass the
> + * length check and fail only because BOOT_<slot>_LEFT does not exist.
> + */
> + ut_assertok(env_set("BOOT_ORDER", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"));
> + ut_asserteq(1, run_command("bootflow boot", 0));
> + ut_assert_nextline("** Booting bootflow 'mmc10.bootdev.whole' with
> rauc");
> + ut_assert_nextline("Boot failed (err=%d)", -ENOENT);
> + ut_assert_console_end();
> diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
> @@ -1520,6 +1520,29 @@ static int bootstd_images(struct unit_test_state *uts)
> ptr = map_sysmem(img->addr, 0);
> ut_asserteq_strn("BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=", ptr);
>
> + /*
> + * Boot with a BOOT_ORDER slot name (33 chars) that is too long for the
> + * "BOOT_<slot>_LEFT" env-var name buffer. It must be rejected rather
> + * than overflow the stack.
> + */
> + ut_assertok(run_command("bootflow select 0", 0));
> + ut_assert_console_end();
> + ut_assertok(env_set("BOOT_ORDER", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
> B"));
> + ut_asserteq(1, run_command("bootflow boot", 0));
> + ut_assert_nextline("** Booting bootflow 'mmc10.bootdev.whole' with
> rauc");
> + ut_assert_nextline("Boot failed (err=%d)", -ENAMETOOLONG);
> + ut_assert_console_end();
This is in the wrong function. bootstd_images() scans
mmc2/mmc1/mmc4/mmc5 and produces the four extlinux/script/cros
bootflows listed just above; it never binds bootmeth_rauc or enables
mmc10, so 'bootflow select 0' picks mmc1.bootdev.part_1 (extlinux_cfg)
and the expected "** Booting bootflow 'mmc10.bootdev.whole' with rauc"
line never appears. Please extend bootflow_rauc() (or add a sibling
test that reuses its setup) so mmc10 is bound and rauc is in the
bootmeth order before 'bootflow boot' runs. Also restore BOOT_ORDER
(and the bootmeth/bootdev order) at the end so it does not leak into
the next test.
Regards,
Simon