Skip to contentSkip to conversation

bpf: Expose bpf_d_path helper to vfs_read/vfs_write

PATCH In review Hengqi Chen 4 participants 6 messages Jul 12, 2021 – Jul 18, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Expose bpf_d_path helper to vfs_read/vfs_write

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
 BTF_ID(func, dentry_open)
 BTF_ID(func, vfs_getattr)
 BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
 BTF_SET_END(btf_allowlist_d_path)
 
 static bool bpf_d_path_allowed(const struct bpf_prog *prog)
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Hengqi Chen

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

---

As I understand it dpath helper is allowed as long as we are not in NMI/interrupt context, so these should be fine to add.

Quoted 19 lines
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
 BTF_ID(func, dentry_open)
 BTF_ID(func, vfs_getattr)
 BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
 BTF_SET_END(btf_allowlist_d_path)
 
 static bool bpf_d_path_allowed(const struct bpf_prog *prog)
Signature · 1 line
2.25.1
Acked-by
#2 lore raw
Quoted 5 lines · John Fastabend
Quoted 4 lines · Hengqi Chen

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

Quoted 8 lines
Quoted 2 lines

---

As I understand it dpath helper is allowed as long as we are not in NMI/interrupt context, so these should be fine to add.

The corresponding bcc discussion thread is here:
https://github.com/iovisor/bcc/issues/3527

Quoted 22 lines
Quoted 20 lines
  kernel/trace/bpf_trace.c | 2 ++
  1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
  BTF_ID(func, dentry_open)
  BTF_ID(func, vfs_getattr)
  BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
  BTF_SET_END(btf_allowlist_d_path)
 
  static bool bpf_d_path_allowed(const struct bpf_prog *prog)
Signature · 1 line
2.25.1
#3 lore raw
Quoted 27 lines · Yonghong Song
Quoted 5 lines · John Fastabend
Quoted 4 lines · Hengqi Chen

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

Quoted 8 lines
Quoted 2 lines

---

As I understand it dpath helper is allowed as long as we are not in NMI/interrupt context, so these should be fine to add.

The corresponding bcc discussion thread is here:

   https://github.com/iovisor/bcc/issues/3527
Quoted 4 lines
Quoted 4 lines
  kernel/trace/bpf_trace.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 11 lines
Quoted 11 lines

kernel/trace/bpf_trace.c BTF_ID(func, vfs_fallocate) · line 866

Quoted 11 lines
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
  BTF_ID(func, dentry_open)
  BTF_ID(func, vfs_getattr)
  BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
  BTF_SET_END(btf_allowlist_d_path)

That feels incomplete.
I know we can add more later, but why these two and not vfs_readv ? security_file_permission should probably be added as well ? Along with all sys_* entry points ?

#4 lore raw
Quoted 28 lines · Alexei Starovoitov
Quoted 27 lines · Yonghong Song
Quoted 5 lines · John Fastabend
Quoted 4 lines · Hengqi Chen

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

Quoted 8 lines
Quoted 2 lines

---

As I understand it dpath helper is allowed as long as we are not in NMI/interrupt context, so these should be fine to add.

The corresponding bcc discussion thread is here:

    https://github.com/iovisor/bcc/issues/3527
Quoted 4 lines
Quoted 4 lines
   kernel/trace/bpf_trace.c | 2 ++
   1 file changed, 2 insertions(+)
Quoted 16 lines
Quoted 11 lines
Quoted 11 lines

kernel/trace/bpf_trace.c BTF_ID(func, vfs_fallocate) · line 866

Quoted 11 lines
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
   BTF_ID(func, dentry_open)
   BTF_ID(func, vfs_getattr)
   BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
   BTF_SET_END(btf_allowlist_d_path)

That feels incomplete.
I know we can add more later, but why these two and not vfs_readv ? security_file_permission should probably be added as well ? Along with all sys_* entry points ?

The first argument of bpf_d_path is "struct path *, path" which needs to be a BTF_ID w.r.t. verifier.

I think maybe we should target the common kernel functions which has "struct path *" or "struct file *" arguments?

vfs_readv and security_file_permission or other possible candidates are not added since there are no use case for those yet. But agree that adding some vfs_* calls and security_file* options are a good call since they could be used in a different situation and adding them may save another kernel patch.

The syscall entry points typically only contains fd. Although bpf program might hack to do something to convert fd to a file, I still think this is a unlikely use case.

#5 lore raw
Quoted 60 lines · Yonghong Song
Quoted 28 lines · Alexei Starovoitov
Quoted 27 lines · Yonghong Song
Quoted 5 lines · John Fastabend
Quoted 4 lines · Hengqi Chen

Add vfs_read and vfs_write to bpf_d_path allowlist. This will help tools like IOVisor's filetop to get full file path.

Quoted 8 lines
Quoted 2 lines

---

As I understand it dpath helper is allowed as long as we are not in NMI/interrupt context, so these should be fine to add.

The corresponding bcc discussion thread is here:
    https://github.com/iovisor/bcc/issues/3527

Quoted 4 lines
Quoted 4 lines

   kernel/trace/bpf_trace.c | 2 ++

   1 file changed, 2 insertions(+)
Quoted 16 lines
Quoted 11 lines
Quoted 11 lines

kernel/trace/bpf_trace.c BTF_ID(func, vfs_fallocate) · line 866

Quoted 11 lines
kernel/trace/bpf_trace.c +2 -0
index 64bd2d84367f..6d3f951f38c5 100644
@@ -861,6 +861,8 @@ BTF_ID(func, vfs_fallocate)
    BTF_ID(func, dentry_open)
    BTF_ID(func, vfs_getattr)
    BTF_ID(func, filp_close)
+BTF_ID(func, vfs_read)
+BTF_ID(func, vfs_write)
    BTF_SET_END(btf_allowlist_d_path)

That feels incomplete.
I know we can add more later, but why these two and not vfs_readv ? security_file_permission should probably be added as well ? Along with all sys_* entry points ?

The first argument of bpf_d_path is "struct path *, path" which needs to be a BTF_ID w.r.t. verifier.

I think maybe we should target the common kernel functions which has "struct path *" or "struct file *" arguments?

vfs_readv and security_file_permission or other possible candidates are not added since there are no use case for those yet. But agree that adding some vfs_* calls and security_file* options are a good call since they could be used in a different situation and adding them may save another kernel patch.

Quoted 3 lines

The syscall entry points typically only contains fd. Although bpf program might hack to do something to convert fd to a file, I still think this is a unlikely use case.

Thanks for the review and suggestions.

I will send a v2 for review.

Thanks,
Hengqi