sdcardfs: check the free space before creating files

User can create zero byte files even sdcardfs hits the reserved limit
that will consume blocks for the file name and eventually use up all
memeory. Check the avaliable free space before creating files.

port (CR) from P.

Change-Id: Ib902844f2e6e6c638184895e3f4fa7282acc8333
Signed-off-by: a17671 <a17671@motorola.com>
Reviewed-on: https://gerrit.mot.com/1435234
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Igor Kovalenko <igork@motorola.com>
Submit-Approved: Jira Key
Reviewed-on: https://gerrit.mot.com/1531814
Reviewed-by: Shi-Yong Li <a22381@motorola.com>
This commit is contained in:
Shiyong Li authored and Gilberto Gambugge committed 2023-06-01 00:47:10 -03:00
1 parent b987498275
commit 9a7ae86cc9
1 file changed
+10 -1
+10 -1
View File
@@ -63,7 +63,7 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
umode_t mode, bool want_excl)
{
int err;
struct dentry *lower_dentry;
struct dentry *lower_dentry, *parent_dentry;
struct vfsmount *lower_dentry_mnt;
struct dentry *lower_parent_dentry = NULL;
struct path lower_path;
@@ -76,6 +76,15 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
goto out_eacces;
}
parent_dentry = dget_parent(dentry);
if (!check_min_free_space(parent_dentry, 0, 1)) {
pr_err("sdcardfs: No minimum free space.\n");
err = -ENOSPC;
dput(parent_dentry);
goto out_eacces;
}
dput(parent_dentry);
/* save current_cred and override it */
saved_cred = override_fsids(SDCARDFS_SB(dir->i_sb),
SDCARDFS_I(dir)->data);