selftests/bpf: Fix file_reader/on_open_non_sleepable_first on overlayfs
Subsystems (3)
PATCH 1/1 selftests/bpf: Fix file_reader/on_open_non_sleepable_first on overlayfs
on_open_non_sleepable_first fails every time when the test_progs binary is on overlayfs, as under /home and /tmp in a virtme-ng guest:
run_test:FAIL:err unexpected err: actual 4 != expected 0
bpf_task_work_schedule_signal() returns -EBUSY. On overlayfs, the open() of /proc/self/exe calls security_file_open() twice: once for the overlay file, and once more for the backing file through ovl_open() -> backing_file_open() -> vfs_open(). The program runs twice in the same task, and the second call finds the work from the first one still pending, since it only runs on return to user space.
Act only on the first call. The other file_open programs in the file either don't schedule task work or don't check the result, so running twice doesn't affect them.
---
Tested in a virtme-ng guest on bpf-next (82cc2b4383e3): file_reader passes from overlayfs and from a tmpfs copy, and 20 times in a row from overlayfs; without the change the subtest fails from overlayfs and passes from tmpfs.
The patch, this text and the tests were written and run with Claude Code; I reproduced the issue and reviewed the change.
--- tools/testing/selftests/bpf/progs/file_reader.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/file_reader.c +7 -1
@@ -28,6 +28,7 @@ char tmp_buf[256000];int pid =0 ;int err, run_success =0 ;__u64 beyond_eof_offset; +bool done;static int validate_file_read (struct file *file);static int task_work_callback (struct bpf_map *map,void *key,void *value);
@@ -101,8 +102,13 @@ int on_open_non_sleepable_first(void *c)int key =0 ;int ret; -if (bpf_get_current_pid_tgid () >>32 != pid) +/* +* On overlayfs, file_open runs again for the backing file, while the +* work scheduled by the first call is still pending. +*/ +if (bpf_get_current_pid_tgid () >>32 != pid || done)return 0 ; + done = true; file =bpf_get_task_exe_file (task);if (!file) {
---
base-commit: 82cc2b4383e3edfa1026c8612fb4e90a9329ba11
change-id: 20261120-file-reader-overlayfs-04998dda6593
Best regards,
Signature · 1 line
Hang Zhengyang <[email protected]>