Hi, On 11/16/2022 3:16 AM, Martin KaFai Lau wrote: > On 11/10/22 10:34 PM, Hou Tao wrote: >> From: Hou Tao <houtao1@xxxxxxxxxx> >> >> For many bpf iterator (e.g., cgroup iterator), iterator link acquires >> the reference of iteration target in .attach_target(), but iterator link >> may be closed before or in the middle of iteration, so iterator will >> need to acquire the reference of iteration target as well to prevent >> potential use-after-free. To avoid doing the acquisition in >> .init_seq_private() for each iterator type, just pin iterator link in >> iterator. > > iiuc, a link currently will go away when all its fds closed and pinned file > removed. After this change, the link will stay until the last iter is > closed(). Before then, the user space can still "bpftool link show" and even > get the link back by bpf_link_get_fd_by_id(). If this is the case, it would > be useful to explain it in the commit message. Yes, the iterator link is still reachable from "bpftool link show" and bpf_link_get_fd_by_id(). > > and does this new behavior make sense when comparing with other link types? Have not considered about that. It seems that other link type will not be used as an input for the creation of a bpf object (e.g., iterator). But if the fd of other link type is closed, the link will be released. So after the fix in v2, the behavior of iterator link will be different with other link types. > >> >> Fixes: d4ccaf58a847 ("bpf: Introduce cgroup iter") >> Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> >> --- >> kernel/bpf/bpf_iter.c | 21 ++++++++++++++------- >> 1 file changed, 14 insertions(+), 7 deletions(-) >> .