linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-unionfs@vger.kernel.org
Subject: [PATCH 1/4] ovl: protect copying of realinode attributes to ovl inode
Date: Tue, 12 Sep 2023 20:36:50 +0300	[thread overview]
Message-ID: <20230912173653.3317828-2-amir73il@gmail.com> (raw)
In-Reply-To: <20230912173653.3317828-1-amir73il@gmail.com>

ovl_copyattr() may be called concurrently from aio completion context
without any lock and that could lead to overlay inode attributes getting
permanently out of sync with real inode attributes.

Similarly, ovl_file_accessed() is always called without any lock to do
"compare & copy" of mtime/ctime from realinode to inode.

Use ovl inode spinlock to protect those two helpers.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/file.c | 2 ++
 fs/overlayfs/util.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 4193633c4c7a..c6ad84cf9246 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -249,6 +249,7 @@ static void ovl_file_accessed(struct file *file)
 	if (!upperinode)
 		return;
 
+	spin_lock(&inode->i_lock);
 	ctime = inode_get_ctime(inode);
 	uctime = inode_get_ctime(upperinode);
 	if ((!timespec64_equal(&inode->i_mtime, &upperinode->i_mtime) ||
@@ -256,6 +257,7 @@ static void ovl_file_accessed(struct file *file)
 		inode->i_mtime = upperinode->i_mtime;
 		inode_set_ctime_to_ts(inode, uctime);
 	}
+	spin_unlock(&inode->i_lock);
 
 	touch_atime(&file->f_path);
 }
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 89e0d60d35b6..b7922862ece3 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -1403,6 +1403,7 @@ void ovl_copyattr(struct inode *inode)
 	realinode = ovl_i_path_real(inode, &realpath);
 	real_idmap = mnt_idmap(realpath.mnt);
 
+	spin_lock(&inode->i_lock);
 	vfsuid = i_uid_into_vfsuid(real_idmap, realinode);
 	vfsgid = i_gid_into_vfsgid(real_idmap, realinode);
 
@@ -1413,4 +1414,5 @@ void ovl_copyattr(struct inode *inode)
 	inode->i_mtime = realinode->i_mtime;
 	inode_set_ctime_to_ts(inode, inode_get_ctime(realinode));
 	i_size_write(inode, i_size_read(realinode));
+	spin_unlock(&inode->i_lock);
 }
-- 
2.34.1


  reply	other threads:[~2023-09-12 17:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 17:36 [PATCH 0/4] Overlayfs aio cleanups Amir Goldstein
2023-09-12 17:36 ` Amir Goldstein [this message]
2023-09-24  9:28   ` [PATCH 1/4] ovl: protect copying of realinode attributes to ovl inode Amir Goldstein
2023-09-26 21:17     ` Amir Goldstein
2023-10-01 14:11       ` Amir Goldstein
2023-09-12 17:36 ` [PATCH 2/4] ovl: use simpler function to convert iocb to rw flags Amir Goldstein
2023-09-12 17:36 ` [PATCH 3/4] ovl: propagate IOCB_APPEND flag on writes to realfile Amir Goldstein
2023-09-12 17:36 ` [PATCH 4/4] ovl: move ovl_file_accessed() to aio completion Amir Goldstein
2023-09-28  5:11   ` Amir Goldstein

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=20230912173653.3317828-2-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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).