Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
From: Allen <allen.lkml@gmail.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: Allen Pais <apais@linux.microsoft.com>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, viro@zeniv.linux.org.uk,  brauner@kernel.org,
	jack@suse.cz, ebiederm@xmission.com,  keescook@chromium.org,
	j.granados@samsung.com
Subject: Re: [RFC PATCH] fs/coredump: Enable dynamic configuration of max file note size
Date: Tue, 30 Apr 2024 10:51:29 -0700	[thread overview]
Message-ID: <CAOMdWS+jSC5UoO9nqYvRe_rRid_SOSuzK3c8M-NJ9-LKVhoCFg@mail.gmail.com> (raw)
In-Reply-To: <CAOMdWS+u3WkB5yiwTjNKOD1sMSQP-F22FSpkq0R8TCPhihp=2w@mail.gmail.com>

>  Will address it in v2.
>
> > 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.

--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -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

  reply	other threads:[~2024-04-30 17:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29 17:21 [RFC PATCH] fs/coredump: Enable dynamic configuration of max file note size Allen Pais
2024-04-29 18:38 ` Luis Chamberlain
2024-04-29 22:32   ` Allen
2024-04-30 17:51     ` Allen [this message]
2024-04-29 19:49 ` Kees Cook
2024-04-29 22:35   ` Allen
2024-04-30  5:36     ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOMdWS+jSC5UoO9nqYvRe_rRid_SOSuzK3c8M-NJ9-LKVhoCFg@mail.gmail.com \
    --to=allen.lkml@gmail.com \
    --cc=apais@linux.microsoft.com \
    --cc=brauner@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=j.granados@samsung.com \
    --cc=jack@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).