Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99e72a0f authored by Tobias Klauser's avatar Tobias Klauser Committed by David S. Miller
Browse files

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: default avatarTobias Klauser <tklauser@distanz.ch>
Acked-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Acked-by: default avatarAlexei Starovoitov <ast@plumgrid.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 677a9fd3
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -844,7 +844,7 @@ int sk_convert_filter(struct sock_filter *prog, int len,
		return -EINVAL;
		return -EINVAL;


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


	BUILD_BUG_ON(BPF_MEMWORDS > 16);
	BUILD_BUG_ON(BPF_MEMWORDS > 16);


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