Skip to content

Commit e7c1fe2

Browse files
jognesspmladek
authored andcommitted
printk: ringbuffer: avoid memcpy() on state_var
@state_var is copied as part of the descriptor copying via memcpy(). This is not allowed because @state_var is an atomic type, which in some implementations may contain a spinlock. Avoid using memcpy() with @state_var by explicitly copying the other fields of the descriptor. @state_var is set using atomic set operator before returning. Fixes: b6cf8b3 ("printk: add lockless ringbuffer") Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20200914094803.27365-2-john.ogness@linutronix.de
1 parent ce003d6 commit e7c1fe2

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎kernel/printk/printk_ringbuffer.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,14 @@ static enum desc_state desc_read(struct prb_desc_ring *desc_ring,
412412

413413
/*
414414
* Copy the descriptor data. The data is not valid until the
415-
* state has been re-checked.
415+
* state has been re-checked. A memcpy() for all of @desc
416+
* cannot be used because of the atomic_t @state_var field.
416417
*/
417-
memcpy(desc_out, desc, sizeof(*desc_out)); /* LMM(desc_read:C) */
418+
memcpy(&desc_out->info, &desc->info, sizeof(desc_out->info)); /* LMM(desc_read:C) */
419+
memcpy(&desc_out->text_blk_lpos, &desc->text_blk_lpos,
420+
sizeof(desc_out->text_blk_lpos)); /* also part of desc_read:C */
421+
memcpy(&desc_out->dict_blk_lpos, &desc->dict_blk_lpos,
422+
sizeof(desc_out->dict_blk_lpos)); /* also part of desc_read:C */
418423

419424
/*
420425
* 1. Guarantee the descriptor content is loaded before re-checking

0 commit comments

Comments
 (0)