fs/coredump: reduce redundant log noise in validate_coredump_safety
Subsystems (3)
PATCH 1/1 fs/coredump: reduce redundant log noise in validate_coredump_safety
From: Li RongQing <[email protected]>
Currently, writing to 'core_pattern' or 'suid_dumpable' sysctl nodes always triggers validate_coredump_safety(), even if the values have not changed. This results in redundant warning messages in dmesg:
"Unsafe core_pattern used with fs.suid_dumpable=2..."
This patch optimizes the procfs handlers to only invoke the safety validation when an actual change in the configuration is detected:
1. In proc_dostring_coredump(), compare the new core_pattern string with the existing one using strncmp().
2. In proc_dointvec_minmax_coredump(), check if the new suid_dumpable value differs from the previous one.
This keeps the kernel log clean from repetitive warnings when re-applying the same sysctl settings.
--- fs/coredump.c | 3 ++- fs/exec.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
fs/coredump.c +2 -1
@@ -1483,7 +1483,8 @@ static int proc_dostring_coredump(const struct ctl_table *table, int write,return -EINVAL ; } -validate_coredump_safety (); +if (strncmp (old_core_pattern, core_pattern,CORENAME_MAX_SIZE )) +validate_coredump_safety ();return error; }
fs/exec.c +4 -2
@@ -1975,9 +1975,11 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd,static int proc_dointvec_minmax_coredump (const struct ctl_table *table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -int error =proc_dointvec_minmax (table, write, buffer, lenp, ppos); +int error, old =READ_ONCE (suid_dumpable); -if (!error && write) + error =proc_dointvec_minmax (table, write, buffer, lenp, ppos); + +if (!error && write && (old !=READ_ONCE (suid_dumpable)))validate_coredump_safety ();return error; }
Signature · 1 line
2.9.4
Quoted 59 lines
From: Li RongQing <[email protected]>
Currently, writing to '
core_pattern' or 'suid_dumpable' sysctl nodes always triggersvalidate_coredump_safety(), even if the values have not changed. This results in redundant warning messages in dmesg:"Unsafe
core_patternused with fs.suid_dumpable=2..."This patch optimizes the procfs handlers to only invoke the safety validation when an actual change in the configuration is detected:
1. In
proc_dostring_coredump(), compare the newcore_patternstring with the existing one usingstrncmp().
2. Inproc_dointvec_minmax_coredump(), check if the newsuid_dumpablevalue differs from the previous one.This keeps the kernel log clean from repetitive warnings when re-applying the same sysctl settings.
Signed-off-by Li RongQing <[email protected]>--- fs/coredump.c | 3 ++- fs/exec.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)fs/coredump.c +2
-1@@ -1483,7 +1483,8 @@ static int proc_dostring_coredump(const struct ctl_table *table, int write, return -EINVAL; } -validate_coredump_safety (); +if (strncmp (old_core_pattern, core_pattern,CORENAME_MAX_SIZE )) +validate_coredump_safety ();return error; }fs/exec.c +0
-0@@ -1975,9 +1975,11 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd,static int proc_dointvec_minmax_coredump(const struct
ctl_table*table, int write,fs/exec.c +4
-3void *buffer, size_t *lenp, loff_t *ppos) { - int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + int error, old = READ_ONCE(suid_dumpable); -if (!error && write) + error =proc_dointvec_minmax (table, write, buffer, lenp, ppos); + +if (!error && write && (old !=READ_ONCE (suid_dumpable)))validate_coredump_safety ();return error; } --
Quoted 1 line
2.9.4
Ping
Thanks
[Li,Rongqing]
Christian Brauner
maintainerQuoted 16 lines · lirongqing
From: Li RongQing <[email protected]>
Currently, writing to '
core_pattern' or 'suid_dumpable' sysctl nodes always triggersvalidate_coredump_safety(), even if the values have not changed. This results in redundant warning messages in dmesg:"Unsafe
core_patternused with fs.suid_dumpable=2..."This patch optimizes the procfs handlers to only invoke the safety validation when an actual change in the configuration is detected:
1. In
proc_dostring_coredump(), compare the newcore_patternstring with the existing one usingstrncmp().
2. Inproc_dointvec_minmax_coredump(), check if the newsuid_dumpablevalue differs from the previous one.
Quoted 5 lines
This keeps the kernel log clean from repetitive warnings when re-applying the same sysctl settings.
Signed-off-by Li RongQing <[email protected]>---
That warning should very much serve as a reminder to not use that completely unsafe pattern. So no, move to newer coredump infra or use absolute paths, please.