From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jann Horn <jannh@google.com>, Al Viro <viro@zeniv.linux.org.uk>,
Sasha Levin <sashal@kernel.org>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 07/24] fs: use acquire ordering in __fget_light()
Date: Mon, 28 Nov 2022 12:40:07 -0500 [thread overview]
Message-ID: <20221128174027.1441921-7-sashal@kernel.org> (raw)
In-Reply-To: <20221128174027.1441921-1-sashal@kernel.org>
From: Jann Horn <jannh@google.com>
[ 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 | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/fs/file.c b/fs/file.c
index ee9317346702..214364e19d76 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -1029,7 +1029,16 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
struct files_struct *files = current->files;
struct file *file;
- if (atomic_read(&files->count) == 1) {
+ /*
+ * If another thread is concurrently calling close_fd() followed
+ * by put_files_struct(), we must not observe the old table
+ * entry combined with the new refcount - otherwise we could
+ * return a file that is concurrently being freed.
+ *
+ * atomic_read_acquire() pairs with atomic_dec_and_test() in
+ * put_files_struct().
+ */
+ if (atomic_read_acquire(&files->count) == 1) {
file = files_lookup_fd_raw(files, fd);
if (!file || unlikely(file->f_mode & mask))
return 0;
--
2.35.1
next prev parent reply other threads:[~2022-11-28 17:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 17:40 [PATCH AUTOSEL 5.15 01/24] arm64: dts: rockchip: keep I2S1 disabled for GPIO function on ROCK Pi 4 series Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 02/24] arm: dts: rockchip: fix node name for hym8563 rtc Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 03/24] arm: dts: rockchip: remove clock-frequency from rtc Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 04/24] ARM: dts: rockchip: fix ir-receiver node names Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 05/24] arm64: " Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 06/24] ARM: dts: rockchip: rk3188: fix lcdc1-rgb24 node name Sasha Levin
2022-11-28 17:40 ` Sasha Levin [this message]
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 08/24] ARM: 9251/1: perf: Fix stacktraces for tracepoint events in THUMB2 kernels Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 09/24] ARM: 9266/1: mm: fix no-MMU ZERO_PAGE() implementation Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 10/24] ASoC: wm8962: Wait for updated value of WM8962_CLOCKING1 register Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 11/24] spi: mediatek: Fix DEVAPC Violation at KO Remove Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 12/24] ARM: dts: rockchip: disable arm_global_timer on rk3066 and rk3188 Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 13/24] ASoC: rt711-sdca: fix the latency time of clock stop prepare state machine transitions Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 14/24] 9p/fd: Use P9_HDRSZ for header size Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 15/24] regulator: slg51000: Wait after asserting CS pin Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 16/24] ALSA: seq: Fix function prototype mismatch in snd_seq_expand_var_event Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 17/24] selftests/net: Find nettest in current directory Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 18/24] btrfs: send: avoid unaligned encoded writes when attempting to clone range Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 19/24] ASoC: soc-pcm: Add NULL check in BE reparenting Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 20/24] regulator: twl6030: fix get status of twl6032 regulators Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 21/24] fbcon: Use kzalloc() in fbcon_prepare_logo() Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 22/24] usb: dwc3: gadget: Disable GUSB2PHYCFG.SUSPHY for End Transfer Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 23/24] 9p/xen: check logical size for buffer size Sasha Levin
2022-11-28 17:40 ` [PATCH AUTOSEL 5.15 24/24] net: usb: qmi_wwan: add u-blox 0x1342 composition Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221128174027.1441921-7-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®