* [PATCH v2] blkparse: Avoid segfault for wrong cpu number.
@ 2011-05-25 15:49 Tao Ma
2011-05-26 19:11 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Tao Ma @ 2011-05-25 15:49 UTC (permalink / raw)
To: linux-btrace
From: Tao Ma <boyu.mt@taobao.com>
Currently we only check the magic number to see whether
a blktrace is valid or not, but Bill Broadley did meet
with a case that the cpu info is wrong with a number
of 1725552676. So in resize_cpu_info, we meet with a
overflow when calculating
size = new_count * sizeof(struct per_cpu_info);
And the program will be either segfault or has the error
of out of memory. Although this is more likely a kernel
problem, the blkparse shoudn't segfault for it.
So this patch just check whether the cpu stored in the
trace is the same as the file, if not, just warn it out
and skip it.
Cc: Jens Axboe <axboe@kernel.dk>
Reported-by: Bill Broadley <bill@broadley.org>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
---
blkparse.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/blkparse.c b/blkparse.c
index 7ee9f9d..817cb31 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -2354,6 +2354,12 @@ static int ms_prime(struct ms_stream *msp)
if (verify_trace(bit))
goto err;
+ if (bit->cpu != pci->cpu) {
+ fprintf(stderr, "cpu %d trace info has error cpu %d\n",
+ pci->cpu, bit->cpu);
+ continue;
+ }
+
if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY) && bit->action != BLK_TN_MESSAGE) {
handle_notify(bit);
output_binary(bit, sizeof(*bit) + bit->pdu_len);
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] blkparse: Avoid segfault for wrong cpu number.
2011-05-25 15:49 [PATCH v2] blkparse: Avoid segfault for wrong cpu number Tao Ma
@ 2011-05-26 19:11 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2011-05-26 19:11 UTC (permalink / raw)
To: linux-btrace
On 2011-05-25 17:49, Tao Ma wrote:
> From: Tao Ma <boyu.mt@taobao.com>
>
> Currently we only check the magic number to see whether
> a blktrace is valid or not, but Bill Broadley did meet
> with a case that the cpu info is wrong with a number
> of 1725552676. So in resize_cpu_info, we meet with a
> overflow when calculating
> size = new_count * sizeof(struct per_cpu_info);
> And the program will be either segfault or has the error
> of out of memory. Although this is more likely a kernel
> problem, the blkparse shoudn't segfault for it.
>
> So this patch just check whether the cpu stored in the
> trace is the same as the file, if not, just warn it out
> and skip it.
Being a bit conservative doesn't hurt. Applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-26 19:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-25 15:49 [PATCH v2] blkparse: Avoid segfault for wrong cpu number Tao Ma
2011-05-26 19:11 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).