Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memcg: res_counter_read_u64(): fix potential races on 32-bit machines

res_counter_read_u64 reads u64 value without lock. It's dangerous in a
32bit environment. Add locking.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

KAMEZAWA Hiroyuki and committed by
Linus Torvalds
6c191cd0 61f2e7b0

+14
+14
kernel/res_counter.c
··· 126 126 pos, buf, s - buf); 127 127 } 128 128 129 + #if BITS_PER_LONG == 32 130 + u64 res_counter_read_u64(struct res_counter *counter, int member) 131 + { 132 + unsigned long flags; 133 + u64 ret; 134 + 135 + spin_lock_irqsave(&counter->lock, flags); 136 + ret = *res_counter_member(counter, member); 137 + spin_unlock_irqrestore(&counter->lock, flags); 138 + 139 + return ret; 140 + } 141 + #else 129 142 u64 res_counter_read_u64(struct res_counter *counter, int member) 130 143 { 131 144 return *res_counter_member(counter, member); 132 145 } 146 + #endif 133 147 134 148 int res_counter_memparse_write_strategy(const char *buf, 135 149 unsigned long long *res)