From: aburford Date: Fri, 6 May 2022 15:44:36 +0000 (-0400) Subject: add andrew-bugfix.patch X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=cea418b8c3aa92bfc4629cc6a02e8509407e54dd;p=wrapfs-mgmt.git add andrew-bugfix.patch --- diff --git a/andrew-bugfix.patch b/andrew-bugfix.patch new file mode 100644 index 0000000..89c5355 --- /dev/null +++ b/andrew-bugfix.patch @@ -0,0 +1,139 @@ +From 7bdf1ffeeda07fd960783e56449dd057d3cd2781 Mon Sep 17 00:00:00 2001 +From: aburford +Date: Thu, 28 Apr 2022 16:03:46 -0400 +Subject: [PATCH 1/2] fix error handling in wrapfs_read_super + +--- + fs/wrapfs/dentry.c | 8 +++++--- + fs/wrapfs/main.c | 20 +++++--------------- + 2 files changed, 10 insertions(+), 18 deletions(-) + +diff --git a/fs/wrapfs/dentry.c b/fs/wrapfs/dentry.c +index d17d063..507dce4 100644 +--- a/fs/wrapfs/dentry.c ++++ b/fs/wrapfs/dentry.c +@@ -34,9 +34,11 @@ static int wrapfs_d_revalidate(struct dentry *dentry, unsigned int flags) + + static void wrapfs_d_release(struct dentry *dentry) + { +- /* release and reset the lower paths */ +- wrapfs_put_reset_lower_path(dentry); +- free_dentry_private_data(dentry); ++ if (WRAPFS_D(dentry)) { ++ /* release and reset the lower paths */ ++ wrapfs_put_reset_lower_path(dentry); ++ free_dentry_private_data(dentry); ++ } + return; + } + +diff --git a/fs/wrapfs/main.c b/fs/wrapfs/main.c +index daf1758..f0cbf30 100644 +--- a/fs/wrapfs/main.c ++++ b/fs/wrapfs/main.c +@@ -42,7 +42,7 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent) + if (!WRAPFS_SB(sb)) { + printk(KERN_CRIT "wrapfs: read_super: out of memory\n"); + err = -ENOMEM; +- goto out_free; ++ goto out_pput; + } + + /* set the lower superblock field of upper superblock */ +@@ -68,12 +68,12 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent) + inode = wrapfs_iget(sb, d_inode(lower_path.dentry)); + if (IS_ERR(inode)) { + err = PTR_ERR(inode); +- goto out_sput; ++ goto out_pput; + } + sb->s_root = d_make_root(inode); + if (!sb->s_root) { + err = -ENOMEM; +- goto out_iput; ++ goto out_pput; + } + d_set_d_op(sb->s_root, &wrapfs_dops); + +@@ -81,7 +81,7 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent) + sb->s_root->d_fsdata = NULL; + err = new_dentry_private_data(sb->s_root); + if (err) +- goto out_freeroot; ++ goto out_pput; + + /* if get here: cannot have error */ + +@@ -101,18 +101,8 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent) + goto out; /* all is well */ + + /* no longer needed: free_dentry_private_data(sb->s_root); */ +-out_freeroot: +- dput(sb->s_root); +-out_iput: +- iput(inode); +-out_sput: +- /* drop refs we took earlier */ +- atomic_dec(&lower_sb->s_active); +- kfree(WRAPFS_SB(sb)); +- sb->s_fs_info = NULL; +-out_free: ++out_pput: + path_put(&lower_path); +- + out: + return err; + } +-- +2.7.4 + + +From e225135ad17e5f257c9b1eea16c55066db1a335a Mon Sep 17 00:00:00 2001 +From: aburford +Date: Mon, 2 May 2022 10:57:56 -0400 +Subject: [PATCH 2/2] add clarifying comments + +--- + fs/wrapfs/dentry.c | 6 ++++++ + fs/wrapfs/main.c | 8 +++++++- + 2 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/fs/wrapfs/dentry.c b/fs/wrapfs/dentry.c +index 507dce4..dc7e6e6 100644 +--- a/fs/wrapfs/dentry.c ++++ b/fs/wrapfs/dentry.c +@@ -34,6 +34,12 @@ static int wrapfs_d_revalidate(struct dentry *dentry, unsigned int flags) + + static void wrapfs_d_release(struct dentry *dentry) + { ++ /* ++ * It is possible that the dentry private data is null ++ * incase we ran out of memory while initializing it in ++ * new_dentry_private_data. So check for NULL before ++ * attempting to release resources ++ */ + if (WRAPFS_D(dentry)) { + /* release and reset the lower paths */ + wrapfs_put_reset_lower_path(dentry); +diff --git a/fs/wrapfs/main.c b/fs/wrapfs/main.c +index f0cbf30..bb14ac3 100644 +--- a/fs/wrapfs/main.c ++++ b/fs/wrapfs/main.c +@@ -100,7 +100,13 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent) + dev_name, lower_sb->s_type->name); + goto out; /* all is well */ + +- /* no longer needed: free_dentry_private_data(sb->s_root); */ ++ /* ++ * path_put is the only resource we need to free if an error ++ * occured because returning an error from this function will ++ * cause generic_shutdown_super to be called which will call ++ * wrapfs_put_super and that function will release any other ++ * resources we took. ++ */ + out_pput: + path_put(&lower_path); + out: +-- +2.7.4 +