]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
user namespace: fix incorrect memory barriers
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 14 Apr 2014 20:58:55 +0000 (16:58 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Apr 2014 23:49:20 +0000 (16:49 -0700)
commit0bb9d76e45e1372cad71d454ab9d0b0e0ddad440
tree93f85160a19be14c24683241b529cbbaa6a7d34e
parentf994ec5a5d8094a195c23b08d373b055ef0044aa
user namespace: fix incorrect memory barriers

commit e79323bd87808fdfbc68ce6c5371bd224d9672ee upstream.

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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/user_namespace.c