From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 1/6] libext2fs: ext2fs_dup_handle should not alias MMP buffers
Date: Wed, 28 Aug 2013 17:43:51 -0700 [thread overview]
Message-ID: <20130829004350.3190.12494.stgit@blackbox.djwong.org> (raw)
In-Reply-To: <20130829004344.3190.28053.stgit@blackbox.djwong.org>
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>
---
lib/ext2fs/dupfs.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c
index 64d3124..02721e1 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:
next prev parent reply other threads:[~2013-08-29 0:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 0:43 [RFC PATCH v1 0/6] e2fsprogs 8/2013 patchbomb Darrick J. Wong
2013-08-29 0:43 ` Darrick J. Wong [this message]
2013-09-09 14:39 ` [PATCH 1/6] libext2fs: ext2fs_dup_handle should not alias MMP buffers Theodore Ts'o
2013-08-29 0:43 ` [PATCH 2/6] resize2fs: Use blk64_t and location getters for free_gdp_blocks() Darrick J. Wong
2013-09-09 14:41 ` Theodore Ts'o
2013-08-29 0:44 ` [PATCH 3/6] e2fsck: Fix incorrect bbitmap checksum failure caused by integer overflow Darrick J. Wong
2013-09-16 13:42 ` Theodore Ts'o
2013-08-29 0:44 ` [PATCH 4/6] e2fsprogs: Add (optional) sparse checking to the build Darrick J. Wong
2013-08-29 0:44 ` [PATCH 5/6] tune2fs: Zero inode table when removing checksums Darrick J. Wong
2013-09-16 13:53 ` Theodore Ts'o
2013-08-29 0:44 ` [PATCH 6/6] resize2fs: Convert fs to and from 64bit mode Darrick J. Wong
2013-09-09 17:29 ` Darrick J. Wong
2013-09-09 17:47 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130829004350.3190.12494.stgit@blackbox.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).