gen_init_cpio: stop parsing on lines with a missing argument list
PATCH 1/1 gen_init_cpio: stop parsing on lines with a missing argument list
When a line in the cpio list consists of a file type followed only by whitespace and no newline (e.g. "slink " as the last line of the file), strtok(NULL, "\n") returns NULL. main() prints an error and sets ec, but then carries on and passes the NULL args pointer to the type handler, which hands it to sscanf() and crashes:
AddressSanitizer: SEGV on unknown address 0x000000000000
#4 __isoc99_sscanf
#5 cpio_mkslink_line usr/gen_init_cpio.c:169Break out of the loop as is already done for the other format error, so that the error is reported and gen_init_cpio exits with a failure status.
Found by fuzzing gen_init_cpio built with ASan/UBSan.
Reproducer:
printf 'slink ' > list && usr/gen_init_cpio list
--- usr/gen_init_cpio.c | 1 + 1 file changed, 1 insertion(+)
usr/gen_init_cpio.c +1 -0
@@ -756,6 +756,7 @@ int main (int argc, char *argv[])"ERROR: incorrect format, newline required line %d: '%s'\n" , line_nr, line); ec =-1 ; +break ; }for (type_idx =0 ; file_handler_table[type_idx].type; type_idx++) {
Signature · 1 line
2.34.1
Nathan Chancellor
maintainerQuoted 1 line · On Mon, 05 Oct 2026 03:57:29 -0500, lzhan011 wrote:
gen_init_cpio: stop parsing on lines with a missing argument list
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-unstable
Thanks!
[1/1] gen_init_cpio: stop parsing on lines with a missing argument list
https://git.kernel.org/kbuild/c/4677a58a643f9
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.
Best regards,
Signature · 2 lines
Cheers, Nathan
A message that is not in the archive (sent off-list or not yet received): CAGD6qbRTat70Uf7Ax_e+M0pphwJN9s5+iyWM_3ELPQGm3YjdFw@mail.gmail.com
Nathan Chancellor
maintainerQuoted 9 lines · LZ
Hi Nathan,
Thanks for applying the patch. I noticed that I submitted it with my username lzhan011 as the author/sign-off name. For proper attribution, my name should be Leizhen Zhang <[email protected]>.
Would you prefer that I resend the patch with the corrected author/sign-off, or is it possible to amend it in the tree? Thank you so much for your help.
I have updated the patch in the Kbuild tree, as it was at the top.
https://git.kernel.org/kbuild/c/c8dd1aa0274d8ad3df82ec1b064065f410ce99ed
Please note this is incorrect for all of the other changes you have sent, so you will need to resend them. You did not include the Kconfig reviewer Julian Braha on the patches touching scripts/kconfig, so please include him when you resend.
Signature · 2 lines
Cheers, Nathan