The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 1/2] pstore: fix buffer overflow while write offset equal to buffer size
@ 2014-03-12 13:24 Liu Shuo
  2014-03-12 13:34 ` [PATCH 2/2] pstore: fix memory leak when decompress using big_oops_buf Liu Shuo
  2014-03-12 16:50 ` [PATCH 1/2] pstore: fix buffer overflow while write offset equal to buffer size Kees Cook
  0 siblings, 2 replies; 6+ messages in thread
From: Liu Shuo @ 2014-03-12 13:24 UTC (permalink / raw)
  To: LKML; +Cc: Kees Cook, Anton Vorontsov, Colin Cross, Tony Luck, Zhang Yanmin

From: Liu ShuoX <shuox.liu@intel.com>

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 <shuox.liu@intel.com>
---
 fs/pstore/ram_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index de272d4..ff7e3d4 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -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);
 
-- 
1.8.3.2




^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-17 21:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-12 13:24 [PATCH 1/2] pstore: fix buffer overflow while write offset equal to buffer size Liu Shuo
2014-03-12 13:34 ` [PATCH 2/2] pstore: fix memory leak when decompress using big_oops_buf Liu Shuo
2014-03-13  3:48   ` Kees Cook
2014-03-17 21:45     ` Tony Luck
2014-03-12 16:50 ` [PATCH 1/2] pstore: fix buffer overflow while write offset equal to buffer size Kees Cook
2014-03-13  2:18   ` Shuo Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox