Skip to content

Commit 62e5873

Browse files
committed
Merge tag 'size_t-saturating-helpers-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux
Pull misc hardening updates from Gustavo Silva: "Replace a few open-coded instances with size_t saturating arithmetic helpers" * tag 'size_t-saturating-helpers-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux: virt: acrn: Prefer array_size and struct_size over open coded arithmetic afs: Prefer struct_size over open coded arithmetic
2 parents a3a8b54 + 746f1b0 commit 62e5873

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

drivers/virt/acrn/acrn_drv.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ struct vm_memory_region_op {
4848
* @reserved: Reserved.
4949
* @regions_num: The number of vm_memory_region_op.
5050
* @regions_gpa: Physical address of a vm_memory_region_op array.
51+
* @regions_op: Flexible array of vm_memory_region_op.
5152
*
5253
* HC_VM_SET_MEMORY_REGIONS uses this structure to manage EPT mappings of
5354
* multiple memory regions of a User VM. A &struct vm_memory_region_batch
5455
* contains multiple &struct vm_memory_region_op for batch processing in the
5556
* ACRN Hypervisor.
5657
*/
5758
struct vm_memory_region_batch {
58-
u16 vmid;
59-
u16 reserved[3];
60-
u32 regions_num;
61-
u64 regions_gpa;
59+
u16 vmid;
60+
u16 reserved[3];
61+
u32 regions_num;
62+
u64 regions_gpa;
63+
struct vm_memory_region_op regions_op[];
6264
};
6365

6466
/**

drivers/virt/acrn/mm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap)
192192

193193
/* Get the page number of the map region */
194194
nr_pages = memmap->len >> PAGE_SHIFT;
195-
pages = vzalloc(nr_pages * sizeof(struct page *));
195+
pages = vzalloc(array_size(nr_pages, sizeof(*pages)));
196196
if (!pages)
197197
return -ENOMEM;
198198

@@ -244,16 +244,15 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap)
244244
}
245245

246246
/* Prepare the vm_memory_region_batch */
247-
regions_info = kzalloc(sizeof(*regions_info) +
248-
sizeof(*vm_region) * nr_regions,
249-
GFP_KERNEL);
247+
regions_info = kzalloc(struct_size(regions_info, regions_op,
248+
nr_regions), GFP_KERNEL);
250249
if (!regions_info) {
251250
ret = -ENOMEM;
252251
goto unmap_kernel_map;
253252
}
254253

255254
/* Fill each vm_memory_region_op */
256-
vm_region = (struct vm_memory_region_op *)(regions_info + 1);
255+
vm_region = regions_info->regions_op;
257256
regions_info->vmid = vm->vmid;
258257
regions_info->regions_num = nr_regions;
259258
regions_info->regions_gpa = virt_to_phys(vm_region);

fs/afs/security.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ void afs_cache_permit(struct afs_vnode *vnode, struct key *key,
219219
* yet.
220220
*/
221221
size++;
222-
new = kzalloc(sizeof(struct afs_permits) +
223-
sizeof(struct afs_permit) * size, GFP_NOFS);
222+
new = kzalloc(struct_size(new, permits, size), GFP_NOFS);
224223
if (!new)
225224
goto out_put;
226225

0 commit comments

Comments
 (0)