diff options
author | Ahmed S. Darwish <darwish.07@gmail.com> | 2010-12-25 04:57:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-12-28 14:12:32 -0500 |
commit | 1873bb8115e678ad9fd0aac9dbbc68383bc36e06 (patch) | |
tree | 938017e949de036589035da33975257e68afed65 /drivers/char/ramoops.c | |
parent | ffc96d628b651b69b39909fc3e9e8f465df1eed3 (diff) |
RAMOOPS: Don't overflow over non-allocated regions
The current code mis-calculates the ramoops header size, leading to an
overflow over the next record at best, or over a non-allocated region at
worst. Fix that calculation.
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Acked-by: Marco Stornelli <marco.stornelli@gmail.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/ramoops.c')
-rw-r--r-- | drivers/char/ramoops.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c index 73dcb0ee41fd..d3d63be2cd37 100644 --- a/drivers/char/ramoops.c +++ b/drivers/char/ramoops.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/ramoops.h> | 29 | #include <linux/ramoops.h> |
30 | 30 | ||
31 | #define RAMOOPS_KERNMSG_HDR "====" | 31 | #define RAMOOPS_KERNMSG_HDR "====" |
32 | #define RAMOOPS_HEADER_SIZE (5 + sizeof(struct timeval)) | ||
33 | 32 | ||
34 | #define RECORD_SIZE 4096 | 33 | #define RECORD_SIZE 4096 |
35 | 34 | ||
@@ -65,8 +64,8 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
65 | struct ramoops_context, dump); | 64 | struct ramoops_context, dump); |
66 | unsigned long s1_start, s2_start; | 65 | unsigned long s1_start, s2_start; |
67 | unsigned long l1_cpy, l2_cpy; | 66 | unsigned long l1_cpy, l2_cpy; |
68 | int res; | 67 | int res, hdr_size; |
69 | char *buf; | 68 | char *buf, *buf_orig; |
70 | struct timeval timestamp; | 69 | struct timeval timestamp; |
71 | 70 | ||
72 | /* Only dump oopses if dump_oops is set */ | 71 | /* Only dump oopses if dump_oops is set */ |
@@ -74,6 +73,8 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
74 | return; | 73 | return; |
75 | 74 | ||
76 | buf = (char *)(cxt->virt_addr + (cxt->count * RECORD_SIZE)); | 75 | buf = (char *)(cxt->virt_addr + (cxt->count * RECORD_SIZE)); |
76 | buf_orig = buf; | ||
77 | |||
77 | memset(buf, '\0', RECORD_SIZE); | 78 | memset(buf, '\0', RECORD_SIZE); |
78 | res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR); | 79 | res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR); |
79 | buf += res; | 80 | buf += res; |
@@ -81,8 +82,9 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, | |||
81 | res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec); | 82 | res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec); |
82 | buf += res; | 83 | buf += res; |
83 | 84 | ||
84 | l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE)); | 85 | hdr_size = buf - buf_orig; |
85 | l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE) - l2_cpy); | 86 | l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - hdr_size)); |
87 | l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - hdr_size) - l2_cpy); | ||
86 | 88 | ||
87 | s2_start = l2 - l2_cpy; | 89 | s2_start = l2 - l2_cpy; |
88 | s1_start = l1 - l1_cpy; | 90 | s1_start = l1 - l1_cpy; |