Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
free prog->aux->used_maps in verifier linux hooks
Browse files Browse the repository at this point in the history
  o In kernel, it is freed when map itself is freed.
  o This is to avoid sanitizer to report memory leak.

Signed-off-by: Yonghong Song <yhs@plumgrid.com>
  • Loading branch information
yonghong-song committed Sep 17, 2015
1 parent 13df8d0 commit 2859d34
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
21 changes: 1 addition & 20 deletions README.md
Expand Up @@ -47,7 +47,7 @@ make headers_install
```

For above linux tree, apply the following patch so that llvm can cope with linux
inline assembly, and workaround a memory leak reporting issue.
inline assembly:

```
yhs@ubuntu:~/work/fuzzer/net-next$ git diff
Expand All @@ -64,25 +64,6 @@ index c361593..cacbe0f 100644
else
# This warning generated too much noise in a regular build.
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index b074b23..af83c6e 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2186,6 +2186,14 @@ skip_full_check:
* bpf_ld_imm64 instructions
*/
convert_pseudo_ld_imm64(env);
+
+#if 1
+ /* this is a workaround for userspace verifier.
+ * in kernel, the env->prog->aux->used_maps will be
+ * freed when the map itself is freed.
+ */
+ kfree(env->prog->aux->used_maps);
+#endif
}
free_log_buf:
yhs@ubuntu:~/work/fuzzer/net-next$
```

Expand Down
6 changes: 6 additions & 0 deletions src/helper/linux_hook.c
Expand Up @@ -801,6 +801,12 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
if (err >= 0) {
/* run eBPF verifier */
err = bpf_check(&prog, &attr);

/* this is a workaround for userspace verifier.
* in kernel, the env->prog->aux->used_maps will be
* freed when the map itself is freed.
*/
kfree(prog->aux->used_maps);
}
bpf_prog_free_k(prog);
return err;
Expand Down
2 changes: 1 addition & 1 deletion src/test/linux-samples-bpf/test_verifier.c
Expand Up @@ -1009,7 +1009,7 @@ static void usage(char *prog)

int main(int argc, char **argv)
{
if (argc > 0) {
if (argc > 1) {
if (argc == 3 && strcmp(argv[1], "-g") == 0) {
/* generate test cases for fuzzer, no need to run the test */
int ret;
Expand Down

0 comments on commit 2859d34

Please sign in to comment.