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

Commit bb3d132a authored by Dan Carpenter's avatar Dan Carpenter Committed by Theodore Ts'o
Browse files

ext4: fix potential NULL dereference in ext4_free_inodes_counts()



The ext4_get_group_desc() function returns NULL on error, and
ext4_free_inodes_count() function dereferences it without checking.
There is a check on the next line, but it's too late.

Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Cc: stable@kernel.org
parent e93376c2
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -508,12 +508,14 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
	for (i = 0; i < ngroups; i++) {
		grp = (parent_group + i) % ngroups;
		desc = ext4_get_group_desc(sb, grp, NULL);
		if (desc) {
			grp_free = ext4_free_inodes_count(sb, desc);
		if (desc && grp_free && grp_free >= avefreei) {
			if (grp_free && grp_free >= avefreei) {
				*group = grp;
				return 0;
			}
		}
	}

	if (avefreei) {
		/*