From: Milan Broz <mbroz@redhat.com>

Check that the log bitmap will fit within the log device.

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
---
 drivers/md/dm-log.c |    8 ++++++++
 1 files changed, 8 insertions(+)

Index: linux-2.6.28/drivers/md/dm-log.c
===================================================================
--- linux-2.6.28.orig/drivers/md/dm-log.c	2009-01-05 18:18:20.000000000 +0000
+++ linux-2.6.28/drivers/md/dm-log.c	2009-01-05 18:18:22.000000000 +0000
@@ -457,6 +457,14 @@ static int create_log_context(struct dm_
 		 */
 		buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) +
 				       bitset_size, ti->limits.hardsect_size);
+
+		if (buf_size > dev->bdev->bd_inode->i_size) {
+			DMWARN("log device %s too small: need %llu bytes",
+				dev->name, (unsigned long long)buf_size);
+			kfree(lc);
+			return -EINVAL;
+		}
+
 		lc->header_location.count = buf_size >> SECTOR_SHIFT;
 
 		lc->io_req.mem.type = DM_IO_VMA;