Skip to content

Commit fdb6a8f

Browse files
Robert RichterIngo Molnar
authored andcommitted
oprofile: fix uninitialized use of struct op_entry
Impact: fix crash In case of losing samples struct op_entry could have been used uninitialized causing e.g. a wrong preemption count or NULL pointer access. This patch fixes this. Signed-off-by: Robert Richter <robert.richter@amd.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent c903ff8 commit fdb6a8f

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎drivers/oprofile/cpu_buffer.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,21 @@ oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
393393
return;
394394

395395
fail:
396+
entry->event = NULL;
396397
cpu_buf->sample_lost_overflow++;
397398
}
398399

399400
int oprofile_add_data(struct op_entry *entry, unsigned long val)
400401
{
402+
if (!entry->event)
403+
return 0;
401404
return op_cpu_buffer_add_data(entry, val);
402405
}
403406

404407
int oprofile_write_commit(struct op_entry *entry)
405408
{
409+
if (!entry->event)
410+
return -EINVAL;
406411
return op_cpu_buffer_write_commit(entry);
407412
}
408413

‎drivers/oprofile/cpu_buffer.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ static inline void op_cpu_buffer_reset(int cpu)
6666
cpu_buf->last_task = NULL;
6767
}
6868

69+
/*
70+
* op_cpu_buffer_add_data() and op_cpu_buffer_write_commit() may be
71+
* called only if op_cpu_buffer_write_reserve() did not return NULL or
72+
* entry->event != NULL, otherwise entry->size or entry->event will be
73+
* used uninitialized.
74+
*/
75+
6976
struct op_sample
7077
*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
7178
int op_cpu_buffer_write_commit(struct op_entry *entry);

0 commit comments

Comments
 (0)