]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
coredump: Use __counted_by_ptr for struct core_name::corename
authorKees Cook <kees@kernel.org>
Mon, 20 Oct 2025 22:01:17 +0000 (15:01 -0700)
committerKees Cook <kees@kernel.org>
Sat, 17 Jan 2026 19:00:37 +0000 (11:00 -0800)
Use the __counted_by annotation now available for struct pointer
members, __counted_by_ptr(). Move assignments to immediately
after allocation.

Link: https://patch.msgid.link/20251020220118.1226740-3-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
fs/coredump.c

index 8feb9c1cf83db357aa83c8db6369bfecf1f3355c..c7f75042831a9cb19ed55bdd485f9226bc761b91 100644 (file)
@@ -92,7 +92,7 @@ enum coredump_type_t {
 };
 
 struct core_name {
-       char *corename;
+       char *corename __counted_by_ptr(size);
        int used, size;
        unsigned int core_pipe_limit;
        bool core_dumped;
@@ -106,15 +106,15 @@ static int expand_corename(struct core_name *cn, int size)
 
        size = kmalloc_size_roundup(size);
        corename = krealloc(cn->corename, size, GFP_KERNEL);
-
        if (!corename)
                return -ENOMEM;
 
+       cn->corename = corename;
+       cn->size = size;
+
        if (size > core_name_size) /* racy but harmless */
                core_name_size = size;
 
-       cn->size = size;
-       cn->corename = corename;
        return 0;
 }