Skip to content

Commit 27fb7b6

Browse files
Qing WangNobody
Qing Wang
authored and
Nobody
committed
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 <[email protected]> Acked-by: John Fastabend <[email protected]>
1 parent f30d604 commit 27fb7b6

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

net/bpf/test_run.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,9 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
358358
return -EINVAL;
359359

360360
if (ctx_size_in) {
361-
info.ctx = kzalloc(ctx_size_in, GFP_USER);
362-
if (!info.ctx)
363-
return -ENOMEM;
364-
if (copy_from_user(info.ctx, ctx_in, ctx_size_in)) {
365-
err = -EFAULT;
366-
goto out;
367-
}
361+
info.ctx = memdup_user(ctx_in, ctx_size_in);
362+
if (IS_ERR(info.ctx))
363+
return PTR_ERR(info.ctx);
368364
} else {
369365
info.ctx = NULL;
370366
}
@@ -392,7 +388,6 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
392388
copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32)))
393389
err = -EFAULT;
394390

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

10541049
if (ctx_size_in) {
1055-
ctx = kzalloc(ctx_size_in, GFP_USER);
1056-
if (!ctx)
1057-
return -ENOMEM;
1058-
if (copy_from_user(ctx, ctx_in, ctx_size_in)) {
1059-
err = -EFAULT;
1060-
goto out;
1061-
}
1050+
ctx = memdup_user(ctx_in, ctx_size_in);
1051+
if (IS_ERR(ctx))
1052+
return PTR_ERR(ctx);
10621053
}
10631054

10641055
rcu_read_lock_trace();

0 commit comments

Comments
 (0)