From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Tuo Li <islituo@gmail.com>, BassCheck <bass@buaa.edu.cn>,
Andreas Gruenbacher <agruenba@redhat.com>,
Sasha Levin <sashal@kernel.org>,
swhiteho@redhat.com, rpeterso@redhat.com,
cluster-devel@redhat.com
Subject: [PATCH AUTOSEL 5.15 10/24] gfs2: Fix possible data races in gfs2_show_options()
Date: Sun, 23 Jul 2023 21:33:11 -0400 [thread overview]
Message-ID: <20230724013325.2332084-10-sashal@kernel.org> (raw)
In-Reply-To: <20230724013325.2332084-1-sashal@kernel.org>
From: Tuo Li <islituo@gmail.com>
[ Upstream commit 6fa0a72cbbe45db4ed967a51f9e6f4e3afe61d20 ]
Some fields such as gt_logd_secs of the struct gfs2_tune are accessed
without holding the lock gt_spin in gfs2_show_options():
val = sdp->sd_tune.gt_logd_secs;
if (val != 30)
seq_printf(s, ",commit=%d", val);
And thus can cause data races when gfs2_show_options() and other functions
such as gfs2_reconfigure() are concurrently executed:
spin_lock(>->gt_spin);
gt->gt_logd_secs = newargs->ar_commit;
To fix these possible data races, the lock sdp->sd_tune.gt_spin is
acquired before accessing the fields of gfs2_tune and released after these
accesses.
Further changes by Andreas:
- Don't hold the spin lock over the seq_printf operations.
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/gfs2/super.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index ca6ee1cbccd50..51b44da4a0d64 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -980,7 +980,14 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
{
struct gfs2_sbd *sdp = root->d_sb->s_fs_info;
struct gfs2_args *args = &sdp->sd_args;
- int val;
+ unsigned int logd_secs, statfs_slow, statfs_quantum, quota_quantum;
+
+ spin_lock(&sdp->sd_tune.gt_spin);
+ logd_secs = sdp->sd_tune.gt_logd_secs;
+ quota_quantum = sdp->sd_tune.gt_quota_quantum;
+ statfs_quantum = sdp->sd_tune.gt_statfs_quantum;
+ statfs_slow = sdp->sd_tune.gt_statfs_slow;
+ spin_unlock(&sdp->sd_tune.gt_spin);
if (is_ancestor(root, sdp->sd_master_dir))
seq_puts(s, ",meta");
@@ -1035,17 +1042,14 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
}
if (args->ar_discard)
seq_puts(s, ",discard");
- val = sdp->sd_tune.gt_logd_secs;
- if (val != 30)
- seq_printf(s, ",commit=%d", val);
- val = sdp->sd_tune.gt_statfs_quantum;
- if (val != 30)
- seq_printf(s, ",statfs_quantum=%d", val);
- else if (sdp->sd_tune.gt_statfs_slow)
+ if (logd_secs != 30)
+ seq_printf(s, ",commit=%d", logd_secs);
+ if (statfs_quantum != 30)
+ seq_printf(s, ",statfs_quantum=%d", statfs_quantum);
+ else if (statfs_slow)
seq_puts(s, ",statfs_quantum=0");
- val = sdp->sd_tune.gt_quota_quantum;
- if (val != 60)
- seq_printf(s, ",quota_quantum=%d", val);
+ if (quota_quantum != 60)
+ seq_printf(s, ",quota_quantum=%d", quota_quantum);
if (args->ar_statfs_percent)
seq_printf(s, ",statfs_percent=%d", args->ar_statfs_percent);
if (args->ar_errors != GFS2_ERRORS_DEFAULT) {
--
2.39.2
next prev parent reply other threads:[~2023-07-24 1:45 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 1:33 [PATCH AUTOSEL 5.15 01/24] media: v4l2-mem2mem: add lock to protect parameter num_rdy Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 02/24] media: camss: set VFE bpl_alignment to 16 for sdm845 and sm8250 Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 03/24] usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 04/24] media: platform: mediatek: vpu: fix NULL ptr dereference Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 05/24] thunderbolt: Read retimer NVM authentication status prior tb_retimer_set_inbound_sbtx() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 06/24] xhci: Don't require a valid get_quirks() function pointer during xhci setup Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 07/24] usb: chipidea: imx: don't request QoS for imx8ulp Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 08/24] usb: cdns2: Device side header file for CDNS2 driver Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 09/24] usb: chipidea: imx: add missing USB PHY DPDM wakeup setting Sasha Levin
2023-07-24 1:33 ` Sasha Levin [this message]
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 11/24] pcmcia: rsrc_nonstatic: Fix memory leak in nonstatic_release_resource_db() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 12/24] firewire: net: fix use after free in fwnet_finish_incoming_packet() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 13/24] watchdog: sp5100_tco: support Hygon FCH/SCH (Server Controller Hub) Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 14/24] Bluetooth: L2CAP: Fix use-after-free Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 15/24] Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_ready_cb Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 16/24] Bluetooth: btusb: Add MT7922 bluetooth ID for the Asus Ally Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 17/24] drm/amdgpu: Fix potential fence use-after-free v2 Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 18/24] fs/ntfs3: Enhance sanity check while generating attr_list Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 19/24] fs: ntfs3: Fix possible null-pointer dereferences in mi_read() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 20/24] fs/ntfs3: Use __GFP_NOWARN allocation at ntfs_load_attr_list() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 21/24] fs/ntfs3: Mark ntfs dirty when on-disk struct is corrupted Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 22/24] ALSA: hda/realtek: Add quirks for Unis H3C Desktop B760 & Q760 Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 23/24] ALSA: hda: fix a possible null-pointer dereference due to data race in snd_hdac_regmap_sync() Sasha Levin
2023-07-24 1:33 ` [PATCH AUTOSEL 5.15 24/24] apparmor: fix use of strcpy in policy_unpack_test 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=20230724013325.2332084-10-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=agruenba@redhat.com \
--cc=bass@buaa.edu.cn \
--cc=cluster-devel@redhat.com \
--cc=islituo@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rpeterso@redhat.com \
--cc=stable@vger.kernel.org \
--cc=swhiteho@redhat.com \
/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®