Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kexec_file: increase maximum file size to 4G

In some case initrd can be large. For example, it could be a netboot
image loaded by u-root, that is kexec'ing into it.

The maximum size of initrd is arbitrary set to 2G. Also, the limit is not
very obvious because it is hidden behind a generic INT_MAX macro.

Theoretically, we could make it LONG_MAX, but it is safer to keep it sane,
and just increase it to 4G.

Increase the size to 4G, and make it obvious by having a new macro that
specifies the maximum file size supported by kexec_file_load() syscall:
KEXEC_FILE_SIZE_MAX.

Link: https://lkml.kernel.org/r/20220527025535.3953665-3-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Sasha Levin <sashal@kernel.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Baoquan He <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
akpm
f4da7afe dabba872

+7 -3
+7 -3
kernel/kexec_file.c
··· 31 31 32 32 static int kexec_calculate_store_digests(struct kimage *image); 33 33 34 + /* Maximum size in bytes for kernel/initrd files. */ 35 + #define KEXEC_FILE_SIZE_MAX min_t(s64, 4LL << 30, SSIZE_MAX) 36 + 34 37 /* 35 38 * Currently this is the only default function that is exported as some 36 39 * architectures need it to do additional handlings. ··· 192 189 const char __user *cmdline_ptr, 193 190 unsigned long cmdline_len, unsigned flags) 194 191 { 195 - int ret; 192 + ssize_t ret; 196 193 void *ldata; 197 194 198 195 ret = kernel_read_file_from_fd(kernel_fd, 0, &image->kernel_buf, 199 - INT_MAX, NULL, READING_KEXEC_IMAGE); 196 + KEXEC_FILE_SIZE_MAX, NULL, 197 + READING_KEXEC_IMAGE); 200 198 if (ret < 0) 201 199 return ret; 202 200 image->kernel_buf_len = ret; ··· 217 213 /* It is possible that there no initramfs is being loaded */ 218 214 if (!(flags & KEXEC_FILE_NO_INITRAMFS)) { 219 215 ret = kernel_read_file_from_fd(initrd_fd, 0, &image->initrd_buf, 220 - INT_MAX, NULL, 216 + KEXEC_FILE_SIZE_MAX, NULL, 221 217 READING_KEXEC_INITRAMFS); 222 218 if (ret < 0) 223 219 goto out;