Skip to content

Commit 13f4a69

Browse files
DemiMarieMike Snitzer
authored andcommitted
dm ioctl: Avoid pointer arithmetic overflow
Especially on 32-bit systems, it is possible for the pointer arithmetic to overflow and cause a userspace pointer to be dereferenced in the kernel. Signed-off-by: Demi Marie Obenour <[email protected]> Reviewed-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent b60528d commit 13f4a69

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/md/dm-ioctl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,22 @@ static int next_target(struct dm_target_spec *last, uint32_t next, void *end,
13971397
static_assert(__alignof__(struct dm_target_spec) <= 8,
13981398
"struct dm_target_spec must not require more than 8-byte alignment");
13991399

1400+
/*
1401+
* Number of bytes remaining, starting with last. This is always
1402+
* sizeof(struct dm_target_spec) or more, as otherwise *last was
1403+
* out of bounds already.
1404+
*/
1405+
size_t remaining = (char *)end - (char *)last;
1406+
1407+
/*
1408+
* There must be room for both the next target spec and the
1409+
* NUL-terminator of the target itself.
1410+
*/
1411+
if (remaining - sizeof(struct dm_target_spec) <= next) {
1412+
DMERR("Target spec extends beyond end of parameters");
1413+
return -EINVAL;
1414+
}
1415+
14001416
if (next % __alignof__(struct dm_target_spec)) {
14011417
DMERR("Next dm_target_spec (offset %u) is not %zu-byte aligned",
14021418
next, __alignof__(struct dm_target_spec));

0 commit comments

Comments
 (0)