From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25CAC1754B for ; Tue, 30 Apr 2024 05:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714455411; cv=none; b=Qp4wUhcMYdXZi5TIXUihkccehK2D/ZqtK7Sr4nL1GZFll5Xl7zwcnW9UmlodLAZIvgssmdDHDVVnWMxnURIX6tb9qGGCI/VX0uo5iYyDrYEB2ygzPDbgg5rmODF8OPocXnVCz+b7L+8fhwiVj37wJ+AwnMmjLbn/+U6gf1WpUX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714455411; c=relaxed/simple; bh=ic45Ly5iOqM2hN40D+e1MnLz2cah/7zHv0WBtywKiU8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FNg6cPZ8Qp35AeZOA/eU+eQ2lmHqNaJJGL4eIzM+4druCQS9IF4K1Te3AXw5BBzYRIv7NUQhFlVLPzG4wNmorypgbIUwWpIa+ovUc5kE5GN1bxV+bqHxNn9TYlNjZyY5G+aNsqXF11HOnDF3+vO4hJvMnF8rlvczUadhL+OSxZI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=kUvPO+dy; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kUvPO+dy" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e40042c13eso35892295ad.2 for ; Mon, 29 Apr 2024 22:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714455409; x=1715060209; darn=vger.kernel.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=tfcUvly+FIvb0j4uFmsdXOeKUl+PlbA1SIU5IPSmRRs=; b=kUvPO+dyIdUtHDCRCw+bSVBv2FNq1I4DEqiMAbE7LqxbvlX9XhLkoU/x11Z0H5eM0g 09LOmvnCr/JFaspzk7Y/Czo/QXMif/fwLWt88ODWVO5c84y9i50lPDZI7toB5OQVGf3+ jelFypwwof1N5v3dgB4teLsKIyc6LqXyH+uFg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714455409; x=1715060209; 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=tfcUvly+FIvb0j4uFmsdXOeKUl+PlbA1SIU5IPSmRRs=; b=YKZ6Tu23/ldvnnoWktpFltjesprhiKvGH/UUklh2rYaj5ABVYfu0s+qQ9SeU0XIG9N Q3H7g5TPiHlS+ih6bmTAZBWOv6jZPSPmir0Wg7yvgeGRC2l42Tx/2t4FGIuTcuvXzzOG a7yI9BugZIsAS6cHk5mh3pp747L8+HWCu1apbqI8n3ixFDi814PEBn2Jo2c6zDV520ia UVFVQ9Lmkc9h8+9JjuuIWL7I6A3Mi6hzk/j9gg0WY9UL2dViFh0VrYWci44lDvpjUSFA okozXvKhGUUaJ8B5tda8TYPmp1MEKzJ4qT8EXT47mp1cjigHol9zEjve6OXVmz90/YEW PqxQ== X-Forwarded-Encrypted: i=1; AJvYcCUh5w3pI3FCI3t1bujKtnD0E/czQ+MlOO1OQTC0Zg2ogAuhJqkd0WO8WTHqmhRyzgTOweS/dtG5IFk9QCIMzbwc/vGZmSooiJ234oVg X-Gm-Message-State: AOJu0YwC0HZSsCOyWjCXTVFfCVaVIgu0ztOXsgYkh5Vy1ObzOS1SUNPM KKKhrB+h1c93F/Y7/5q8ZMCWWWcDQYjuVfL7NpaxY85UG5CmwrkD97e8ERFBQg== X-Google-Smtp-Source: AGHT+IEI1xCl5MgJCRf5jfTPqNjC35t8O+Ee/g+Asor/wizBcjvlYPWp+LqGt/RJxxnu3iJri6Tn1w== X-Received: by 2002:a17:903:487:b0:1dc:a605:5435 with SMTP id jj7-20020a170903048700b001dca6055435mr12028201plb.31.1714455409417; Mon, 29 Apr 2024 22:36:49 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id n1-20020a170902d2c100b001e2a7e90321sm21334480plc.224.2024.04.29.22.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 22:36:48 -0700 (PDT) Date: Mon, 29 Apr 2024 22:36:48 -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: [RFC PATCH] fs/coredump: Enable dynamic configuration of max file note size Message-ID: <202404292236.568F42D3C@keescook> References: <20240429172128.4246-1-apais@linux.microsoft.com> <202404291245.18281A6D@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Apr 29, 2024 at 03:35:01PM -0700, Allen wrote: > On Mon, Apr 29, 2024 at 12:49 PM Kees Cook wrote: > > > > On Mon, Apr 29, 2024 at 05:21:28PM +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. > > > > Under what conditions is this actually needed? > > I addressed this in the email I sent out before this. > > > > > > [...] > > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > > > index 81cc974913bb..80cdc37f2fa2 100644 > > > --- a/kernel/sysctl.c > > > +++ b/kernel/sysctl.c > > > @@ -63,6 +63,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #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, > > > + }, > > > > 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 > > Makes sense. Let me know if the below looks fine, > > 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..2108eb93acb9 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) {} Yes; thank you! I like this naming (and sysctl location) now. :) -Kees -- Kees Cook