Re: [PATCH v4 2/6] initramfs_test: test header fields with 0x hex prefix
From: Andy Shevchenko
Date: Mon Mar 30 2026 - 05:59:27 EST
On Sun, Mar 29, 2026 at 09:30:24PM +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.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
--
With Best Regards,
Andy Shevchenko