Skip to content

Commit

Permalink
pstore: Fix buffer overflow while write offset equal to
Browse files Browse the repository at this point in the history
 buffer size

In case new offset is equal to prz->buffer_size, it won't wrap at this
time and will return old(overflow) value next time.

Signed-off-by: Liu ShuoX <[email protected]>
Acked-by: Kees Cook <[email protected]>
Signed-off-by: Tony Luck <[email protected]>
Signed-off-by: Pranav Vashi <[email protected]>
  • Loading branch information
Liu ShuoX authored and neobuddy89 committed Jul 15, 2015
1 parent 763ddbd commit ff1279e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/pstore/ram_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static size_t buffer_start_add_atomic(struct persistent_ram_zone *prz, size_t a)
do {
old = atomic_read(&prz->buffer->start);
new = old + a;
while (unlikely(new > prz->buffer_size))
while (unlikely(new >= prz->buffer_size))
new -= prz->buffer_size;
} while (atomic_cmpxchg(&prz->buffer->start, old, new) != old);

Expand Down Expand Up @@ -91,7 +91,7 @@ static size_t buffer_start_add_locked(struct persistent_ram_zone *prz, size_t a)

old = atomic_read(&prz->buffer->start);
new = old + a;
while (unlikely(new > prz->buffer_size))
while (unlikely(new >= prz->buffer_size))
new -= prz->buffer_size;
atomic_set(&prz->buffer->start, new);

Expand Down

0 comments on commit ff1279e

Please sign in to comment.