Skip to content

Commit

Permalink
oprofile: fix uninitialized use of struct op_entry
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Robert Richter authored and Ingo Molnar committed Jan 17, 2009
1 parent c903ff8 commit fdb6a8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/oprofile/cpu_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,21 @@ oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
return;

fail:
entry->event = NULL;
cpu_buf->sample_lost_overflow++;
}

int oprofile_add_data(struct op_entry *entry, unsigned long val)
{
if (!entry->event)
return 0;
return op_cpu_buffer_add_data(entry, val);
}

int oprofile_write_commit(struct op_entry *entry)
{
if (!entry->event)
return -EINVAL;
return op_cpu_buffer_write_commit(entry);
}

Expand Down
7 changes: 7 additions & 0 deletions drivers/oprofile/cpu_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ static inline void op_cpu_buffer_reset(int cpu)
cpu_buf->last_task = NULL;
}

/*
* op_cpu_buffer_add_data() and op_cpu_buffer_write_commit() may be
* called only if op_cpu_buffer_write_reserve() did not return NULL or
* entry->event != NULL, otherwise entry->size or entry->event will be
* used uninitialized.
*/

struct op_sample
*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
int op_cpu_buffer_write_commit(struct op_entry *entry);
Expand Down

0 comments on commit fdb6a8f

Please sign in to comment.