]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/coredump: reduce redundant log noise in validate_coredump_safety
authorLi RongQing <lirongqing@baidu.com>
Fri, 10 Apr 2026 08:09:18 +0000 (04:09 -0400)
committerChristian Brauner <brauner@kernel.org>
Thu, 21 May 2026 11:39:33 +0000 (13:39 +0200)
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.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Link: https://patch.msgid.link/20260410080918.2319-1-lirongqing@baidu.com
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/coredump.c
fs/exec.c

index bb6fdb1f458e9b855c76b1a0f8c2e801d204b7cb..c0c919621a7aff9bcf7526e9a6feb19ad92bac68 100644 (file)
@@ -1488,7 +1488,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;
 }
 
index ba12b4c466f6daf48cdc898e59c062341e400e36..2889b7cf808d7fa2bc8da9fe83ce39007cfaf66d 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -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;
 }