Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/linux: support for BPF filesystem #1456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pchaigno
Copy link
Contributor

This pull requests puts filenames for the bpf$OBJ_PIN_(MAP|PROG) and bpf$OBJ_GET_(MAP|PROG) syscalls on the /sys/fs/bpf/ filesystem. I've checked that it works correctly by running syzkaller long enough that it managed to pin a map!

Note that I've also updated create-image.sh to mount the BPF filesystem at startup time. Since this special filesystem is only supported in Linux 4.4+, it may create issues for older kernels. Is that something we care about for create-image.sh? Should there be an option to not write that line to /etc/fstab (+documentation)?

sys/linux/bpf.txt Outdated Show resolved Hide resolved
@dvyukov
Copy link
Collaborator

dvyukov commented Oct 15, 2019

Use of the global path is problematic for several reasons:

  • that location is shared between multiple test process and they will all create file names like 'file0'
  • nobody will clean up there after tests
  • tests won't be reproducible since running the same program second time will lead to completely different execution
  • we don't require use of create-image.sh even syzbot doesn't use it
  • consider a kernel dev trying to reproduce a bug report, say they don't have this path, so no bug is reproduced

We generally try to prepare isolated environment for each test, grep cgroup/mount in executor/*.h. That code is also used in reproducers so a repro will create all necessary env as well.

Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
@pchaigno
Copy link
Contributor Author

Thanks for the review!

I've updated the branch with just stringnoz for now. I'll have a look at executor/common_linux.h.

@codecov-io
Copy link

Codecov Report

Merging #1456 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1456      +/-   ##
==========================================
+ Coverage   56.42%   56.44%   +0.01%     
==========================================
  Files         135      135              
  Lines       25796    25796              
==========================================
+ Hits        14555    14560       +5     
+ Misses      10570    10566       -4     
+ Partials      671      670       -1
Impacted Files Coverage Δ
prog/rand.go 88.9% <0%> (+0.54%) ⬆️
prog/any.go 89.39% <0%> (+0.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05ad729...c1aeb30. Read the comment docs.

@pchaigno
Copy link
Contributor Author

We generally try to prepare isolated environment for each test, grep cgroup/mount in executor/*.h. That code is also used in reproducers so a repro will create all necessary env as well.

I'm not quite sure how to proceed with this issue. It looks like we would need either 1) a way to refer to the executor's temporary directory from syscall descriptions, or 2) to chroot into that temporary directory after mounting the BPF filesystem.

I'm guessing option 1 is preferred (?). Option 2 is probably only okay when using the namespace sandbox and even then we'll have another issue: we can't mount the BPF filesystem into a user namespace.

@dvyukov
Copy link
Collaborator

dvyukov commented Nov 1, 2019

A test process always have cwd set to the temp directory, so a name like "bpf" will refer to the temp dir (well, not after chdir into a subdir, but we can live with that, the same for any other file names).

@pchaigno
Copy link
Contributor Author

pchaigno commented Nov 2, 2019

Hm, right. Not sure why I didn't consider a relative path. I will update the pull request for that.

@dvyukov
Copy link
Collaborator

dvyukov commented Nov 3, 2019

tools/create-image.sh is only used by humans, we also need similar changes in tools/create-gce-image.sh which is used by syzbot (run make generate after changing it).
Is bfs fs global? Or each mount contains own entries? Ideally for test isolation purposes, we give each test process a private dir/mount (e.g. see what we do with syzcgroup in executor). Perhaps we could mount bpf, and then create a new dir per test in the mount and then create a link from the test private dir to the corresponding dir in the mount, and then delete it after the test? See e.g. setup_cgroups_loop/setup_cgroups_test. Then each test will have "./bpf" dir, but it will be a new, private one.

@pchaigno
Copy link
Contributor Author

pchaigno commented Nov 5, 2019

tools/create-image.sh is only used by humans, we also need similar changes in tools/create-gce-image.sh which is used by syzbot (run make generate after changing it).

I don't think we'll need changes in these scripts after all.

Is bfs fs global? Or each mount contains own entries? Ideally for test isolation purposes, we give each test process a private dir/mount (e.g. see what we do with syzcgroup in executor). Perhaps we could mount bpf, and then create a new dir per test in the mount and then create a link from the test private dir to the corresponding dir in the mount, and then delete it after the test? See e.g. setup_cgroups_loop/setup_cgroups_test. Then each test will have "./bpf" dir, but it will be a new, private one.

As far as I can see (through quick tests), the bpf filesystem mounts are not global. Each mount contains its own entries, so we can simply mount it inside the tests' private directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants