Skip to content

Commit 99e72a0

Browse files
tklauserdavem330
authored andcommitted
net: filter: Use kcalloc/kmalloc_array to allocate arrays
Use kcalloc/kmalloc_array to make it clear we're allocating arrays. No integer overflow can actually happen here, since len/flen is guaranteed to be less than BPF_MAXINSNS (4096). However, this changed makes sure we're not going to get one if BPF_MAXINSNS were ever increased. Signed-off-by: Tobias Klauser <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 677a9fd commit 99e72a0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ int sk_convert_filter(struct sock_filter *prog, int len,
844844
return -EINVAL;
845845

846846
if (new_prog) {
847-
addrs = kzalloc(len * sizeof(*addrs), GFP_KERNEL);
847+
addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
848848
if (!addrs)
849849
return -ENOMEM;
850850
}
@@ -1101,7 +1101,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
11011101

11021102
BUILD_BUG_ON(BPF_MEMWORDS > 16);
11031103

1104-
masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
1104+
masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
11051105
if (!masks)
11061106
return -ENOMEM;
11071107

0 commit comments

Comments
 (0)