diff options
author | Liu ShuoX <shuox.liu@intel.com> | 2014-03-12 09:24:44 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2014-03-17 17:14:03 -0400 |
commit | 017321cf390045dd4c4afc4a232995ea50bcf66d (patch) | |
tree | c7ce8487792ba20f6e07d3320e4985e331fbf921 /fs/pstore | |
parent | 34f0ec82e0a99009161a281629280cfcad187696 (diff) |
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: Liu ShuoX <shuox.liu@intel.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'fs/pstore')
-rw-r--r-- | fs/pstore/ram_core.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index de272d426763..ff7e3d4df5a1 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) | |||
54 | do { | 54 | do { |
55 | old = atomic_read(&prz->buffer->start); | 55 | old = atomic_read(&prz->buffer->start); |
56 | new = old + a; | 56 | new = old + a; |
57 | while (unlikely(new > prz->buffer_size)) | 57 | while (unlikely(new >= prz->buffer_size)) |
58 | new -= prz->buffer_size; | 58 | new -= prz->buffer_size; |
59 | } while (atomic_cmpxchg(&prz->buffer->start, old, new) != old); | 59 | } while (atomic_cmpxchg(&prz->buffer->start, old, new) != old); |
60 | 60 | ||
@@ -91,7 +91,7 @@ static size_t buffer_start_add_locked(struct persistent_ram_zone *prz, size_t a) | |||
91 | 91 | ||
92 | old = atomic_read(&prz->buffer->start); | 92 | old = atomic_read(&prz->buffer->start); |
93 | new = old + a; | 93 | new = old + a; |
94 | while (unlikely(new > prz->buffer_size)) | 94 | while (unlikely(new >= prz->buffer_size)) |
95 | new -= prz->buffer_size; | 95 | new -= prz->buffer_size; |
96 | atomic_set(&prz->buffer->start, new); | 96 | atomic_set(&prz->buffer->start, new); |
97 | 97 | ||