Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > fc11cd6e1c513a17304da94a5390f3cd > files > 1435

kernel-2.6.18-194.11.1.el5.src.rpm

From: Milan Broz <mbroz@redhat.com>
Date: Mon, 16 Mar 2009 16:59:16 +0100
Subject: [md] dm: check log bitmap will fit within the log device
Message-id: 49BE7754.1060008@redhat.com
O-Subject: [RHEL 5.4 PATCH] dm: Check that the log bitmap will fit within the log device.
Bugzilla: 471565
RH-Acked-by: Alasdair G Kergon <agk@redhat.com>

RHEL5.4 device mapper: Check that the log bitmap will fit within the log device.
Resolves: rhbz#471565

Patch is upstream, commit ac1f0ac22c7be908fd33407273b9808bfaedada4

Code prevents the "attempt to access beyond end of device" errors
which can happen for example when using 1k extent and mirror
in lvm2 (userspace problem is addressed by bz 477040).

Patch compiled and tested (testcase in bugzilla).

diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 23bfcdf..e00e4c7 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -468,6 +468,14 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
 		 */
 		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;
 		lc->io_req.client = dm_io_client_create(dm_div_up(buf_size,