Skip to content

Commit a728ce8

Browse files
Xichao Zhaokees
authored andcommitted
binfmt_elf: Replace offsetof() with struct_size() in fill_note_info()
When dealing with structures containing flexible arrays, struct_size() provides additional compile-time checks compared to offsetof(). This enhances code robustness and reduces the risk of potential errors. Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com> Link: https://lore.kernel.org/r/20250813115058.635742-1-zhao.xichao@vivo.com Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 5e08824 commit a728ce8

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

fs/binfmt_elf.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,16 +1845,14 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
18451845
/*
18461846
* Allocate a structure for each thread.
18471847
*/
1848-
info->thread = kzalloc(offsetof(struct elf_thread_core_info,
1849-
notes[info->thread_notes]),
1850-
GFP_KERNEL);
1848+
info->thread = kzalloc(struct_size(info->thread, notes, info->thread_notes),
1849+
GFP_KERNEL);
18511850
if (unlikely(!info->thread))
18521851
return 0;
18531852

18541853
info->thread->task = dump_task;
18551854
for (ct = dump_task->signal->core_state->dumper.next; ct; ct = ct->next) {
1856-
t = kzalloc(offsetof(struct elf_thread_core_info,
1857-
notes[info->thread_notes]),
1855+
t = kzalloc(struct_size(t, notes, info->thread_notes),
18581856
GFP_KERNEL);
18591857
if (unlikely(!t))
18601858
return 0;

0 commit comments

Comments
 (0)