From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49099C4345F for ; Thu, 2 May 2024 22:47:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C342A6B0088; Thu, 2 May 2024 18:47:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE3466B0089; Thu, 2 May 2024 18:47:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAC036B008A; Thu, 2 May 2024 18:47:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 817226B0088 for ; Thu, 2 May 2024 18:47:34 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0554D40188 for ; Thu, 2 May 2024 22:47:34 +0000 (UTC) X-FDA: 82074944028.02.5F24846 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 2200920007 for ; Thu, 2 May 2024 22:47:30 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=MaMpicFu; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714690051; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qMDOwJlnqLjVTDrfPZW0Iu5hD97JbrHipMX/GW9VxEA=; b=qo6yMR8Xe8yPYGcC3QJOBiGbSqRLk+UloWqjQYQ5mWDRho2sc5jl0fY3+6AWw5c2SpTaA5 eE5XsevSlSa7oGPWA0sJsEuKfUIAsh0C+QOlr6EdeRh/LUYfq7YMHjspZ4HceFh3lZ6wH7 5t8RBSG1rHdqo1Ksvv5LNFmC7VTs8FE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714690051; a=rsa-sha256; cv=none; b=VOoDCxUJYO7mX0LPjEIG7G+djGuCJTkt9x3j/oSBgOkYgfLamyvGBM6VXq5wJQAM5o0o3H hiUPpKUmoUtaQbIt3OwQfWPclgLTE2olMHiWBU65yA7ybsqtnlcPZWGbobLt00SNyMelO2 3fdZXyU91ufcCJS8lyp9z8FWn+CTM7I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=MaMpicFu; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5dca1efad59so6248822a12.2 for ; Thu, 02 May 2024 15:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714690050; x=1715294850; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=qMDOwJlnqLjVTDrfPZW0Iu5hD97JbrHipMX/GW9VxEA=; b=MaMpicFuLSFUPTLtgcdJ1JMl6/hCFn1OEWJaPznoW8EpBFTMoyP6T27mUxGsvv4po6 VvJ7OGgkJh9ZxbqgzjPXSZc60viPnoDNB+f+Lx1FAILx6fs2gnTWivekI6Flja2gGp3g V/8nE6CaOLkS/cmXC88QxA85DOddiQoI7JLBA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714690050; x=1715294850; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qMDOwJlnqLjVTDrfPZW0Iu5hD97JbrHipMX/GW9VxEA=; b=bAa4zZgqd/KCEtqkJuJ2H88jIedcmmiiELdosHFmTbbfMx8i9vMyht967lMoZqGaSR U/fusP8OGwfFiEr1xX9dYHwui/1WfVTmP/1ckZMSoT5t+MYs5ftEp6F2ZwGZLLJdWIT8 iZBBZdQTZ/0OKRkwjC+HJjKeN0Sts/2QwAxrLri8xrUe25SOOUtiG7zCD7AHjb8bQOQK NMzs//ZePtaE6JFXY+0KUsdJAxTo8HA0PGHQ1DMHjBqeLvBMJVCmJ6xmftoUX4YFo9Od 64BklyxplyI63JKqYCH4mGoAw5ZBjC9VCi/c0YlfGrpMVE3iSZXiC0Ju9L0qeeJNI9hb Lj4Q== X-Forwarded-Encrypted: i=1; AJvYcCUqncuPLn3nVuw5UtUExryjW3jlfkvfvjX8ZVc5gUEq0ZJtXK0Ei5xDZo0a5AqZsQX2woTpzMwo/HiMHTXACoPJWb8= X-Gm-Message-State: AOJu0Yz5pCE/b5NVATrWrvV+gboB6KX4I/Ly4kkn7GHUyzkRceoMtTfw vr0IQrITn0o6BB8UZP8tKG32+MGWxggQkahPT2We6JLqBRDtwDmnyxHhApWAOw== X-Google-Smtp-Source: AGHT+IHD0FBpS56EdsfC3+XKdOjNxpAQUA2NXZ5FFtInn2XZKWCGioJvIGY86CTQK3kPpRVrkEePfg== X-Received: by 2002:a17:90b:149:b0:2b3:70d4:15fb with SMTP id em9-20020a17090b014900b002b370d415fbmr1053056pjb.24.1714690049899; Thu, 02 May 2024 15:47:29 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001e446490072sm1905831plb.25.2024.05.02.15.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 15:47:29 -0700 (PDT) Date: Thu, 2 May 2024 15:47:28 -0700 From: Kees Cook To: Allen Cc: Allen Pais , 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, mcgrof@kernel.org, j.granados@samsung.com Subject: Re: [PATCH v2] fs/coredump: Enable dynamic configuration of max file note size Message-ID: <202405021545.4A3ACDED0@keescook> References: <20240502145920.5011-1-apais@linux.microsoft.com> <202405021045.360F5313EA@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Stat-Signature: 7ydg7hj8egannpy1nif3qnubq7xjdpam X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 2200920007 X-HE-Tag: 1714690050-52455 X-HE-Meta: U2FsdGVkX19y29B/Qm0N315x2SVsWPlXTtSdQ6AvgFQE5IRBvHB/jnJ/bxRsNSDNaS1cknRPRM6qznO8x+iI0S+sPFNg2icQ6XU6dLDNxHp0SG63lAvZwz2kgUMcagWyGrHBojYMFuTOJj/LQpTyp/DjxmKa4u22va0yeMmQq3wRpTNtoYzEzVuFhDdku525AWqKWA5W7fdmplmXEV4i5KdJEVDms7n2OvTyPQ/vZFhuJYt3F67uZ7cLXDhoTtvwo5rX4nIPjPgs6gcleEl2Z/8odLUqQmI+L8yZb0s0ylcddGY097TZtnOo5/sJHniqiht27UYVFTzvrJhzLtXMsQTm97irembFuNFPN0vPclYtGCMPI3Uu5sAmRi1Zkli+wi5IOgUw2q/eDDOHOXpSFcyguba/fGtpWcx61am4WrnPwOsNFhle6IUAIs2slfqEdVo7Yn+N1uPRTa2e7egKx+YzCUaL0SUy4T3NRCUPTxo/wim8/V/sc8VUUl+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ner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, May 02, 2024 at 01:03:52PM -0700, Allen wrote: > On Thu, May 2, 2024 at 10:50 AM Kees Cook wrote: > > > > On Thu, May 02, 2024 at 02:59:20PM +0000, Allen Pais wrote: > > > 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 > > > > The names and paths in the commit log need a refresh here, since they've > > changed. > > Will fix it in v3. > > > > > > > > Why is this being done? > > > 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. > > > > Thanks for adding this! > > > > > > > > Signed-off-by: Vijay Nag > > > Signed-off-by: Allen Pais > > > > > > --- > > > Changes in v2: > > > - Move new sysctl to fs/coredump.c [Luis & Kees] > > > - rename max_file_note_size to core_file_note_size_max [kees] > > > - Capture "why this is being done?" int he commit message [Luis & Kees] > > > --- > > > fs/binfmt_elf.c | 3 +-- > > > fs/coredump.c | 10 ++++++++++ > > > include/linux/coredump.h | 1 + > > > 3 files changed, 12 insertions(+), 2 deletions(-) > > > > > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > > > index 5397b552fbeb..6aebd062b92b 100644 > > > --- a/fs/binfmt_elf.c > > > +++ b/fs/binfmt_elf.c > > > @@ -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; > > > > I wonder, given the purpose of this sysctl, if it would be a > > discoverability improvement to include a pr_warn_once() before the > > EINVAL? Like: > > > > /* paranoia check */ > > if (size >= core_file_note_size_max) { > > pr_warn_once("coredump Note size too large: %zu (does kernel.core_file_note_size_max sysctl need adjustment?\n", size); > > return -EINVAL; > > } > > > > What do folks think? (I can't imagine tracking down this problem > > originally was much fun, for example.) > > I think this would really be helpful. I will go ahead and add this if > there's no objection from anyone. > > Also, I haven't received a reply from Luis, do you think we need to > add a ceiling? > > +#define MAX_FILE_NOTE_SIZE (4*1024*1024) > +#define MAX_ALLOWED_NOTE_SIZE (16*1024*1024) // Define a reasonable max cap > ..... > > + { > + .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)) > + core_file_note_size_max = MAX_FILE_NOTE_SIZE; // Revert to > default if out of bounds > + return error; > +} > > > Or, should we go ahead with the current patch(with the warning added)? Let's add a ceiling just to avoid really pathological behavior. We got this far with 4M, so having a new ceiling seems reasonable. And for implementing it, see proc_douintvec_minmax. -Kees -- Kees Cook