From: kaber@trash.net Date: Sat, 19 Mar 2005 05:37:15 +0000 (-0800) Subject: [PATCH] Fix crash while reading /proc/net/route X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b1530aa9b161a2f9f077f075853063bece4e008;p=thirdparty%2Fkernel%2Fstable.git [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 --- 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; }