Skip to content

Commit fac4ab5

Browse files
committed
coredump: Use __counted_by_ptr for struct core_name::corename
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>
1 parent a120a83 commit fac4ab5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

fs/coredump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ enum coredump_type_t {
9292
};
9393

9494
struct core_name {
95-
char *corename;
95+
char *corename __counted_by_ptr(size);
9696
int used, size;
9797
unsigned int core_pipe_limit;
9898
bool core_dumped;
@@ -106,15 +106,15 @@ static int expand_corename(struct core_name *cn, int size)
106106

107107
size = kmalloc_size_roundup(size);
108108
corename = krealloc(cn->corename, size, GFP_KERNEL);
109-
110109
if (!corename)
111110
return -ENOMEM;
112111

112+
cn->corename = corename;
113+
cn->size = size;
114+
113115
if (size > core_name_size) /* racy but harmless */
114116
core_name_size = size;
115117

116-
cn->size = size;
117-
cn->corename = corename;
118118
return 0;
119119
}
120120

0 commit comments

Comments
 (0)