Commit 6c191cd01a935e5b53ef43c9403c771bb7a32b60

Authored by KAMEZAWA Hiroyuki
Committed by Linus Torvalds
1 parent 61f2e7b0f4

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>

Showing 1 changed file with 14 additions and 0 deletions Side-by-side Diff

kernel/res_counter.c
... ... @@ -126,10 +126,24 @@
126 126 pos, buf, s - buf);
127 127 }
128 128  
  129 +#if BITS_PER_LONG == 32
129 130 u64 res_counter_read_u64(struct res_counter *counter, int member)
130 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
  142 +u64 res_counter_read_u64(struct res_counter *counter, int member)
  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)