Skip to content

Commit bd504bc

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm: limit the number of targets and parameter size area
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]>
1 parent 41bccc9 commit bd504bc

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
@@ -22,6 +22,8 @@
2222
#include "dm-ima.h"
2323

2424
#define DM_RESERVED_MAX_IOS 1024
25+
#define DM_MAX_TARGETS 1048576
26+
#define DM_MAX_TARGET_PARAMS 1024
2527

2628
struct dm_io;
2729

drivers/md/dm-ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,8 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
19411941
minimum_data_size - sizeof(param_kernel->version)))
19421942
return -EFAULT;
19431943

1944-
if (param_kernel->data_size < minimum_data_size) {
1944+
if (unlikely(param_kernel->data_size < minimum_data_size) ||
1945+
unlikely(param_kernel->data_size > DM_MAX_TARGETS * DM_MAX_TARGET_PARAMS)) {
19451946
DMERR("Invalid data size in the ioctl structure: %u",
19461947
param_kernel->data_size);
19471948
return -EINVAL;

drivers/md/dm-table.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
129129
int dm_table_create(struct dm_table **result, blk_mode_t mode,
130130
unsigned int num_targets, struct mapped_device *md)
131131
{
132-
struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL);
132+
struct dm_table *t;
133+
134+
if (num_targets > DM_MAX_TARGETS)
135+
return -EOVERFLOW;
136+
137+
t = kzalloc(sizeof(*t), GFP_KERNEL);
133138

134139
if (!t)
135140
return -ENOMEM;
@@ -144,7 +149,7 @@ int dm_table_create(struct dm_table **result, blk_mode_t mode,
144149

145150
if (!num_targets) {
146151
kfree(t);
147-
return -ENOMEM;
152+
return -EOVERFLOW;
148153
}
149154

150155
if (alloc_targets(t, num_targets)) {

0 commit comments

Comments
 (0)