Skip to contentSkip to conversation

dm integrity: Reject mappings too large for device

PATCH In review Ondrej Mosnacek 2 participants 2 messages Jun 5, 2017 – Jun 8, 2017 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm integrity: Reject mappings too large for device

Before this patch, dm-integrity would successfully create mappings with the number of sectors greater than the provided data sector count. Attempts to read sectors of this mapping that were beyond the provided data sector count would then yield run-time messages of the form "device-mapper: integrity: Too big sector number: ...".

This patch fixes this by emitting an error when the requested mapping size is bigger than the provided data sector count.

Cc Mikulas Patocka <[email protected]>
Cc Milan Broz <[email protected]>
---
 drivers/md/dm-integrity.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/md/dm-integrity.c +5 -0
index 7910bfe50da4..4ab10cf718c9 100644
@@ -3040,6 +3040,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 		ti->error = "The device is too small";
 		goto bad;
 	}
+	if (ti->len > ic->provided_data_sectors) {
+		r = -EINVAL;
+		ti->error = "Not enough provided sectors for requested mapping size";
+		goto bad;
+	}
 
 	if (!buffer_sectors)
 		buffer_sectors = 1;
Signature · 1 line
2.11.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ondrej Mosnacek

Before this patch, dm-integrity would successfully create mappings with the number of sectors greater than the provided data sector count. Attempts to read sectors of this mapping that were beyond the provided data sector count would then yield run-time messages of the form "device-mapper: integrity: Too big sector number: ...".

This patch fixes this by emitting an error when the requested mapping size is bigger than the provided data sector count.

Cc Mikulas Patocka <[email protected]>
Cc Milan Broz <[email protected]>
Quoted 24 lines
---
 drivers/md/dm-integrity.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/md/dm-integrity.c +5 -0
index 7910bfe50da4..4ab10cf718c9 100644
@@ -3040,6 +3040,11 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
 		ti->error = "The device is too small";
 		goto bad;
 	}
+	if (ti->len > ic->provided_data_sectors) {
+		r = -EINVAL;
+		ti->error = "Not enough provided sectors for requested mapping size";
+		goto bad;
+	}
 
 	if (!buffer_sectors)
 		buffer_sectors = 1;
Signature · 1 line
2.11.0