fs: use acquire ordering in __fget_light()
authorJann Horn <jannh@google.com>
Mon, 31 Oct 2022 17:52:56 +0000 (18:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Dec 2022 10:37:15 +0000 (11:37 +0100)
commit66717ad03b80802752c9931afeedfcbd6806a8c2
treec5e568b8ded0ad092e7b7655cc8d4b3cdb7c183a
parent1222e2364ac7e608c3bc5a87f5ed288357f397ad
fs: use acquire ordering in __fget_light()

[ Upstream commit 7ee47dcfff1835ff75a794d1075b6b5f5462cfed ]

We must prevent the CPU from reordering the files->count read with the
FD table access like this, on architectures where read-read reordering is
possible:

    files_lookup_fd_raw()
                                  close_fd()
                                  put_files_struct()
    atomic_read(&files->count)

I would like to mark this for stable, but the stable rules explicitly say
"no theoretical races", and given that the FD table pointer and
files->count are explicitly stored in the same cacheline, this sort of
reordering seems quite unlikely in practice...

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/file.c