]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dm: restrict dm device size to 2^63-512 bytes
authorMikulas Patocka <mpatocka@redhat.com>
Fri, 14 Mar 2025 12:51:32 +0000 (13:51 +0100)
committerMikulas Patocka <mpatocka@redhat.com>
Fri, 14 Mar 2025 12:58:33 +0000 (13:58 +0100)
The devices with size >= 2^63 bytes can't be used reliably by userspace
because the type off_t is a signed 64-bit integer.

Therefore, we limit the maximum size of a device mapper device to
2^63-512 bytes.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-table.c

index 0ef5203387b26f96d59235a48f746e96927b196b..04b3e9758e53193d6e74dff8e51c10bfe74eb512 100644 (file)
@@ -697,6 +697,10 @@ int dm_table_add_target(struct dm_table *t, const char *type,
                DMERR("%s: zero-length target", dm_device_name(t->md));
                return -EINVAL;
        }
+       if (start + len < start || start + len > LLONG_MAX >> SECTOR_SHIFT) {
+               DMERR("%s: too large device", dm_device_name(t->md));
+               return -EINVAL;
+       }
 
        ti->type = dm_get_target_type(type);
        if (!ti->type) {