Skip to content

Commit

Permalink
quota: Fix memory leak when handling corrupted quota file
Browse files Browse the repository at this point in the history
When checking corrupted quota file we can bail out and leak allocated
info structure. Properly free info structure on error return.

Reported-by: [email protected]
Fixes: 11c514a ("quota: Sanity-check quota file headers on load")
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
jankara committed Jan 5, 2021
1 parent 36bbbd0 commit a4db107
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fs/quota/quota_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,24 @@ static int v2_read_file_info(struct super_block *sb, int type)
quota_error(sb, "Number of blocks too big for quota file size (%llu > %llu).",
(loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits,
i_size_read(sb_dqopt(sb)->files[type]));
goto out;
goto out_free;
}
if (qinfo->dqi_free_blk >= qinfo->dqi_blocks) {
quota_error(sb, "Free block number too big (%u >= %u).",
qinfo->dqi_free_blk, qinfo->dqi_blocks);
goto out;
goto out_free;
}
if (qinfo->dqi_free_entry >= qinfo->dqi_blocks) {
quota_error(sb, "Block with free entry too big (%u >= %u).",
qinfo->dqi_free_entry, qinfo->dqi_blocks);
goto out;
goto out_free;
}
ret = 0;
out_free:
if (ret) {
kfree(info->dqi_priv);
info->dqi_priv = NULL;
}
out:
up_read(&dqopt->dqio_sem);
return ret;
Expand Down

0 comments on commit a4db107

Please sign in to comment.