Skip to content
Permalink
Browse files
net: bpf: switch over to memdup_user()
This patch fixes the following Coccinelle warning:

net/bpf/test_run.c:361:8-15: WARNING opportunity for memdup_user
net/bpf/test_run.c:1055:8-15: WARNING opportunity for memdup_user

Use memdup_user rather than duplicating its implementation
This is a little bit restricted to reduce false positives

Signed-off-by: Qing Wang <wangqing@vivo.com>
  • Loading branch information
Qing Wang authored and intel-lab-lkp committed Oct 18, 2021
1 parent 431bfb9 commit 0f26c48ef52a60e8ce1ec2eccf6cf0819ee1e8e8
Showing 1 changed file with 6 additions and 15 deletions.
@@ -358,13 +358,9 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
return -EINVAL;

if (ctx_size_in) {
info.ctx = kzalloc(ctx_size_in, GFP_USER);
if (!info.ctx)
return -ENOMEM;
if (copy_from_user(info.ctx, ctx_in, ctx_size_in)) {
err = -EFAULT;
goto out;
}
info.ctx = memdup_user(ctx_in, ctx_size_in);
if (IS_ERR(info.ctx))
return ERR_PTR(PTR_ERR(info.ctx));
} else {
info.ctx = NULL;
}
@@ -392,7 +388,6 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32)))
err = -EFAULT;

out:
kfree(info.ctx);
return err;
}
@@ -1052,13 +1047,9 @@ int bpf_prog_test_run_syscall(struct bpf_prog *prog,
return -EINVAL;

if (ctx_size_in) {
ctx = kzalloc(ctx_size_in, GFP_USER);
if (!ctx)
return -ENOMEM;
if (copy_from_user(ctx, ctx_in, ctx_size_in)) {
err = -EFAULT;
goto out;
}
ctx = memdup_user(ctx_in, ctx_size_in);
if (IS_ERR(ctx))
return ERR_PTR(PTR_ERR(ctx));
}

rcu_read_lock_trace();

0 comments on commit 0f26c48

Please sign in to comment.