Skip to content

Commit

Permalink
net: filter: Use kcalloc/kmalloc_array to allocate arrays
Browse files Browse the repository at this point in the history
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 <tklauser@distanz.ch>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tobias Klauser authored and David S. Miller committed Jun 25, 2014
1 parent 677a9fd commit 99e72a0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ int sk_convert_filter(struct sock_filter *prog, int len,
return -EINVAL;

if (new_prog) {
addrs = kzalloc(len * sizeof(*addrs), GFP_KERNEL);
addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
if (!addrs)
return -ENOMEM;
}
Expand Down Expand Up @@ -1101,7 +1101,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)

BUILD_BUG_ON(BPF_MEMWORDS > 16);

masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
if (!masks)
return -ENOMEM;

Expand Down

0 comments on commit 99e72a0

Please sign in to comment.