From patchwork Thu May 2 14:59:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allen Pais X-Patchwork-Id: 13651758 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 CA185C4345F for ; Thu, 2 May 2024 14:59:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06BC46B0083; Thu, 2 May 2024 10:59:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01B486B0085; Thu, 2 May 2024 10:59:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E00676B0087; Thu, 2 May 2024 10:59:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C55F66B0083 for ; Thu, 2 May 2024 10:59:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7D728A1DBA for ; Thu, 2 May 2024 14:59:29 +0000 (UTC) X-FDA: 82073764458.17.B23C332 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 9C737120016 for ; Thu, 2 May 2024 14:59:26 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=kLpxbUQM; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf29.hostedemail.com: domain of apais@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=apais@linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714661966; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=emptab7+3YFMG1SQMC0wFEdq7q5l4lpPKpITnuC0zJg=; b=Ci0QOQw9ASDW64oKNcsiE7bPtHixc43Xr40QF5p6dwGc45/n8Oske3bS5q8seJAChnYA62 huAVbpr5T4HWqtr+/Rnia0fZtsD+l9b0A/IzpUAXgdXVK0M94kFPjWF7MknqiET5iuWI7Q s4ByU7hd7bkJYEHY63KHv78EbhLfvNM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=kLpxbUQM; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf29.hostedemail.com: domain of apais@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=apais@linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714661966; a=rsa-sha256; cv=none; b=XBbaNbWd42PfAJUiil7QdrMXzz6b+KG7zLIYR2pVUeFjdgD2vOCCO/wBJST/Z9DFsawUWC tY7t2x+UgifUsd5Pvd/BtW1kri/LZXDnRXKKdo92X2H70kn6AvqnnCR7snx//WjPIamo6I G+uhLaAISp7GmL774SISGlAwNEVVP5Y= Received: from apais-vm1.0synte4vioeebbvidf5q0vz2ua.xx.internal.cloudapp.net (unknown [52.183.86.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 4E46E20B2C80; Thu, 2 May 2024 07:59:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4E46E20B2C80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1714661965; bh=emptab7+3YFMG1SQMC0wFEdq7q5l4lpPKpITnuC0zJg=; h=From:To:Cc:Subject:Date:From; b=kLpxbUQM6vgG2iRx6mGF27Bwzlq2ikZH0BIuBoKzsQ0i7ds67Lu5X4A7WWApGpM7I uXdh2D8hr8mXwvd2AM9XSyAxcCX3NtWB6bQiN+RFltl5adKQ5Ht6BPHpEgj0du8fAX JEZ8PEm5s2jkhU5eJFIac47yXgch+NYOIJIcwj1E= From: Allen Pais To: linux-fsdevel@vger.kernel.org Cc: 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, mcgrof@kernel.org, j.granados@samsung.com Subject: [PATCH v2] fs/coredump: Enable dynamic configuration of max file note size Date: Thu, 2 May 2024 14:59:20 +0000 Message-Id: <20240502145920.5011-1-apais@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9C737120016 X-Stat-Signature: jdmeiss3goe714dzthcoju8n647tc5um X-HE-Tag: 1714661966-333907 X-HE-Meta: U2FsdGVkX1+V5jHPrbRXAiNsuci7i6AuyH/6QNVw+VZsPmGbgVb1ME6PpPDoWmcw03/SboeihHfAZValGqZkc2p2Gt95M9mfiNmLkeuNRKbKPiZuroQSTCHj4eE4usSjVYNPEcJ1eRB3Xy03H977ydwHx4C9nLLk8PtZLAgWtp2km8ddImkukdMLo96Hw8LZUS1/ZKv1ACDc8wUFAV7HBf1PpJvc4l/ABI5CIHb6D4OHtzRzfdOPBgNqCUNZuNiXJ5j3IQa8y0jwJfjPFk3hM7Uw8stuJdPg7EPo8GRlYWcndEVyEF3JYkT+rZwkcEfeQba3yCWMJC5RyOFDKJWmEyGVQt936nWDAHrJjfR8knURLARR/5qIueqCUlLCXmhrLgB85jJnz48aH77Re6jGgZRsSDyKw6BYym/RpEqcjlLK1q5M+S5guy4dysSEESsA/H3ltCFtMGZYZM4KUvxUTNafgrM90O3OCR0ec/M/Qde60IDfnWVJA1H6TDDJ97wTo89lJZJ/S1p0R2AKhrJI5JRMOOVYyIUvYXRWYROji+e6q0bzfRLOy8TZyZGVObzG2s7N0oXhiHf/z9Cv9GWfqUN5BGWow99r85RMtlJCT5sqJqo/AyMcktjWxlKLMiHEt8LSmVlW/XgBZ7FaFg+b7kA1jRCuv4PNqrX/T+8m3nFRQGvviAY7haENXAZyX1GbMmipshfkDZuNSGmHi7wVzwXZDbgBY+6oHi8ZnA4htsg4mTY5LT3qJlhmY2vjfu/soLZtMh1YjUMl1Z996uHUAGFTaxz4wm189DoS4F27OemZ0E0QKPZebmnXFmmxceh1j3eY6mbiVelU+8Tu94Ob3SvgXzuWNEuoOZQLYP93k/odgNMmTRH0l1gYIBck5N3lNMheKi840ZLAlqiZaKGYuqLoJQNXQ9WXPRqJ5vuIhdNV+lxRHrHkXDc1uMl1iREC2b30MLmSFddxMZwlRMR mtOT9+A7 9ypQmHn/zXeT7MGZvA364FsCik9+bQtRI+WuMLDr8ccV4PzGi7NFW1eqpab7E3t50rYGuWGmD0y/LItOMXU1zOajJxdo8P/1jKfBvdgU5BrCLR0WKMnfVAAt8/VrS0pUVODert1vXqEy4WNrI7BpI7NEmL5je4Pd+7tNFJTxJ7+q7OkIY1yNaLMpzUY47XL515rbl X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 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. 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; size = round_up(size, PAGE_SIZE); /* diff --git a/fs/coredump.c b/fs/coredump.c index be6403b4b14b..a312be48030f 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -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) diff --git a/include/linux/coredump.h b/include/linux/coredump.h index d3eba4360150..14c057643e7f 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -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) {}