Skip to contentSkip to conversation

fs/coredump: Enable dynamic configuration of max file note size

RFC PATCH Superseded Allen Pais 4 participants 7 messages Apr 29, 2024 – Apr 30, 2024

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Allen Pais

author
#0 lore raw

RFC PATCH 1/1 fs/coredump: Enable dynamic configuration of max file note size

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

- Remove hardcoded MAX_FILE_NOTE_SIZE from fs/binfmt_elf.c.
- Define max_file_note_size in fs/coredump.c with an initial value set to 4MB.
- Declare max_file_note_size as an external variable in include/linux/coredump.h.
- Add a new sysctl entry in kernel/sysctl.c to manage this setting at runtime.

$ sysctl -a | grep max_file_note_size
kernel.max_file_note_size = 4194304
$ sysctl -n kernel.max_file_note_size
4194304

$echo 519304 > /proc/sys/kernel/max_file_note_size

$sysctl -n kernel.max_file_note_size
519304

---
 fs/binfmt_elf.c          | 3 +--
 fs/coredump.c            | 3 +++
 include/linux/coredump.h | 1 +
 kernel/sysctl.c          | 8 ++++++++
 4 files changed, 13 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +1 -2
index 5397b552fbeb..5fc7baa9ebf2 100644
@@ -1564,7 +1564,6 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
 	fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
 }
 
-#define MAX_FILE_NOTE_SIZE (4*1024*1024)
 /*
  * Format of NT_FILE note:
  *
@@ -1592,7 +1591,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm
 
 	names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
-	if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
+	if (size >= max_file_note_size) /* paranoia check */
 		return -EINVAL;
 	size = round_up(size, PAGE_SIZE);
 	/*
fs/coredump.c +3 -0
index be6403b4b14b..a83c6cc893fc 100644
@@ -56,10 +56,13 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int max_file_note_size = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
 	char *corename;
include/linux/coredump.h +1 -0
index d3eba4360150..e1ae7ab33d76 100644
@@ -46,6 +46,7 @@ static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
 #endif
 
 #if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)
+extern unsigned int max_file_note_size;
 extern void validate_coredump_safety(void);
 #else
 static inline void validate_coredump_safety(void) {}
kernel/sysctl.c +8 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
+	{
+		.procname       = "max_file_note_size",
+		.data           = &max_file_note_size,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_dointvec,
+	},
 #ifdef CONFIG_PROC_SYSCTL
 	{
 		.procname	= "tainted",
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · Allen Pais

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

- Remove hardcoded MAX_FILE_NOTE_SIZE from fs/binfmt_elf.c.
- Define max_file_note_size in fs/coredump.c with an initial value set to 4MB.
- Declare max_file_note_size as an external variable in include/linux/coredump.h.
- Add a new sysctl entry in kernel/sysctl.c to manage this setting at runtime.

$ sysctl -a | grep max_file_note_size
kernel.max_file_note_size = 4194304
Quoted 7 lines
$ sysctl -n kernel.max_file_note_size
4194304

$echo 519304 > /proc/sys/kernel/max_file_note_size

$sysctl -n kernel.max_file_note_size
519304

This doesn't highlight anything about *why*. So in practice you must've hit a use case where ELF notes are huge, can you give an example of that? The commit should also describe that this is only used in the path of a coredump on ELF binaries via elf_core_dump().

More below.

Quoted 74 lines
---
 fs/binfmt_elf.c          | 3 +--
 fs/coredump.c            | 3 +++
 include/linux/coredump.h | 1 +
 kernel/sysctl.c          | 8 ++++++++
 4 files changed, 13 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +1 -2
index 5397b552fbeb..5fc7baa9ebf2 100644
@@ -1564,7 +1564,6 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
 	fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
 }
 
-#define MAX_FILE_NOTE_SIZE (4*1024*1024)
 /*
  * Format of NT_FILE note:
  *
@@ -1592,7 +1591,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm
 
 	names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
-	if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
+	if (size >= max_file_note_size) /* paranoia check */
 		return -EINVAL;
 	size = round_up(size, PAGE_SIZE);
 	/*
fs/coredump.c +3 -0
index be6403b4b14b..a83c6cc893fc 100644
@@ -56,10 +56,13 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int max_file_note_size = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
 	char *corename;
include/linux/coredump.h +1 -0
index d3eba4360150..e1ae7ab33d76 100644
@@ -46,6 +46,7 @@ static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
 #endif
 
 #if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)
+extern unsigned int max_file_note_size;
 extern void validate_coredump_safety(void);
 #else
 static inline void validate_coredump_safety(void) {}
kernel/sysctl.c +1 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0644,

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 1634

Quoted 10 lines
kernel/sysctl.c +7 -0
 		.proc_handler	= proc_dointvec,
 	},
+	{
+		.procname       = "max_file_note_size",
+		.data           = &max_file_note_size,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_dointvec,
+	},
 #ifdef CONFIG_PROC_SYSCTL

No, please move this to coredump_sysctls in fs/coredump.c. And there is no point in supporting int, this is unisgned int right? So use the right proc handler for it.

If we're gonna do this, it makes sense to document the ELF note binary limiations. Then, consider a defense too, what if a specially crafted binary with a huge elf note are core dumped many times, what then? Lifting to 4 MiB puts in a situation where abuse can lead to many silly insane kvmalloc()s. Is that what we want? Why?

Luis

#4 lore raw
In reply to Allen Pais
Quoted 4 lines · Allen Pais

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

Under what conditions is this actually needed?

Quoted 14 lines

[...]

kernel/sysctl.c +1 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 1633

Quoted 10 lines
kernel/sysctl.c +7 -0
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
+	{
+		.procname       = "max_file_note_size",
+		.data           = &max_file_note_size,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_dointvec,
+	},

Please don't add new sysctls to kernel/sysctl.c. Put this in fs/coredump.c instead, and name it "core_file_note_size_max". (A "max" suffix is more common than prefixes, and I'd like it clarified that it relates to the coredumper with the "core" prefix that match the other coredump sysctls.

-Kees

Signature · 1 line
Kees Cook
#2 lore raw
In reply to Luis Chamberlain
Quoted 20 lines · Luis Chamberlain
Quoted 18 lines · Allen Pais

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

- Remove hardcoded MAX_FILE_NOTE_SIZE from fs/binfmt_elf.c.
- Define max_file_note_size in fs/coredump.c with an initial value set to 4MB.
- Declare max_file_note_size as an external variable in include/linux/coredump.h.
- Add a new sysctl entry in kernel/sysctl.c to manage this setting at runtime.

$ sysctl -a | grep max_file_note_size
kernel.max_file_note_size = 4194304
$ sysctl -n kernel.max_file_note_size
4194304

$echo 519304 > /proc/sys/kernel/max_file_note_size

Quoted 8 lines
Quoted 2 lines

$sysctl -n kernel.max_file_note_size
519304

This doesn't highlight anything about *why*. So in practice you must've hit a use case where ELF notes are huge, can you give an example of that? The commit should also describe that this is only used in the path of a coredump on ELF binaries via elf_core_dump().

Yes, I should have captured it. We have observed that during a crash
when there are more than 65k mmaps in memory, the existing fixed limit on the size of the ELF notes section becomes a bottleneck. The notes section quickly reaches its capacity, leading to incomplete memory segment information in the resulting coredump. This truncation compromises the utility of the coredumps, as crucial information about the memory state at the time of the crash might be omitted.

I will add the above to the commit message. Hope that addresses your concern.

Quoted 74 lines

More below.

Quoted 72 lines
---
 fs/binfmt_elf.c          | 3 +--
 fs/coredump.c            | 3 +++
 include/linux/coredump.h | 1 +
 kernel/sysctl.c          | 8 ++++++++
 4 files changed, 13 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +1 -2
index 5397b552fbeb..5fc7baa9ebf2 100644
@@ -1564,7 +1564,6 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
      fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
 }
 
-#define MAX_FILE_NOTE_SIZE (4*1024*1024)
 /*
  * Format of NT_FILE note:
  *
@@ -1592,7 +1591,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm
 
      names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
-     if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
+     if (size >= max_file_note_size) /* paranoia check */
              return -EINVAL;
      size = round_up(size, PAGE_SIZE);
      /*
fs/coredump.c +3 -0
index be6403b4b14b..a83c6cc893fc 100644
@@ -56,10 +56,13 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int max_file_note_size = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
      char *corename;
include/linux/coredump.h +1 -0
index d3eba4360150..e1ae7ab33d76 100644
@@ -46,6 +46,7 @@ static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
 #endif
 
 #if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)
+extern unsigned int max_file_note_size;
 extern void validate_coredump_safety(void);
 #else
 static inline void validate_coredump_safety(void) {}
kernel/sysctl.c +1 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 
Quoted 17 lines

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 1634

Quoted 12 lines
kernel/sysctl.c +7 -0
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
              .mode           = 0644,
              .proc_handler   = proc_dointvec,
      },
+     {
+             .procname       = "max_file_note_size",
+             .data           = &max_file_note_size,
+             .maxlen         = sizeof(unsigned int),
+             .mode           = 0644,
+             .proc_handler   = proc_dointvec,
+     },
 #ifdef CONFIG_PROC_SYSCTL

No, please move this to coredump_sysctls in fs/coredump.c. And there is no point in supporting int, this is unisgned int right? So use the right proc handler for it.

Will address it in v2.

Quoted 6 lines

If we're gonna do this, it makes sense to document the ELF note binary limiations. Then, consider a defense too, what if a specially crafted binary with a huge elf note are core dumped many times, what then? Lifting to 4 MiB puts in a situation where abuse can lead to many silly insane kvmalloc()s. Is that what we want? Why?

You raise a good point. I need to see how we can safely handle this case.

Thanks,
Allen

Quoted 1 line

Luis

Signature · 1 line
       - Allen
#5 lore raw
In reply to Kees Cook
Quoted 8 lines · Kees Cook
Quoted 4 lines · Allen Pais

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

Under what conditions is this actually needed?

I addressed this in the email I sent out before this.

Quoted 31 lines
Quoted 15 lines

[...]

kernel/sysctl.c +1 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 1633

Quoted 10 lines
kernel/sysctl.c +7 -0
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
              .mode           = 0644,
              .proc_handler   = proc_dointvec,
      },
+     {
+             .procname       = "max_file_note_size",
+             .data           = &max_file_note_size,
+             .maxlen         = sizeof(unsigned int),
+             .mode           = 0644,
+             .proc_handler   = proc_dointvec,
+     },

Please don't add new sysctls to kernel/sysctl.c. Put this in fs/coredump.c instead, and name it "core_file_note_size_max". (A "max" suffix is more common than prefixes, and I'd like it clarified that it relates to the coredumper with the "core" prefix that match the other coredump sysctls.

Quoted 1 line

-Kees

Makes sense. Let me know if the below looks fine,

fs/binfmt_elf.c +0 -0
index 5397b552fbeb..6aebd062b92b 100644
@@ -1564,7 +1564,6 @@ static void fill_siginfo_note(struct memelfnote

*note, user_siginfo_t *csigdata,

        fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);

}

-#define MAX_FILE_NOTE_SIZE (4*1024*1024)
/*
* Format of NT_FILE note:
*
@@ -1592,7 +1591,7 @@ static int fill_files_note(struct memelfnote *note, struct coredump_params *cprm

        names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
-       if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
+       if (size >= core_file_note_size_max) /* paranoia check */
                return -EINVAL;
        size = round_up(size, PAGE_SIZE);
        /*
fs/coredump.c +10 -0
index be6403b4b14b..2108eb93acb9 100644
@@ -56,10 +56,13 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int core_file_note_size_max = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
        char *corename;
@@ -1020,6 +1023,13 @@ static struct ctl_table coredump_sysctls[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
+       {
+               .procname       = "core_file_note_size_max",
+               .data           = &core_file_note_size_max,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = proc_douintvec,
+       },
 };
 
 static int __init init_fs_coredump_sysctls(void)
include/linux/coredump.h +0 -0
index d3eba4360150..14c057643e7f 100644
@@ -46,6 +46,7 @@ static inline void do_coredump(const

kernel_siginfo_t *siginfo) {}
#endif

#if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)
+extern unsigned int core_file_note_size_max;
extern void validate_coredump_safety(void); #else
static inline void validate_coredump_safety(void) {}

Thanks,
Allen

#6 lore raw
Quoted 114 lines · Allen
Quoted 8 lines · Kees Cook
Quoted 4 lines · Allen Pais

Introduce the capability to dynamically configure the maximum file note size for ELF core dumps via sysctl. This enhancement removes the previous static limit of 4MB, allowing system administrators to adjust the size based on system-specific requirements or constraints.

Under what conditions is this actually needed?

I addressed this in the email I sent out before this.

Quoted 31 lines
Quoted 15 lines

[...]

kernel/sysctl.c +1 -0
index 81cc974913bb..80cdc37f2fa2 100644
@@ -63,6 +63,7 @@
 #include <linux/mount.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/pid.h>
+#include <linux/coredump.h>
 
 #include "../lib/kstrtox.h"
 

kernel/sysctl.c static struct ctl_table kern_table[] = { · line 1633

Quoted 10 lines
kernel/sysctl.c +7 -0
@@ -1623,6 +1624,13 @@ static struct ctl_table kern_table[] = {
              .mode           = 0644,
              .proc_handler   = proc_dointvec,
      },
+     {
+             .procname       = "max_file_note_size",
+             .data           = &max_file_note_size,
+             .maxlen         = sizeof(unsigned int),
+             .mode           = 0644,
+             .proc_handler   = proc_dointvec,
+     },

Please don't add new sysctls to kernel/sysctl.c. Put this in fs/coredump.c instead, and name it "core_file_note_size_max". (A "max" suffix is more common than prefixes, and I'd like it clarified that it relates to the coredumper with the "core" prefix that match the other coredump sysctls.

Quoted 1 line

-Kees

Makes sense. Let me know if the below looks fine,

fs/binfmt_elf.c +0 -1
index 5397b552fbeb..6aebd062b92b 100644
@@ -1564,7 +1564,6 @@ static void fill_siginfo_note(struct memelfnote
 *note, user_siginfo_t *csigdata,
        fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
 }
 
-#define MAX_FILE_NOTE_SIZE (4*1024*1024)
 /*
  * Format of NT_FILE note:

*

fs/binfmt_elf.c +1 -1
@@ -1592,7 +1591,7 @@ static int fill_files_note(struct memelfnote
 *note, struct coredump_params *cprm
 
        names_ofs = (2 + 3 * count) * sizeof(data[0]);
  alloc:
-       if (size >= MAX_FILE_NOTE_SIZE) /* paranoia check */
+       if (size >= core_file_note_size_max) /* paranoia check */
                return -EINVAL;
        size = round_up(size, PAGE_SIZE);
        /*
fs/coredump.c +10 -0
index be6403b4b14b..2108eb93acb9 100644
@@ -56,10 +56,13 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int core_file_note_size_max = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
        char *corename;
@@ -1020,6 +1023,13 @@ static struct ctl_table coredump_sysctls[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
+       {
+               .procname       = "core_file_note_size_max",
+               .data           = &core_file_note_size_max,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = proc_douintvec,
+       },
 };
 
 static int __init init_fs_coredump_sysctls(void)
include/linux/coredump.h +1 -0
index d3eba4360150..14c057643e7f 100644
@@ -46,6 +46,7 @@ static inline void do_coredump(const
 kernel_siginfo_t *siginfo) {}
 #endif
 
 #if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)
+extern unsigned int core_file_note_size_max;
 extern void validate_coredump_safety(void);
 #else
Quoted 1 line

static inline void validate_coredump_safety(void) {}

Yes; thank you! I like this naming (and sysctl location) now. :)

-Kees

Signature · 1 line
Kees Cook
#3 lore raw
In reply to Allen
Quoted 10 lines

Will address it in v2.

Quoted 6 lines

If we're gonna do this, it makes sense to document the ELF note binary limiations. Then, consider a defense too, what if a specially crafted binary with a huge elf note are core dumped many times, what then? Lifting to 4 MiB puts in a situation where abuse can lead to many silly insane kvmalloc()s. Is that what we want? Why?

You raise a good point. I need to see how we can safely handle this case.

Luis,

Here's a rough idea that caps the max allowable size for the note section. I am using 16MB as the max value.

fs/coredump.c +12 -0
@@ -56,10 +56,14 @@
 static bool dump_vma_snapshot(struct coredump_params *cprm);
 static void free_vma_snapshot(struct coredump_params *cprm);
 
+#define MAX_FILE_NOTE_SIZE (4*1024*1024)
+#define MAX_ALLOWED_NOTE_SIZE (16*1024*1024)
+
 static int core_uses_pid;
 static unsigned int core_pipe_limit;
 static char core_pattern[CORENAME_MAX_SIZE] = "core";
 static int core_name_size = CORENAME_MAX_SIZE;
+unsigned int core_file_note_size_max = MAX_FILE_NOTE_SIZE;
 
 struct core_name {
        char *corename;
@@ -1060,12 +1064,22 @@ static struct ctl_table coredump_sysctls[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
+       {
+               .procname       = "core_file_note_size_max",
+               .data           = &core_file_note_size_max,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = proc_core_file_note_size_max,
+       },
 };
 
+int proc_core_file_note_size_max(struct ctl_table *table, int write,

void __user *buffer, size_t *lenp, loff_t *ppos) {
+ int error = proc_douintvec(table, write, buffer, lenp, ppos);
+ if (write && (core_file_note_size_max < MAX_FILE_NOTE_SIZE
+ || core_file_note_size_max > MAX_ALLOWED_NOTE_SIZE))
+. /* Revert to default if out of bounds */
+ core_file_note_size_max = MAX_FILE_NOTE_SIZE;
+ return error;
+}

Let me know what you think.

Thanks,
- Allen