init/initramfs_test: wait_for_initramfs() before running
PATCH 1/1 init/initramfs_test: wait_for_initramfs() before running
initramfs_test_extract() and friends call unpack_to_rootfs() from a kunit kthread while do_populate_rootfs() may still be running asynchronously from rootfs_initcall. unpack_to_rootfs() keeps its parser state in module-static variables (victim, byte_count, state, this_header, header_buf, name_buf, ...), so the two writers corrupt each other.
On arm64 v7.0-rc5+ this oopses early in boot:
Unable to handle kernel paging request at virtual address ffff80018f9f0ffc pc : do_reset+0x3c/0x98 Call trace: do_reset initramfs_test_extract kunit_try_run_case Initramfs unpacking failed: junk within compressed archive
do_reset() faults because 'victim' was overwritten by the boot-time unpacker; the boot unpacker meanwhile logs the bogus "junk within compressed archive" on the real initrd because the test wrecked its state machine.
Add a .suite_init callback that calls wait_for_initramfs() so the async unpack is quiescent before the first case runs. suite_init runs once per suite rather than before every individual test case.
---
v2: Hook up .suite_init for initramfs test suite (sashiko-bot)
init/initramfs_test.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
init/initramfs_test.c +16 -1
@@ -3,7 +3,9 @@#include <linux/fcntl.h> #include <linux/file.h> #include <linux/fs.h> +#include <linux/init.h> #include <linux/init_syscalls.h> +#include <linux/initrd.h> #include <linux/stringify.h> #include <linux/timekeeping.h> #include "initramfs_internal.h"
@@ -510,8 +512,21 @@ static struct kunit_case __refdata initramfs_test_cases[] = { {}, }; -static struct kunit_suite initramfs_test_suite = { +static int __init initramfs_test_init (struct kunit_suite *suite) +{ +/* +* unpack_to_rootfs() uses module-static state (victim, byte_count, +* state, ...). The boot-time async do_populate_rootfs() may still be +* running, so wait for it to finish before we call unpack_to_rootfs() +* from the test thread, otherwise the two writers race and crash. +*/ +wait_for_initramfs (); +return 0 ; +} + +static struct kunit_suite __refdata initramfs_test_suite = { .name ="initramfs" , + .suite_init = initramfs_test_init, .test_cases = initramfs_test_cases, };kunit_test_init_section_suites (&initramfs_test_suite);
Signature · 1 line
2.34.1
Quoted 8 lines · Jia He
initramfs_test_extract()and friends callunpack_to_rootfs()from a kunit kthread whiledo_populate_rootfs()may still be running asynchronously fromrootfs_initcall.unpack_to_rootfs()keeps its parser state in module-static variables (victim,byte_count, state,this_header,header_buf,name_buf, ...), so the two writers corrupt each other.[...]
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.misc
[1/1] init/initramfs_test: wait_for_initramfs() before running
https://git.kernel.org/vfs/vfs/c/c876fe9797d8