Re: [PATCH v2 bpf-next 1/4] bpf: introduce task_vma bpf_iter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/17/20 9:23 PM, Alexei Starovoitov wrote:
On Thu, Dec 17, 2020 at 8:33 PM Song Liu <songliubraving@xxxxxx> wrote:

ahh. I missed that. Makes sense.
vm_file needs to be accurate, but vm_area_struct should be accessed as ptr_to_btf_id.

Passing pointer of vm_area_struct into BPF will be tricky. For example, shall we
allow the user to access vma->vm_file? IIUC, with ptr_to_btf_id the verifier will
allow access of vma->vm_file as a valid pointer to struct file. However, since the
vma might be freed, vma->vm_file could point to random data.

I don't think so. The proposed patch will do get_file() on it.
There is actually no need to assign it into a different variable.
Accessing it via vma->vm_file is safe and cleaner.

I did not check the code but do you have scenarios where vma is freed but old vma->vm_file is not freed due to reference counting, but
freed vma area is reused so vma->vm_file could be garbage?


[1] ff9f47f6f00c ("mm: proc: smaps_rollup: do not stall write attempts on mmap_lock")

Thanks for this link. With "if (mmap_lock_is_contended())" check it should work indeed.

To make sure we are on the same page: I am using slightly different mechanism in
task_vma_iter, which doesn't require checking mmap_lock_is_contended(). In the
smaps_rollup case, the code only unlock mmap_sem when the lock is contended. In
task_iter, we always unlock mmap_sem between two iterations. This is because we
don't want to hold mmap_sem while calling the BPF program, which may sleep (calling
bpf_d_path).

That part is clear. I had to look into mmap_read_lock_killable() implementation
to realize that it's checking for lock_is_contended after acquiring
and releasing
if there is a contention. So it's the same behavior at the end.




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux