Hi Alexey,

On 2026-09-18T10:52:27, Alexey Charkov <[email protected]> wrote:
> test: spl: Size the FIT properties for the image name
>
> create_fit() budgets a flat 596 bytes for the properties it writes, but
> one of them is the image name (named after the test itself), which is used
> twice and can cause libfdt run out of room and create_fit() return 0 if a
> new test with a longer name is added.

'can cause libfdt to run out of room'

Please can you make the motivation concrete? By my measurement on
64-bit sandbox, 596 bytes fits a name of up to 27 characters, which is
exactly spl_test_image_FIT_INTERNAL, and the next patch adds
30-character names such as spl_test_nor_FIT_INTERNAL_LZMA. So this is
needed by the series, rather than being a hypothetical problem.

>
> Size the buffer accounting for the name explicitly.
>
> Signed-off-by: Alexey Charkov <[email protected]>
>
> test/image/spl_load.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

> diff --git a/test/image/spl_load.c b/test/image/spl_load.c
> @@ -163,7 +163,14 @@ static size_t start_fit(void *dst, size_t fit_size, 
> size_t data_size,
> +      * The name goes in twice, as the description of both the image and the
> +      * configuration, and for external data this budget is exact: it is the
> +      * whole buffer start_fit() gets, and where the data then starts, which
> +      * the loader expects 4-byte aligned.
> +      */
> +     size_t prop_size = ALIGN(596 + 2 * strlen(spl_image->name), 4);

This works, but 596 already includes room for two copies of a
27-character name. With an empty name the FIT needs 548 bytes on
64-bit (540 on 32-bit), so the name is now counted twice and there are
always at least 48 bytes spare. That is harmless, but 'exact' reads as
though the figure is tight, when I think you mean that prop_size is
also the data offset.

Also, each copy of the name takes ALIGN(strlen() + 1, 4) bytes in the
FIT, so 2 * strlen() can be up to 8 bytes short; only the slack in 596
covers this. Please can you either reduce the base to what the fixed
properties need and add 2 * ALIGN(strlen() + 1, 4), or reword the
comment to say that 596 is the fixed part plus some margin? The first
option is already a multiple of 4, so the outer ALIGN() could go.

Regards,
Simon

Reply via email to