Skip to content

Commit bf11d71

Browse files
GustavoARSilvamstsirkin
authored andcommitted
vhost: Use flex_array_size() helper in copy_from_user()
Make use of the flex_array_size() helper to calculate the size of a flexible array member within an enclosing structure. This helper offers defense-in-depth against potential integer overflows, while at the same time makes it explicitly clear that we are dealing with a flexible array member. Signed-off-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/20200731130956.GA30525@embeddedor Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 0ea9ee4 commit bf11d71

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/vhost/vhost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
14051405

14061406
memcpy(newmem, &mem, size);
14071407
if (copy_from_user(newmem->regions, m->regions,
1408-
mem.nregions * sizeof *m->regions)) {
1408+
flex_array_size(newmem, regions, mem.nregions))) {
14091409
kvfree(newmem);
14101410
return -EFAULT;
14111411
}

0 commit comments

Comments
 (0)