diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2014-06-24 09:33:22 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-06-25 19:40:02 -0400 |
commit | 99e72a0fed07d118d329f3046ad2ec2ae9357d63 (patch) | |
tree | 1517dd11ff7021cb4d06dcd335edd2d8009294d0 /net | |
parent | 677a9fd3e6e6e03e11b979b69c9f8c813583683a (diff) |
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 <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>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/filter.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 4d13b125ef4b..1dbf6462f766 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -844,7 +844,7 @@ int sk_convert_filter(struct sock_filter *prog, int len, | |||
844 | return -EINVAL; | 844 | return -EINVAL; |
845 | 845 | ||
846 | if (new_prog) { | 846 | if (new_prog) { |
847 | addrs = kzalloc(len * sizeof(*addrs), GFP_KERNEL); | 847 | addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL); |
848 | if (!addrs) | 848 | if (!addrs) |
849 | return -ENOMEM; | 849 | return -ENOMEM; |
850 | } | 850 | } |
@@ -1101,7 +1101,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen) | |||
1101 | 1101 | ||
1102 | BUILD_BUG_ON(BPF_MEMWORDS > 16); | 1102 | BUILD_BUG_ON(BPF_MEMWORDS > 16); |
1103 | 1103 | ||
1104 | masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL); | 1104 | masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL); |
1105 | if (!masks) | 1105 | if (!masks) |
1106 | return -ENOMEM; | 1106 | return -ENOMEM; |
1107 | 1107 | ||