Re: [PATCH v5 2/6] initramfs_test: test header fields with 0x hex prefix

From: Andy Shevchenko

Date: Tue Mar 31 2026 - 06:19:01 EST


On Tue, Mar 31, 2026 at 05:57:32PM +1100, David Disseldorp wrote:
> cpio header fields are 8-byte hex strings, but one "interesting"
> side-effect of our historic simple_str[n]toul() use means that a "0x"
> (or "0X") prefixed header field will be successfully processed when
> coupled alongside a 6-byte hex remainder string.
>
> "0x" prefix support is contrary to the initramfs specification at
> Documentation/driver-api/early-userspace/buffer-format.rst which states:
>
> The structure of the cpio_header is as follows (all fields contain
> hexadecimal ASCII numbers fully padded with '0' on the left to the
> full width of the field, for example, the integer 4780 is represented
> by the ASCII string "000012ac"):
>
> Test for this corner case by injecting "0x" prefixes into the uid, gid
> and namesize cpio header fields. Confirm that init_stat() returns
> matching uid and gid values.
>
> This test can be modified in future to expect unpack_to_rootfs() failure
> when header validation is changed to properly follow the specification.
>
> Add some missing struct kstat initializations to account for possible
> init_stat() failures.

Right, thanks.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

--
With Best Regards,
Andy Shevchenko