Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69e29d1c authored by Ritesh Harjani's avatar Ritesh Harjani
Browse files

sdcardfs: Fix a case where sdcardfs may fail to create a file



Test case:-
1. touch <sdcardfs-path>/file1
2. In parallel keep dropping the caches.

In below sequence:-
1. __sdcardfs_lookup
2. vfs_path_lookup   --> returns -ENOENT(since file is not yet present)
3. d_hash_lookup     --> if returned NULL, then sdcardfs returns NULL

In above sequence of events, sdcardfs has not taken any ref count
on lower_dentry while doing vfs_path_lookup.
If in case like during low memory situation, if shrink_dcache is invoked
then it will remove the dentry from lookup cache.
Now when sdcardfs searches for d_hash_lookup, it could not find the
dentry and assumes that lower FS did not create it and hence returns and
error.

To fix this, it should again go via lookup_one_len_unlocked call
to see if dentry is really present or not.

Change-Id: I58e73e39605bfd5e81dffd878701d3f744514c05
Signed-off-by: default avatarRitesh Harjani <riteshh@codeaurora.org>
parent 4c314540
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -369,18 +369,13 @@ static struct dentry *__sdcardfs_lookup(struct dentry *dentry,
	/* See if the low-level filesystem might want
	 * to use its own hash
	 */
	lower_dentry = d_hash_and_lookup(lower_dir_dentry, &dname);
	lower_dentry = lookup_one_len_unlocked(dname.name, lower_dir_dentry,
					       dname.len);
	if (IS_ERR(lower_dentry))
		return lower_dentry;

	if (!lower_dentry) {
		/* We called vfs_path_lookup earlier, and did not get a negative
		 * dentry then. Don't confuse the lower filesystem by forcing
		 * one on it now...
		 */
	if (d_really_is_negative(lower_dentry))
		err = -ENOENT;
		goto out;
	}

	lower_path.dentry = lower_dentry;
	lower_path.mnt = mntget(lower_dir_mnt);