gen_init_cpio: fix short read file handling
authorDavid Disseldorp <ddiss@suse.de>
Tue, 10 May 2022 01:29:20 +0000 (18:29 -0700)
committerakpm <akpm@linux-foundation.org>
Tue, 10 May 2022 01:29:20 +0000 (18:29 -0700)
commit3a2699cfbe317f6e1b9c84d2f10ab7debb1c79dc
tree86fd88d4da577fcdae5c0f33edbf889bcb290477
parent1274aea127b2e8c9a4b9cbcc3ea6baf78990a958
gen_init_cpio: fix short read file handling

When processing a "file" entry, gen_init_cpio attempts to allocate a
buffer large enough to stage the entire contents of the source file.  It
then attempts to fill the buffer via a single read() call and subsequently
writes out the entire buffer length, without checking that read() returned
the full length, potentially writing uninitialized buffer memory.

Fix this by breaking up file I/O into 64k chunks and only writing the
length returned by the prior read() call.

Link: https://lkml.kernel.org/r/20220404093429.27570-5-ddiss@suse.de
Signed-off-by: David Disseldorp <ddiss@suse.de>
Reviewed-by: Martin Wilck <mwilck@suse.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
usr/gen_init_cpio.c