Skip to contentSkip to conversation

kexec_file: Increase maximum file size to 4G

PATCH In review Pasha Tatashin 1 participant 3 messages May 26, 2022 – May 27, 2022

Subsystems (3)
lore
Share & tools
lore

Pasha Tatashin

author maintainer
#0 lore raw

PATCH 1/1 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.

---
 kernel/kexec_file.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/kexec_file.c +6 -2
index 8347fc158d2b..1be2227b33e6 100644
@@ -31,6 +31,9 @@
 
 static int kexec_calculate_store_digests(struct kimage *image);
 
+/* Maximum size in bytes for kernel/initrd files. */
+#define KEXEC_FILE_SIZE_MAX	(4UL << 30)
+
 /*
  * Currently this is the only default function that is exported as some
  * architectures need it to do additional handlings.
@@ -227,7 +230,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
 	void *ldata;
 
 	ret = kernel_read_file_from_fd(kernel_fd, 0, &image->kernel_buf,
-				       INT_MAX, NULL, READING_KEXEC_IMAGE);
+				       KEXEC_FILE_SIZE_MAX, NULL,
+				       READING_KEXEC_IMAGE);
 	if (ret < 0)
 		return ret;
 	image->kernel_buf_len = ret;
@@ -247,7 +251,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
 	/* It is possible that there no initramfs is being loaded */
 	if (!(flags & KEXEC_FILE_NO_INITRAMFS)) {
 		ret = kernel_read_file_from_fd(initrd_fd, 0, &image->initrd_buf,
-					       INT_MAX, NULL,
+					       KEXEC_FILE_SIZE_MAX, NULL,
 					       READING_KEXEC_INITRAMFS);
 		if (ret < 0)
 			goto out;
Signature · 1 line
2.36.1.124.g0e6072fb45-goog
author maintainer
#1 lore raw
Quoted 7 lines · Pasha Tatashin

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.

Quoted 8 lines

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.

Should be instead:

Thanks,
Pasha

Quoted 40 lines
---
 kernel/kexec_file.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/kexec_file.c +6 -3
index 8347fc158d2b..1be2227b33e6 100644
@@ -31,6 +31,9 @@
 
 static int kexec_calculate_store_digests(struct kimage *image);
 
+/* Maximum size in bytes for kernel/initrd files. */
+#define KEXEC_FILE_SIZE_MAX    (4UL << 30)
+
 /*
  * Currently this is the only default function that is exported as some
  * architectures need it to do additional handlings.
@@ -227,7 +230,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
        void *ldata;
 
        ret = kernel_read_file_from_fd(kernel_fd, 0, &image->kernel_buf,
-                                      INT_MAX, NULL, READING_KEXEC_IMAGE);
+                                      KEXEC_FILE_SIZE_MAX, NULL,
+                                      READING_KEXEC_IMAGE);
        if (ret < 0)
                return ret;
        image->kernel_buf_len = ret;
@@ -247,7 +251,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
        /* It is possible that there no initramfs is being loaded */
        if (!(flags & KEXEC_FILE_NO_INITRAMFS)) {
                ret = kernel_read_file_from_fd(initrd_fd, 0, &image->initrd_buf,
-                                              INT_MAX, NULL,
+                                              KEXEC_FILE_SIZE_MAX, NULL,
                                               READING_KEXEC_INITRAMFS);
                if (ret < 0)
                        goto out;
--

2.36.1.124.g0e6072fb45-goog

author maintainer
#2 lore raw
Quoted 10 lines · Pasha Tatashin
Quoted 7 lines · Pasha Tatashin

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.

Quoted 6 lines
Quoted 6 lines

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.

It appears that since:
f7a4f689bca6072492626938aad6dd2f32c5bf97 fs/kernel_read_file: Remove redundant size argument

Introduced a change to kernel_read_file to limit the maximum file internally from SIZE_MAX to INT_MAX.

Therefore, more changes will be needed. I will work on them and sent them in v2.

Quoted 19 lines
Quoted 2 lines

Should be instead:

Thanks,
Pasha

Quoted 10 lines
---
 kernel/kexec_file.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/kexec_file.c +0 -0
index 8347fc158d2b..1be2227b33e6 100644
@@ -31,6 +31,9 @@
 
Quoted 4 lines

kernel/kexec_file.c line 35

Quoted 4 lines
kernel/kexec_file.c +2 -0
 static int kexec_calculate_store_digests(struct kimage *image);
 
+/* Maximum size in bytes for kernel/initrd files. */
+#define KEXEC_FILE_SIZE_MAX    (4UL << 30)

Also, I will address 32-bit, with picking minimum between SIZE_MAX and kexec max file.

Thanks,
Pasha