--- linux-last/include/linux/device-mapper.h	Tue Nov 13 14:38:11 2001
+++ linux/include/linux/device-mapper.h	Tue Nov 13 16:01:12 2001
@@ -42,6 +42,7 @@
  * (ie. opened/closed).
  */
 int dm_table_get_device(struct dm_table *t, const char *path,
+			offset_t start, offset_t len,
 			struct dm_dev **result);
 void dm_table_put_device(struct dm_table *table, struct dm_dev *d);
 
--- linux-last/drivers/md/dm-table.c	Tue Nov 13 15:56:39 2001
+++ linux/drivers/md/dm-table.c	Tue Nov 13 16:04:55 2001
@@ -6,6 +6,9 @@
 
 #include "dm.h"
 
+#include <linux/blkdev.h>
+
+
 /* ceiling(n / size) * size */
 static inline ulong round_up(ulong n, ulong size)
 {
@@ -258,10 +261,32 @@
 }
 
 /*
+ * If possible (ie. blk_size[major] is set), this
+ * checks an area of a destination device is
+ * valid.
+ */
+static int check_device_area(kdev_t dev, offset_t start, offset_t len)
+{
+	int *sizes;
+	offset_t dev_size;
+
+	if (!(sizes = blk_size[MAJOR(dev)]) || !(dev_size = sizes[MINOR(dev)]))
+		/* we don't know the device details,
+		 * so give the benefit of the doubt */
+		return 1;
+
+	 /* convert to 512-byte sectors */
+	dev_size <<= 1;
+
+	return ((start < dev_size) && (len <= (dev_size - start)));
+}
+
+/*
  * add a device to the list, or just increment the
  * usage count if it's already present.
  */
 int dm_table_get_device(struct dm_table *t, const char *path,
+			offset_t start, offset_t len,
 			struct dm_dev **result)
 {
 	int r;
@@ -290,6 +315,13 @@
 		list_add(&dd->list, &t->devices);
 	}
 	atomic_inc(&dd->count);
+
+	if (!check_device_area(dd->dev, start, len)) {
+		WARN("device '%s' not large enough for target", path);
+		dm_table_put_device(t, dd);
+		return -EINVAL;
+	}
+
 	*result = dd;
 
 	return 0;
--- linux-last/drivers/md/dm-linear.c	Tue Nov 13 14:24:30 2001
+++ linux/drivers/md/dm-linear.c	Tue Nov 13 15:59:21 2001
@@ -48,7 +48,7 @@
 		goto bad;
 	}
 
-	if ((r = dm_table_get_device(t, path, &lc->dev))) {
+	if ((r = dm_table_get_device(t, path, start, l, &lc->dev))) {
 		err("couldn't lookup device", e_private);
 		r = -ENXIO;
 		goto bad;
