[vbox-dev] [PATCH] vboxsf: Fix various issues with force_restat

Hans de Goede hdegoede at redhat.com
Wed Jan 10 06:12:12 GMT 2018


Fix various issues with force_restat:
-Use time_before to protect against jiffies wrap-around
-Clear force_restat on successful stat in sf_inode_revalidate
-In sf_lookup() clear force_restat on the new sf_inode_info,
 rather then leaving force_restat on the new sf_inode_info to whatever
 kmalloc gave us (so uninitialized) and wrongly clearing it on the
 parent directory inode
-In sf_read_super() explictly initialize force_restat to 0, rather then
 leaving force_restat on the new sf_inode_info to whatever kmalloc gave us

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 fs/vboxsf/dirops.c | 2 +-
 fs/vboxsf/utils.c  | 3 ++-
 fs/vboxsf/vfsmod.c | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/vboxsf/dirops.c b/fs/vboxsf/dirops.c
index aebb31975d5b..b6c49a089cc7 100644
--- a/fs/vboxsf/dirops.c
+++ b/fs/vboxsf/dirops.c
@@ -313,6 +313,7 @@ static struct dentry *sf_lookup(struct inode *parent, struct dentry *dentry,
 			goto fail;
 		}
 		sf_new_i->handle = SHFL_HANDLE_NIL;
+		sf_new_i->force_restat = 0;
 		sf_new_i->force_reread = 0;
 
 		ino = iunique(parent->i_sb, 1);
@@ -329,7 +330,6 @@ static struct dentry *sf_lookup(struct inode *parent, struct dentry *dentry,
 		unlock_new_inode(inode);
 	}
 
-	sf_i->force_restat = 0;
 	dentry->d_time = jiffies;
 	d_set_d_op(dentry, &sf_dentry_ops);
 	d_add(dentry, inode);
diff --git a/fs/vboxsf/utils.c b/fs/vboxsf/utils.c
index cc270457c3f7..5f91b2faa437 100644
--- a/fs/vboxsf/utils.c
+++ b/fs/vboxsf/utils.c
@@ -157,7 +157,7 @@ int sf_inode_revalidate(struct dentry *dentry)
 	sf_i = GET_INODE_INFO(dentry->d_inode);
 
 	if (!sf_i->force_restat) {
-		if (jiffies - dentry->d_time < sf_g->ttl)
+		if (time_before(jiffies, dentry->d_time + sf_g->ttl))
 			return 0;
 	}
 
@@ -166,6 +166,7 @@ int sf_inode_revalidate(struct dentry *dentry)
 		return err;
 
 	dentry->d_time = jiffies;
+	sf_i->force_restat = 0;
 	sf_init_inode(sf_g, dentry->d_inode, &info);
 	return 0;
 }
diff --git a/fs/vboxsf/vfsmod.c b/fs/vboxsf/vfsmod.c
index 9b3838b11365..1f3b4182bc0a 100644
--- a/fs/vboxsf/vfsmod.c
+++ b/fs/vboxsf/vfsmod.c
@@ -180,6 +180,7 @@ static int sf_read_super(struct super_block *sb, void *data, int flags)
 	sf_i->path->size = 2;
 	sf_i->path->string.utf8[0] = '/';
 	sf_i->path->string.utf8[1] = 0;
+	sf_i->force_restat = 0;
 	sf_i->force_reread = 0;
 
 	err = sf_stat(__func__, sf_g, sf_i->path, &fsinfo, 0);
-- 
2.14.3




More information about the vbox-dev mailing list