Skip to contentSkip to conversation

fs/affs: release memory if affs_init_bitmap fails

PATCH In review Navid Emamdoost 3 participants 3 messages Sep 17, 2019 – Sep 25, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/affs: release memory if affs_init_bitmap fails

In affs_init_bitmap, on error handling path we may release the allocated memory.

---
 fs/affs/bitmap.c | 1 +
 1 file changed, 1 insertion(+)
fs/affs/bitmap.c +1 -0
index 5ba9ef2742f6..745ed2cc4b51 100644
@@ -347,6 +347,7 @@ int affs_init_bitmap(struct super_block *sb, int *flags)
 out:
 	affs_brelse(bh);
 	affs_brelse(bmap_bh);
+	kfree(sbi->s_bitmap);
 	return res;
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Navid Emamdoost

In affs_init_bitmap, on error handling path we may release the allocated memory.

Yes the memory should be released but not all paths that lead to the label 'out' are actually errors:

288 if (affs_checksum_block(sb, bh)) {
289 pr_warn("Bitmap %u invalid - mounting %s read only.\n",
290 bm->bm_key, sb->s_id);
291 *flags |= SB_RDONLY;
292 goto out;
293 }

ie. the return value 'res' is still 0, and the filesystem is mounted read-only.

Quoted 10 lines
---
 fs/affs/bitmap.c | 1 +
 1 file changed, 1 insertion(+)
fs/affs/bitmap.c +0 -0
index 5ba9ef2742f6..745ed2cc4b51 100644

fs/affs/bitmap.c int affs_init_bitmap(struct super_block *sb, int *flags) · line 350

Quoted 4 lines
fs/affs/bitmap.c +1 -0
@@ -347,6 +347,7 @@ int affs_init_bitmap(struct super_block *sb, int *flags)
 out:
 	affs_brelse(bh);
 	affs_brelse(bmap_bh);
+	kfree(sbi->s_bitmap);

The sbi->s_bitmap would be freed but at umount time it will be freed again.

Quoted 7 lines
fs/affs/bitmap.c +0 -0
 	return res;
 }
 
Signature · 1 line
2.17.1
maintainer
#2 lore raw
Quoted 6 lines · David Sterba
Quoted 2 lines · Navid Emamdoost

In affs_init_bitmap, on error handling path we may release the allocated memory.

Yes the memory should be released but not all paths that lead to the label 'out' are actually errors:

... and none of them should be freeing anything here, errors or no errors.

Quoted 2 lines

The sbi->s_bitmap would be freed but at umount time it will be freed again.

It actually would be freed by superblock destructor, be it on umount or on failed fill_super.