[PATCH RFC v2 4/6] coredump: show supported coredump modes

Christian Brauner posted 6 patches 9 months, 1 week ago
[PATCH RFC v2 4/6] coredump: show supported coredump modes
Posted by Christian Brauner 9 months, 1 week ago
Allow userspace to discover what coredump modes are supported.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/coredump.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fs/coredump.c b/fs/coredump.c
index 9a6cba233db9..1c7428c23878 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1217,6 +1217,13 @@ static int proc_dostring_coredump(const struct ctl_table *table, int write,
 
 static const unsigned int core_file_note_size_min = CORE_FILE_NOTE_SIZE_DEFAULT;
 static const unsigned int core_file_note_size_max = CORE_FILE_NOTE_SIZE_MAX;
+static char core_modes[] = {
+#ifdef CONFIG_UNIX
+	"file\npipe\nunix"
+#else
+	"file\npipe"
+#endif
+};
 
 static const struct ctl_table coredump_sysctls[] = {
 	{
@@ -1260,6 +1267,13 @@ static const struct ctl_table coredump_sysctls[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE,
 	},
+	{
+		.procname	= "core_modes",
+		.data		= core_modes,
+		.maxlen		= sizeof(core_modes) - 1,
+		.mode		= 0444,
+		.proc_handler	= proc_dostring,
+	},
 };
 
 static int __init init_fs_coredump_sysctls(void)

-- 
2.47.2
Re: [PATCH RFC v2 4/6] coredump: show supported coredump modes
Posted by Jann Horn 9 months, 1 week ago
On Fri, May 2, 2025 at 2:43 PM Christian Brauner <brauner@kernel.org> wrote:
> Allow userspace to discover what coredump modes are supported.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/coredump.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index 9a6cba233db9..1c7428c23878 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -1217,6 +1217,13 @@ static int proc_dostring_coredump(const struct ctl_table *table, int write,
>
>  static const unsigned int core_file_note_size_min = CORE_FILE_NOTE_SIZE_DEFAULT;
>  static const unsigned int core_file_note_size_max = CORE_FILE_NOTE_SIZE_MAX;
> +static char core_modes[] = {
> +#ifdef CONFIG_UNIX
> +       "file\npipe\nunix"
> +#else
> +       "file\npipe"
> +#endif
> +};

Nit: You could do something like

static char core_modes[] =
#ifdef CONFIG_UNIX
  "unix\n"
#endif
  "file\npipe"
;
Re: [PATCH RFC v2 4/6] coredump: show supported coredump modes
Posted by Christian Brauner 9 months, 1 week ago
On Fri, May 02, 2025 at 04:07:23PM +0200, Jann Horn wrote:
> On Fri, May 2, 2025 at 2:43 PM Christian Brauner <brauner@kernel.org> wrote:
> > Allow userspace to discover what coredump modes are supported.
> >
> > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > ---
> >  fs/coredump.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/fs/coredump.c b/fs/coredump.c
> > index 9a6cba233db9..1c7428c23878 100644
> > --- a/fs/coredump.c
> > +++ b/fs/coredump.c
> > @@ -1217,6 +1217,13 @@ static int proc_dostring_coredump(const struct ctl_table *table, int write,
> >
> >  static const unsigned int core_file_note_size_min = CORE_FILE_NOTE_SIZE_DEFAULT;
> >  static const unsigned int core_file_note_size_max = CORE_FILE_NOTE_SIZE_MAX;
> > +static char core_modes[] = {
> > +#ifdef CONFIG_UNIX
> > +       "file\npipe\nunix"
> > +#else
> > +       "file\npipe"
> > +#endif
> > +};
> 
> Nit: You could do something like
> 
> static char core_modes[] =
> #ifdef CONFIG_UNIX
>   "unix\n"
> #endif
>   "file\npipe"
> ;

Thanks!