aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2013-09-09 10:39:29 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-09-09 10:39:33 -0400
commit816d2c9cf7fb17fe808a081e076cb558f44ec30d (patch)
tree61316f1ddbfe234adf877f3d4f281d790c7c3515
parent7ff040f30f0ff3bf5e2c832da3cb577e00a52d60 (diff)
downloade2fsprogs-816d2c9cf7fb17fe808a081e076cb558f44ec30d.tar.gz
e2fsprogs-816d2c9cf7fb17fe808a081e076cb558f44ec30d.tar.xz
e2fsprogs-816d2c9cf7fb17fe808a081e076cb558f44ec30d.zip
libext2fs: ext2fs_dup_handle should not alias MMP buffers
It turns out that resize2fs uses ext2fs_dup_handle to duplicate fs handles. If MMP is enabled, this causes both handles to share MMP buffers, which is bad news when it comes time to free both handles. Change the code to (we hope) fix this. This prevents resize2fs from failing with a double-free error when handed a MMP filesystem. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--lib/ext2fs/dupfs.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c
index 64d31248..02721e1a 100644
--- a/lib/ext2fs/dupfs.c
+++ b/lib/ext2fs/dupfs.c
@@ -40,6 +40,9 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
fs->block_map = 0;
fs->badblocks = 0;
fs->dblist = 0;
+ fs->mmp_buf = 0;
+ fs->mmp_cmp = 0;
+ fs->mmp_fd = -1;
io_channel_bumpcount(fs->io);
if (fs->icache)
@@ -87,6 +90,28 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
if (retval)
goto errout;
}
+ if (src->mmp_buf) {
+ retval = ext2fs_get_mem(src->blocksize, &fs->mmp_buf);
+ if (retval)
+ goto errout;
+ memcpy(fs->mmp_buf, src->mmp_buf, src->blocksize);
+ }
+ if (src->mmp_fd >= 0) {
+ fs->mmp_fd = dup(src->mmp_fd);
+ if (fs->mmp_fd < 0) {
+ retval = EXT2_ET_MMP_OPEN_DIRECT;
+ goto errout;
+ }
+ }
+ if (src->mmp_cmp) {
+ int align = ext2fs_get_dio_alignment(src->mmp_fd);
+
+ retval = ext2fs_get_memalign(src->blocksize, align,
+ &fs->mmp_cmp);
+ if (retval)
+ goto errout;
+ memcpy(fs->mmp_cmp, src->mmp_cmp, src->blocksize);
+ }
*dest = fs;
return 0;
errout: