From: a17671 Date: Tue, 18 Sep 2018 09:30:19 +0000 (+0800) Subject: Porting the sdcard panic fix from qcom X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c004983deef12d86a41869c46ed79eed45827acc;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git Porting the sdcard panic fix from qcom Porting the change 226f96b0 from QCOM Fix potential crash when reserved_mb is not zero Author: Lianjun Huang sdcardfs_mkdir() calls check_min_free_space(). When reserved_mb is not zero, a negative dentry will be passed to ext4_statfs at last and ext4_statfs() will crash. The parent dentry is possitive. So we use the parrent dentry to check free space. Change-Id: I0c7c6e38cf116660bc573a7e81a679366aa6c334 Signed-off-by: a17671 Reviewed-on: https://gerrit.mot.com/1242998 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Master Yoda Reviewed-by: Xiangpo Zhao Submit-Approved: Jira Key --- diff --git a/fs/sdcardfs/inode.c b/fs/sdcardfs/inode.c index 4dd681e0d59d..6015d16576b2 100644 --- a/fs/sdcardfs/inode.c +++ b/fs/sdcardfs/inode.c @@ -66,6 +66,7 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry, struct dentry *lower_dentry; struct vfsmount *lower_dentry_mnt; struct dentry *lower_parent_dentry = NULL; + struct dentry *parent_dentry = NULL; struct path lower_path; const struct cred *saved_cred = NULL; struct fs_struct *saved_fs; @@ -82,6 +83,14 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry, if (!saved_cred) return -ENOMEM; + 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_revert; + } + dput(parent_dentry); sdcardfs_get_lower_path(dentry, &lower_path); lower_dentry = lower_path.dentry; lower_dentry_mnt = lower_path.mnt; @@ -122,7 +131,8 @@ out: out_unlock: unlock_dir(lower_parent_dentry); sdcardfs_put_lower_path(dentry, &lower_path); - revert_fsids(saved_cred); +out_revert: + revert_fsids(saved_cred); out_eacces: return err; }