From d4599fc7b5979e28003b971008d78d140bda97de Mon Sep 17 00:00:00 2001 From: aburford Date: Sat, 14 May 2022 20:05:15 -0400 Subject: [PATCH] add patch for self-stacking --- bug-fixes/andrew-fix-self-stack.log | 9 +++++++++ bug-fixes/andrew-fix-self-stack.patch | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 bug-fixes/andrew-fix-self-stack.log create mode 100644 bug-fixes/andrew-fix-self-stack.patch diff --git a/bug-fixes/andrew-fix-self-stack.log b/bug-fixes/andrew-fix-self-stack.log new file mode 100644 index 0000000..69d245f --- /dev/null +++ b/bug-fixes/andrew-fix-self-stack.log @@ -0,0 +1,9 @@ +Wrapfs: fix NULL pointer dereference when stacking wrapfs on top of itself. + +Wrapfs assumes that the d_fsdata field has already been initialized whenever +it is passed one of its own dentries, but it doesn't give the lower fs a chance +to allocate their d_fsdata field when it creates a new lower_dentry. This is +fixed by simply replacing a call to d_add in __wrapfs_lookup with a call to +->lookup on the lower fs inode. + +Signed-off-by: Andrew Burford diff --git a/bug-fixes/andrew-fix-self-stack.patch b/bug-fixes/andrew-fix-self-stack.patch new file mode 100644 index 0000000..46d3dc5 --- /dev/null +++ b/bug-fixes/andrew-fix-self-stack.patch @@ -0,0 +1,20 @@ +diff --git a/fs/wrapfs/lookup.c b/fs/wrapfs/lookup.c +index 7c78d5a..b166c0e 100644 +--- a/fs/wrapfs/lookup.c ++++ b/fs/wrapfs/lookup.c +@@ -260,7 +260,14 @@ static struct dentry *__wrapfs_lookup(struct dentry *dentry, + err = -ENOMEM; + goto out; + } +- d_add(lower_dentry, NULL); /* instantiate and hash */ ++ ++ /* ++ * Calling ->lookup instead of d_add will give the lower fs a chance ++ * to allocate the d_fsdata field but will still instantiate and hash the ++ * lower_dentry. Without this, wrapfs could not stack on top of itself. ++ */ ++ d_inode(lower_dir_dentry) ++ ->i_op->lookup(d_inode(lower_dir_dentry), lower_dentry, flags); + + setup_lower: + lower_path.dentry = lower_dentry; -- 2.34.1