From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42B1CC4332F for ; Thu, 17 Nov 2022 06:49:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234302AbiKQGtE (ORCPT ); Thu, 17 Nov 2022 01:49:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233023AbiKQGtD (ORCPT ); Thu, 17 Nov 2022 01:49:03 -0500 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09B7532E1 for ; Wed, 16 Nov 2022 22:49:01 -0800 (PST) Message-ID: <43bcd243-eea0-6cbe-b24b-640311fa1a83@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1668667739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DbFdZqyR/IcbE2815pvpT0gkN9Pqj+nQe3cjmyP0e4s=; b=gfM3Hl6UhOZsf88yQpkkRe7DOVIc37je6lIN/f8Rr8hObRu5CUrhpOBIVC9n6We7suh7RO 5MCu5AhqhhpXN1RIj8FyMH6s+pzqH4dJ/e5UgircIKQqLic11vzvRXI2D2T5O6HH0uZTgh bjTYt80797NzZ1VOASdqsyz10uMQXQ8= Date: Wed, 16 Nov 2022 22:48:54 -0800 MIME-Version: 1.0 Subject: Re: [PATCH bpf v2 1/3] bpf: Pin iterator link when opening iterator Content-Language: en-US To: Hao Luo , Hou Tao Cc: bpf , Yonghong Song , Andrii Nakryiko , Song Liu , Alexei Starovoitov , Daniel Borkmann , KP Singh , Stanislav Fomichev , Jiri Olsa , John Fastabend , Hou Tao , Alexei Starovoitov References: <20221111063417.1603111-1-houtao@huaweicloud.com> <20221111063417.1603111-2-houtao@huaweicloud.com> <33b5fc4e-be12-3aa8-b063-47aa998b951c@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 11/15/22 6:48 PM, Hao Luo wrote: > On Tue, Nov 15, 2022 at 5:37 PM Alexei Starovoitov > wrote: >> >> On Tue, Nov 15, 2022 at 11:16 AM Martin KaFai Lau wrote: >>> >>> On 11/10/22 10:34 PM, Hou Tao wrote: >>>> From: Hou Tao >>>> >>>> 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. >>> >>> and does this new behavior make sense when comparing with other link types? > > I think this is a unique problem in iter link. Because iter link is > the only link type that can generate another object. Should a similar solution as in the current map iter be used then? I am thinking, after all link fds are closed and its pinned files are removed, if it cannot stop the already created iter, it should at least stop new iter from being created?