Skip to content

Commit 059192e

Browse files
Mikulas PatockasfX-bot
Mikulas Patocka
authored andcommitted
dm: limit the number of targets and parameter size area
commit bd504bcfec41a503b32054da5472904b404341a4 upstream. The kvmalloc function fails with a warning if the size is larger than INT_MAX. The warning was triggered by a syscall testing robot. In order to avoid the warning, this commit limits the number of targets to 1048576 and the size of the parameter area to 1073741824. Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: He Gao <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c8ab83a commit 059192e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

drivers/md/dm-core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "dm.h"
2121

2222
#define DM_RESERVED_MAX_IOS 1024
23+
#define DM_MAX_TARGETS 1048576
24+
#define DM_MAX_TARGET_PARAMS 1024
2325

2426
struct dm_kobject_holder {
2527
struct kobject kobj;

drivers/md/dm-ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,8 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
17601760
if (copy_from_user(param_kernel, user, minimum_data_size))
17611761
return -EFAULT;
17621762

1763-
if (param_kernel->data_size < minimum_data_size)
1763+
if (unlikely(param_kernel->data_size < minimum_data_size) ||
1764+
unlikely(param_kernel->data_size > DM_MAX_TARGETS * DM_MAX_TARGET_PARAMS))
17641765
return -EINVAL;
17651766

17661767
secure_data = param_kernel->flags & DM_SECURE_DATA_FLAG;

drivers/md/dm-table.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
144144
int dm_table_create(struct dm_table **result, fmode_t mode,
145145
unsigned num_targets, struct mapped_device *md)
146146
{
147-
struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL);
147+
struct dm_table *t;
148+
149+
if (num_targets > DM_MAX_TARGETS)
150+
return -EOVERFLOW;
151+
152+
t = kzalloc(sizeof(*t), GFP_KERNEL);
148153

149154
if (!t)
150155
return -ENOMEM;
@@ -158,7 +163,7 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
158163

159164
if (!num_targets) {
160165
kfree(t);
161-
return -ENOMEM;
166+
return -EOVERFLOW;
162167
}
163168

164169
if (alloc_targets(t, num_targets)) {

0 commit comments

Comments
 (0)