ext2fs_free() does not set the ext2_filsys pointer to null so the caller is responsible to setting it himself if it is needed. This patch fixes some places where caller did not set ext2_filsys pointer to NULL after ext2fs_free() which might result in use after free. Fix it. Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx> --- lib/ext2fs/openfs.c | 7 ++++--- resize/resize2fs.c | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index aba8a50..b4122de 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -476,10 +476,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, return 0; cleanup: - if (flags & EXT2_FLAG_NOFREE_ON_ERROR) - *ret_fs = fs; - else + if (!(flags & EXT2_FLAG_NOFREE_ON_ERROR)) { ext2fs_free(fs); + fs = NULL; + } + *ret_fs = fs; return retval; } diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 498cf99..8353338 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -209,6 +209,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, rfs->flags = flags; ext2fs_free(rfs->old_fs); + rfs->old_fs = NULL; if (rfs->itable_buf) ext2fs_free_mem(&rfs->itable_buf); if (rfs->reserve_blocks) @@ -220,8 +221,10 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, return 0; errout: - if (rfs->new_fs) + if (rfs->new_fs) { ext2fs_free(rfs->new_fs); + rfs->new_fs = NULL; + } if (rfs->itable_buf) ext2fs_free_mem(&rfs->itable_buf); ext2fs_free_mem(&rfs); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html