ftrace: unsigned idx cannot be less than 0
PATCH 1/1 ftrace: unsigned idx cannot be less than 0
// vi kernel/trace/ftrace.c +787
struct ftrace_iterator {
...
unsigned idx;
...
};
idx is unsigned and cannot be less than 0.
---
kernel/trace/ftrace.c +1 -1
@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;
Quoted 16 lines · Roel Kluin
// vi
kernel/trace/ftrace.c+787
structftrace_iterator{
...unsigned idx;...
};idx is unsigned and cannot be less than 0.
Signed-off-by Roel Kluin <[email protected]>---
kernel/trace/ftrace.c +0
-0
kernel/trace/ftrace.c static void *t_start(struct seq_file *m, loff_t *pos) · line 848
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;
Hi Roel,
I'm not sure this is the right fix.
If you look at t_next, if there is no more page to look at, iter_idx takes -1.
A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 29 lines · Frederic Weisbecker
Quoted 16 lines · Roel Kluin
// vi
kernel/trace/ftrace.c+787
structftrace_iterator{
...unsigned idx;...
};idx is unsigned and cannot be less than 0.
Signed-off-by Roel Kluin <[email protected]>---
kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c static void *t_start(struct seq_file *m, loff_t *pos) · line 848
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;Hi Roel,
Quoted 8 lines
I'm not sure this is the right fix.
If you look att_next, if there is no more page to look at,iter_idxtakes -1.A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
If we turn idx in a signed int, isn't it true that in kernel/trace/ftrace.c, line 806:
retry:
if (iter->idx >= iter->pg->index) {
...
} else {
iter->idx++;
if ( a certain rec-> and iter->flags )
goto retry;
}since iter->pg->index is an unsigned long, when larger than INT_MAX this could result in an endless loop?
Roel
Quoted 51 lines · Roel Kluin
Quoted 29 lines · Frederic Weisbecker
Quoted 16 lines · Roel Kluin
// vi
kernel/trace/ftrace.c+787
structftrace_iterator{
...unsigned idx;...
};idx is unsigned and cannot be less than 0.
Signed-off-by Roel Kluin <[email protected]>---
kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c static void *t_start(struct seq_file *m, loff_t *pos) · line 848
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;Hi Roel,
Quoted 8 lines
I'm not sure this is the right fix.
If you look att_next, if there is no more page to look at,iter_idxtakes -1.A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
If we turn idx in a signed int, isn't it true that in
kernel/trace/ftrace.c, line 806:retry:
if (iter->idx >= iter->pg->index) { ... } else { iter->idx++; if ( a certain rec-> and iter->flags ) goto retry; }
Quoted 4 lines
since
iter->pg->indexis an unsigned long, when larger thanINT_MAXthis could result in an endless loop?Roel
Actually, this is not supposed to reach such a threshold. Looks like it wouldn't increase over ENTRIES_PER_PAGE (defined in ftrace.c) which is smaller than PAGE_SIZE.
So it will stay far from an overflow.
I don't think this type conversion would be an issue. But perhaps there are other things that I don't see.
PATCH v2 1/1 ftrace: unsigned idx cannot be less than 0
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- if (iter->idx < 0) + if (iter->idx == 0)I'm not sure this is the right fix.
If you look att_next, if there is no more page to look at,iter_idxtakes -1.A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
If we turn idx in a signed int, isn't it true that in
kernel/trace/ftrace.c, line 806:
Quoted 7 lines
Quoted 2 lines
since
iter->pg->indexis an unsigned long, when larger thanINT_MAXthis could result in an endless loop?Actually, this is not supposed to reach such a threshold. Looks like it wouldn't increase over
ENTRIES_PER_PAGE(defined inftrace.c) which is smaller thanPAGE_SIZE.
So it will stay far from an overflow.
unless signed idx cannot become less than 0
---
kernel/trace/ftrace.c +1 -1
@@ -786,7 +786,7 @@ enum {struct ftrace_iterator {struct ftrace_page *pg; -unsigned idx; +int idx;unsigned flags;unsigned char buffer[FTRACE_BUFF_MAX +1 ];unsigned buffer_idx;
Steven Rostedt
maintainer[ added Liming to CC ]
Quoted 29 lines · Frederic Weisbecker
Quoted 16 lines · Roel Kluin
// vi
kernel/trace/ftrace.c+787
structftrace_iterator{
...unsigned idx;...
};idx is unsigned and cannot be less than 0.
Signed-off-by Roel Kluin <[email protected]>---
kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c static void *t_start(struct seq_file *m, loff_t *pos) · line 848
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;Hi Roel,
Quoted 8 lines
I'm not sure this is the right fix.
If you look att_next, if there is no more page to look at,iter_idxtakes -1.A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
Correct. This bug was added by:
50cdaf08a8ec1d7f43987705da7aff7cf949708f
ftrace: improve seq_operation of ftrace
So the correct fix is to turn it into a signed int.
Thanks,
-- Steve
2009/1/6 Steven Rostedt <[email protected]>:
Quoted 45 lines
[ added Liming to CC ]
Quoted 29 lines · Frederic Weisbecker
Quoted 16 lines · Roel Kluin
// vi
kernel/trace/ftrace.c+787
structftrace_iterator{
...unsigned idx;...
};idx is unsigned and cannot be less than 0.
Signed-off-by Roel Kluin <[email protected]>---
kernel/trace/ftrace.c +0
-0kernel/trace/ftrace.c static void *t_start(struct seq_file *m, loff_t *pos) · line 848
Quoted 8 lines
kernel/trace/ftrace.c +1
-1@@ -842,7 +842,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)void *p =NULL ;if (*pos >0 ) { -if (iter->idx <0 ) +if (iter->idx ==0 )return p; (*pos)--; iter->idx--;Hi Roel,
Quoted 8 lines
I'm not sure this is the right fix.
If you look att_next, if there is no more page to look at,iter_idxtakes -1.A 0 value would mean: we are in the first index on the page, which means there is something to read and we don't want to return NULL.
I guess that would be better to turn idx into a signed int.
Correct. This bug was added by:
Quoted 9 lines
50cdaf08a8ec1d7f43987705da7aff7cf949708f
ftrace: improveseq_operationof ftraceSo the correct fix is to turn it into a signed int.
Thanks,
-- Steve
Both iter->idx and pg->index should be signed int I guess.
Roel is perhaps right, I don't know how is caught an unsigned long when compared with a signed int if
this int is less than 0.