Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 017321cf authored by Liu ShuoX's avatar Liu ShuoX Committed by Tony Luck
Browse files

pstore: Fix buffer overflow while write offset equal to 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: default avatarLiu ShuoX <shuox.liu@intel.com>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
parent 34f0ec82
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);

@@ -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);