Skip to content

Commit 6fa0a72

Browse files
lituo1996Andreas Gruenbacher
authored andcommitted
gfs2: Fix possible data races in gfs2_show_options()
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->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>
1 parent c8ed1b3 commit 6fa0a72

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

fs/gfs2/super.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,14 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
10041004
{
10051005
struct gfs2_sbd *sdp = root->d_sb->s_fs_info;
10061006
struct gfs2_args *args = &sdp->sd_args;
1007-
int val;
1007+
unsigned int logd_secs, statfs_slow, statfs_quantum, quota_quantum;
1008+
1009+
spin_lock(&sdp->sd_tune.gt_spin);
1010+
logd_secs = sdp->sd_tune.gt_logd_secs;
1011+
quota_quantum = sdp->sd_tune.gt_quota_quantum;
1012+
statfs_quantum = sdp->sd_tune.gt_statfs_quantum;
1013+
statfs_slow = sdp->sd_tune.gt_statfs_slow;
1014+
spin_unlock(&sdp->sd_tune.gt_spin);
10081015

10091016
if (is_ancestor(root, sdp->sd_master_dir))
10101017
seq_puts(s, ",meta");
@@ -1059,17 +1066,14 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
10591066
}
10601067
if (args->ar_discard)
10611068
seq_puts(s, ",discard");
1062-
val = sdp->sd_tune.gt_logd_secs;
1063-
if (val != 30)
1064-
seq_printf(s, ",commit=%d", val);
1065-
val = sdp->sd_tune.gt_statfs_quantum;
1066-
if (val != 30)
1067-
seq_printf(s, ",statfs_quantum=%d", val);
1068-
else if (sdp->sd_tune.gt_statfs_slow)
1069+
if (logd_secs != 30)
1070+
seq_printf(s, ",commit=%d", logd_secs);
1071+
if (statfs_quantum != 30)
1072+
seq_printf(s, ",statfs_quantum=%d", statfs_quantum);
1073+
else if (statfs_slow)
10691074
seq_puts(s, ",statfs_quantum=0");
1070-
val = sdp->sd_tune.gt_quota_quantum;
1071-
if (val != 60)
1072-
seq_printf(s, ",quota_quantum=%d", val);
1075+
if (quota_quantum != 60)
1076+
seq_printf(s, ",quota_quantum=%d", quota_quantum);
10731077
if (args->ar_statfs_percent)
10741078
seq_printf(s, ",statfs_percent=%d", args->ar_statfs_percent);
10751079
if (args->ar_errors != GFS2_ERRORS_DEFAULT) {

0 commit comments

Comments
 (0)