usb: f_fs: Avoid invalid pointer access in ffs_fs_get_tree

Consider a case where ffs_data_new is getting called from
ffs_fs_get_tree and ffs_data_new returns error pointer since
the function (e.g. adb) is already mounted. The driver is only
checking for the NULL return value for ffs but in this case it
will not be NULL, which will fail the check and driver will go
ahead accessing invalid pointer which can lead to inconsistencies.

Fix this by having NULL as well as error pointer check for ffs.

Change-Id: Idad5a0b91148325258ea3f545d4da71644c7fc53
Signed-off-by: Pratham Pratap <prathampratap@codeaurora.org>
This commit is contained in:
Pratham Pratap
2021-03-23 00:07:13 +05:30
committed by Gerrit - the friendly Code Review server
parent 71add66750
commit 73f4406f74

View File

@@ -1684,8 +1684,13 @@ ffs_fs_mount(struct file_system_type *t, int flags,
return ERR_PTR(ret);
ffs = ffs_data_new(dev_name);
if (unlikely(!ffs))
return ERR_PTR(-ENOMEM);
if (IS_ERR_OR_NULL(ffs)) {
if (!ffs)
return ERR_PTR(-ENOMEM);
else
return ERR_PTR((long) ffs);
}
ffs->file_perms = data.perms;
ffs->no_disconnect = data.no_disconnect;