From 1b1530aa9b161a2f9f077f075853063bece4e008 Mon Sep 17 00:00:00 2001 From: "kaber@trash.net" Date: Fri, 18 Mar 2005 21:37:15 -0800 Subject: [PATCH] [PATCH] Fix crash while reading /proc/net/route [IPV4]: Fix crash while reading /proc/net/route caused by stale pointers Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller Signed-off-by: Chris Wright Signed-off-by: Greg Kroah-Hartman --- net/ipv4/fib_hash.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c index 1bf3844dfa423..40d792a0546d8 100644 --- a/net/ipv4/fib_hash.c +++ b/net/ipv4/fib_hash.c @@ -919,13 +919,23 @@ out: return fa; } +static struct fib_alias *fib_get_idx(struct seq_file *seq, loff_t pos) +{ + struct fib_alias *fa = fib_get_first(seq); + + if (fa) + while (pos && (fa = fib_get_next(seq))) + --pos; + return pos ? NULL : fa; +} + static void *fib_seq_start(struct seq_file *seq, loff_t *pos) { void *v = NULL; read_lock(&fib_hash_lock); if (ip_fib_main_table) - v = *pos ? fib_get_next(seq) : SEQ_START_TOKEN; + v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; return v; } -- 2.47.2