init: open output files from cpio unpacking with O_LARGEFILE
authorJohn Sperbeck <jsperbeck@google.com>
Sat, 23 Mar 2024 15:29:34 +0000 (08:29 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 5 Apr 2024 18:21:30 +0000 (11:21 -0700)
If a member of a cpio archive for an initrd or initrams is larger than
2Gb, we'll eventually fail to write to that file when we get to that
limit, unless O_LARGEFILE is set.

The problem can be seen with this recipe, assuming that BLK_DEV_RAM
is not configured:

cd /tmp
dd if=/dev/zero of=BIGFILE bs=1048576 count=2200
echo BIGFILE | cpio -o -H newc -R root:root > initrd.img
kexec -l /boot/vmlinuz-$(uname -r) --initrd=initrd.img --reuse-cmdline
kexec -e

The console will show 'Initramfs unpacking failed: write error'.  With
the patch, the error is gone.

Link: https://lkml.kernel.org/r/20240323152934.3307391-1-jsperbeck@google.com
Signed-off-by: John Sperbeck <jsperbeck@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
init/initramfs.c

index 3127e0bf7bbd15487ea6b50bd277801f6c01ae7e..a298a3854a8018923dbbd26adbc271550ef9a198 100644 (file)
@@ -367,7 +367,7 @@ static int __init do_name(void)
        if (S_ISREG(mode)) {
                int ml = maybe_link();
                if (ml >= 0) {
-                       int openflags = O_WRONLY|O_CREAT;
+                       int openflags = O_WRONLY|O_CREAT|O_LARGEFILE;
                        if (ml != 1)
                                openflags |= O_TRUNC;
                        wfile = filp_open(collected, openflags, mode);