Files
linux/include/linux
Qian Cai 7e23452002 percpu_counter: fix a data race at vm_committed_as
"vm_committed_as.count" could be accessed concurrently as reported by
KCSAN,

 BUG: KCSAN: data-race in __vm_enough_memory / percpu_counter_add_batch

 write to 0xffffffff9451c538 of 8 bytes by task 65879 on cpu 35:
  percpu_counter_add_batch+0x83/0xd0
  percpu_counter_add_batch at lib/percpu_counter.c:91
  __vm_enough_memory+0xb9/0x260
  dup_mm+0x3a4/0x8f0
  copy_process+0x2458/0x3240
  _do_fork+0xaa/0x9f0
  __do_sys_clone+0x125/0x160
  __x64_sys_clone+0x70/0x90
  do_syscall_64+0x91/0xb05
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

 read to 0xffffffff9451c538 of 8 bytes by task 66773 on cpu 19:
  __vm_enough_memory+0x199/0x260
  percpu_counter_read_positive at include/linux/percpu_counter.h:81
  (inlined by) __vm_enough_memory at mm/util.c:839
  mmap_region+0x1b2/0xa10
  do_mmap+0x45c/0x700
  vm_mmap_pgoff+0xc0/0x130
  ksys_mmap_pgoff+0x6e/0x300
  __x64_sys_mmap+0x33/0x40
  do_syscall_64+0x91/0xb05
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

The read is outside percpu_counter::lock critical section which results in
a data race.  Fix it by adding a READ_ONCE() in
percpu_counter_read_positive() which could also service as the existing
compiler memory barrier.

Signed-off-by: Qian Cai <cai@lca.pw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Marco Elver <elver@google.com>
Link: http://lkml.kernel.org/r/1582302724-2804-1-git-send-email-cai@lca.pw
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-07 10:43:43 -07:00
..
2020-03-31 21:29:04 +02:00
2019-09-16 09:56:27 -07:00
2019-12-11 09:12:38 +01:00
2019-11-12 11:43:29 -05:00
2020-03-17 20:48:41 +01:00
2020-03-27 12:04:34 -06:00
2018-11-07 13:44:59 -07:00
2018-11-07 13:44:59 -07:00
2020-03-30 01:34:00 +02:00
2019-06-12 20:27:13 +02:00
2020-01-23 00:35:50 +01:00
2019-10-09 19:33:43 -07:00
2020-03-09 11:12:19 +01:00
2020-02-27 14:58:01 +01:00
2019-12-03 11:20:37 +01:00
2020-02-17 13:37:00 +01:00
2019-09-05 19:52:33 -06:00
2019-02-28 03:28:53 -05:00
2020-01-27 11:09:31 +01:00
2020-01-17 16:48:07 -08:00
2020-01-18 09:19:18 -05:00
2020-03-13 12:49:51 -07:00
2018-12-19 10:42:08 +01:00
2020-03-06 11:06:15 +01:00
2019-02-15 16:54:38 +01:00
2020-03-27 20:19:24 -03:00
2019-07-05 21:34:50 +02:00
2019-06-26 13:19:46 -07:00
2019-10-04 12:31:46 -07:00
2019-10-15 13:34:25 +02:00
2018-11-19 19:03:46 -07:00
2020-03-21 16:00:24 +01:00
2019-06-10 13:00:24 +02:00
2019-12-04 19:44:14 -08:00
2020-01-31 17:33:54 +00:00
2020-02-20 21:17:24 +01:00
2019-12-11 09:12:38 +01:00
2019-09-02 11:43:54 +01:00
2019-03-07 18:32:03 -08:00
2020-03-06 11:56:59 +01:00
2020-04-07 10:43:38 -07:00
2020-04-07 10:43:39 -07:00
2019-12-09 10:55:03 +01:00
2019-08-14 15:30:35 +02:00
2020-03-21 16:00:24 +01:00
2019-11-14 19:06:47 -08:00
2018-10-17 13:56:58 -07:00
2020-01-15 10:54:33 -05:00
2020-01-14 12:20:48 +01:00
2019-06-13 09:02:33 -04:00
2019-02-20 07:22:10 -07:00
2019-02-08 15:02:49 -08:00
2019-12-11 16:37:02 +08:00
2020-04-02 09:35:27 -07:00
2020-04-07 10:43:38 -07:00
2018-10-21 10:46:39 -04:00
2019-11-13 19:09:47 +08:00
2020-01-15 16:30:28 +00:00
2019-07-16 19:23:25 -07:00
2020-03-17 18:31:05 +01:00
2019-12-06 10:47:28 +01:00
2019-06-15 12:25:49 +02:00
2020-01-13 18:16:43 -08:00
2019-11-14 13:07:48 +08:00
2020-03-21 16:00:24 +01:00
2020-02-21 10:31:18 +01:00
2020-04-07 10:43:42 -07:00
2020-03-29 21:53:18 -07:00
2019-05-16 15:51:55 -07:00
2020-02-04 03:05:24 +00:00
2020-03-21 16:00:24 +01:00
2020-03-02 14:04:31 -07:00
2019-11-13 12:15:34 -08:00
2019-02-07 16:38:35 +01:00
2020-02-04 03:05:26 +00:00
2020-03-23 13:41:55 +01:00
2020-04-02 09:35:27 -07:00
2019-07-31 19:03:35 +02:00
2020-02-21 11:22:15 -08:00
2019-01-11 18:05:40 -08:00
2020-01-14 12:20:48 +01:00
2020-03-23 17:01:47 +01:00
2020-03-21 18:56:06 -07:00
2019-11-14 12:20:02 +08:00
2019-05-15 17:35:54 +01:00
2018-12-22 12:15:29 +01:00