From: Jeff Layton <jlayton@kernel.org>
To: viro@zeniv.linux.org.uk, akpm@linux-foundation.org
Cc: linux-fsdevel@vger.kernel.org, sargun@sargun.me,
amir73il@gmail.com, vgoyal@redhat.com
Subject: [PATCH] vfs: protect updates to file->f_sb_err with f_lock
Date: Thu, 3 Dec 2020 14:10:35 -0500 [thread overview]
Message-ID: <20201203191035.1162408-1-jlayton@kernel.org> (raw)
When I added the ability for syncfs to report writeback errors, I
neglected to adequately protect file->f_sb_err. We could have racing
updates to that value if two tasks are issuing syncfs() on the same
fd at the same time.
Fix this by protecting the f_sb_err field with the file->f_lock.
Cc: stable@vger.kernel.org # v5.8+
Fixes: 735e4ae5ba28 ("vfs: track per-sb writeback errors and report them to syncfs")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/sync.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/sync.c b/fs/sync.c
index 1373a610dc78..3be26ff72431 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -162,7 +162,7 @@ SYSCALL_DEFINE1(syncfs, int, fd)
{
struct fd f = fdget(fd);
struct super_block *sb;
- int ret, ret2;
+ int ret, ret2 = 0;
if (!f.file)
return -EBADF;
@@ -172,7 +172,12 @@ SYSCALL_DEFINE1(syncfs, int, fd)
ret = sync_filesystem(sb);
up_read(&sb->s_umount);
- ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);
+ if (errseq_check(&sb->s_wb_err, f.file->f_sb_err)) {
+ /* Something changed, must use slow path */
+ spin_lock(&f.file->f_lock);
+ ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);
+ spin_unlock(&f.file->f_lock);
+ }
fdput(f);
return ret ? ret : ret2;
--
2.28.0
reply other threads:[~2020-12-03 19:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20201203191035.1162408-1-jlayton@kernel.org \
--to=jlayton@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sargun@sargun.me \
--cc=vgoyal@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).