summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Jiaoliang <yujiaoliang@vivo.com>2024-08-21 15:37:08 +0800
committerDaniel Borkmann <daniel@iogearbox.net>2024-08-22 14:28:24 +0200
commitb6ab50902724a27f1fc7136927c27d29f9ba01c6 (patch)
tree2f5645eba318dfcefad76b1b7334a2d67ccab432
parent1a437d35a90b7a765d9ce2c629787d22ff103252 (diff)
bpf: Use kmemdup_array instead of kmemdup for multiple allocation
Let the kmemdup_array() take care about multiplication and possible overflows. Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20240821073709.4067177-1-yujiaoliang@vivo.com
-rw-r--r--net/core/filter.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 78a6f746ea0b..ecf2ddf633bf 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1265,8 +1265,8 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
* so we need to keep the user BPF around until the 2nd
* pass. At this time, the user BPF is stored in fp->insns.
*/
- old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
- GFP_KERNEL | __GFP_NOWARN);
+ old_prog = kmemdup_array(fp->insns, old_len, sizeof(struct sock_filter),
+ GFP_KERNEL | __GFP_NOWARN);
if (!old_prog) {
err = -ENOMEM;
goto out_err;