]> git.baikalelectronics.ru Git - kernel.git/commit
user namespace: fix incorrect memory barriers
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 14 Apr 2014 20:58:55 +0000 (16:58 -0400)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 14 Apr 2014 23:03:02 +0000 (16:03 -0700)
commit8014c9d4319ef77a51075d27dbfd7553b0f00e6b
tree8aeb1f4915b3474277a2b5ea9e3b9e04da88b384
parent55addf3150ef37e6b38d415547cc6f20b4d9aca1
user namespace: fix incorrect memory barriers

smp_read_barrier_depends() can be used if there is data dependency between
the readers - i.e. if the read operation after the barrier uses address
that was obtained from the read operation before the barrier.

In this file, there is only control dependency, no data dependecy, so the
use of smp_read_barrier_depends() is incorrect. The code could fail in the
following way:
* the cpu predicts that idx < entries is true and starts executing the
  body of the for loop
* the cpu fetches map->extent[0].first and map->extent[0].count
* the cpu fetches map->nr_extents
* the cpu verifies that idx < extents is true, so it commits the
  instructions in the body of the for loop

The problem is that in this scenario, the cpu read map->extent[0].first
and map->nr_extents in the wrong order. We need a full read memory barrier
to prevent it.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/user_namespace.c