proc: loadavg reading race
PATCH 1/1 proc: loadavg reading race
The avenrun[] values are supposed to be protected by xtime_lock. loadavg_read_proc does not use it. Theoretically this may result in an occasional glitch when the value read from /proc/loadavg would be as much as 1<<11 times higher than it should be.
Signed-off-by Michal Schmidt <[email protected]>
--- fs/proc/proc_misc.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
fs/proc/proc_misc.c +8 -3
@@ -83,10 +83,15 @@ static int loadavg_read_proc(char *page, char **start, off_t off, {int a, b, c;int len; +unsigned long seq; + +do { + seq =read_seqbegin (&xtime_lock); + a = avenrun[0 ] + (FIXED_1 /200 ); + b = avenrun[1 ] + (FIXED_1 /200 ); + c = avenrun[2 ] + (FIXED_1 /200 ); + }while (read_seqretry (&xtime_lock, seq)); - a = avenrun[0 ] + (FIXED_1 /200 ); - b = avenrun[1 ] + (FIXED_1 /200 ); - c = avenrun[2 ] + (FIXED_1 /200 ); len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n", LOAD_INT(a), LOAD_FRAC(a), LOAD_INT(b), LOAD_FRAC(b),
Signature · 1 line
1.5.3.3