Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1685604rwl; Wed, 5 Apr 2023 22:50:29 -0700 (PDT) X-Google-Smtp-Source: AKy350aXJ8GohuXS/VTZicujg5yC7IILGONRYTfViNg9QqQytB1vQYrwylTaFtZc+eDE+nlT8VSz X-Received: by 2002:a62:7b44:0:b0:623:c943:a2f8 with SMTP id w65-20020a627b44000000b00623c943a2f8mr8119543pfc.20.1680760229384; Wed, 05 Apr 2023 22:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680760229; cv=none; d=google.com; s=arc-20160816; b=ovYQg/3TOUB+GVyhd8iA/8Aioc/FyH0ISOewihuUtzmA3IiZfb59EAsAoGe7Og+1/V 2zo/rvELmmwdGdtxyXBnQMu7JyNCiHBlKUeVQv6+Rpgy+c5ALASB/D9mpMd9bHWjsmdR YVukatMTQun+bYuBxJEVaCy628BK8yag0dSSLtPZCa9bTtP/HsXVvGDkKgH8dvagOIkj yJHex62LpYzMrAxvpkZzsyFAHcy3h8bLCiK1IivL4DeDqd9vorJXLowXi7DybbYjvX2F yXjZ2blebDbY08wWGcBYe/np0e6obA2idBam2cAvgivlLRE5q7mUiONw9oU/XvEMYArT oW3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EvQwfvj8sW09bm2ffaurY8lazWy/P7dLqyu/bRtP2zc=; b=Uy9Fo82VIu3MvHFUUPDRjOAUDxTps9oe6cyoe+/UDXsqL6m4qUD7c+9fw+PKGJDGBR GxYCifyEmat0kZZ3shvonV+r+1pSHv+wFj0SrFVWKSUZ4/ZBdU0P79yS5D8LKr4V3O13 zvc8U4ryMGIUk0m5js2HkNi4Qdy5gGlXw6aUQd6md6HLTyLnXTrEv/kkXZ/9bc+jNlBT Kw5nbgJkqegXEjsmWegoxG7iTrRte9NDKBAE3wSLIs/s6OHhDCiycuGLj3OOa6EjcOrZ 5bDvG2fEsiB1TnX1JkzBTuZy/zPDVYRNQHMJjf1tV75FfCTDyJJb+YHJim8DYKq6abYh d8Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mgnSgnKF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z15-20020aa7948f000000b005a85d73f825si595077pfk.125.2023.04.05.22.50.17; Wed, 05 Apr 2023 22:50:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mgnSgnKF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233303AbjDFFom (ORCPT + 99 others); Thu, 6 Apr 2023 01:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbjDFFok (ORCPT ); Thu, 6 Apr 2023 01:44:40 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB6B1E57; Wed, 5 Apr 2023 22:44:36 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id bi39so4519285qkb.13; Wed, 05 Apr 2023 22:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680759876; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EvQwfvj8sW09bm2ffaurY8lazWy/P7dLqyu/bRtP2zc=; b=mgnSgnKFVTMlcB79EOAEWpjNaxIo8e65mw+PZO9pM0lD0MhTEtHgIkZQJ0YWscS2oj SDvVExAgDJcNhVnm3qMN3x6qFKjv/afkbME/gnQMgNIqxtiKiGRknIEf5bKZK05y+TcT +v/JpxYjMhkDypLl4nAnaQC1Ood7E18Nr5hrd94dhAqOidCgd/OzJ0nsNDirZONe5Tam Zswy7p2/dR4vK6Nua9gzaaGBONktEqugJGU0x9pbpzVM6mbjiytMw/gLwaiITHfy8sqx CpzVgmfB969m68N3Z0vRsWOUN1/LT9M9r16xbslRTDK7JWPCo5G5CI6sv2TqpAC50cWV 1MXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680759876; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvQwfvj8sW09bm2ffaurY8lazWy/P7dLqyu/bRtP2zc=; b=7Jxq9M0Kn3BhNm1FDr+C90W+hc3NhpisWW4+3e4Yam9PIBuK8v0BCdPmP6z0oF+WXu HVCznMBoJhOlqjd1CGcEnv4/dY1mSRFNpF4NFQxv4YYfPyM27QR8qk6ZYyI5IGqTmckp MVvMrAbeJHRszzdCY9hqJH8nek2caOkU7jyXOoRADxYvtPyaMIs0D1a9p6Qd5XVTZe/p qFXwtLY9Op7+F48cx2A6gnOA1VG7VVhwhWcNwFLYB/b5tlMO7j3xjwprsC7h5z49bxN0 cpM2aJT5dzVix8TvyAFWKlhynZQ/4OhwYuA7YkoBWsigkC80kyDtEbeGZ85cxVQFt7gn bt4Q== X-Gm-Message-State: AAQBX9c9gCUohpVKZ5xYPg8CUklOczLHo5OIqpC5tdIO7ro+yKid+7lC 7qiR86NzauzwQnn28ngyX95oK3WfHpPPQXgdQQg= X-Received: by 2002:a05:620a:2596:b0:746:7857:d28b with SMTP id x22-20020a05620a259600b007467857d28bmr1969342qko.14.1680759875932; Wed, 05 Apr 2023 22:44:35 -0700 (PDT) MIME-Version: 1.0 References: <20230326092208.13613-1-laoar.shao@gmail.com> <20230402233740.haxb7lgfavcoe27f@dhcp-172-26-102-232.dhcp.thefacebook.com> <20230403225017.onl5pbp7h2ugclbk@dhcp-172-26-102-232.dhcp.thefacebook.com> <20230406020656.7v5ongxyon5fr4s7@dhcp-172-26-102-232.dhcp.thefacebook.com> In-Reply-To: From: Yafang Shao Date: Thu, 6 Apr 2023 13:43:59 +0800 Message-ID: Subject: Re: [RFC PATCH bpf-next 00/13] bpf: Introduce BPF namespace To: Alexei Starovoitov Cc: Song Liu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 6, 2023 at 12:24=E2=80=AFPM Alexei Starovoitov wrote: > > On Wed, Apr 5, 2023 at 8:22=E2=80=AFPM Yafang Shao = wrote: > > > > On Thu, Apr 6, 2023 at 11:06=E2=80=AFAM Alexei Starovoitov > > wrote: > > > > > > On Wed, Apr 5, 2023 at 7:55=E2=80=AFPM Yafang Shao wrote: > > > > > > > > It seems that I didn't describe the issue clearly. > > > > The container doesn't have CAP_SYS_ADMIN, but the CAP_SYS_ADMIN is > > > > required to run bpftool, so the bpftool running in the container > > > > can't get the ID of bpf objects or convert IDs to FDs. > > > > Is there something that I missed ? > > > > > > Nothing. This is by design. bpftool needs sudo. That's all. > > > > > > > Hmm, what I'm trying to do is make bpftool run without sudo. > > This is not a task that is worth solving. > Then the container with CAP_BPF enabled can't even iterate its bpf progs ..= . > > > > Some questions, > > > > - What if the process exits after attaching the bpf prog and the pr= og > > > > is not auto-detachable? > > > > For example, the reuserport bpf prog is not auto-detachable. Afte= r > > > > pins the reuserport bpf prog, a task can attach it through the pinn= ed > > > > bpf file, but if the task forgets to detach it and the pinned file = is > > > > removed, then it seems there's no way to figure out which task or > > > > cgroup this prog belongs to... > > > > > > you're saying that there is a bpf prog in the kernel without > > > corresponding user space ? > > > > No, it is corresponding to user space. For example, it may be > > corresponding to a socket fd, or a cgroup fd. > > > > > Meaning no user space process has an FD > > > that points to this prog or FD to a map that this prog is using? > > > In such a case this is truly kernel bpf prog. It doesn't belong to cg= roup. > > > > > > > Even if it is kernel bpf prog, it is created by a process. The user > > needs to know which one created it. > > In some situations it's certainly interesting to know which process > loaded a particular program. > In many other situations it's irrelevant. > For example, the process that loaded a prog could have been moved to a > different cgroup. > If you want to track the loading you need to install bpf_lsm > that monitors prog_load hook and collect that info. > It's not the job of the kernel to do it. > Agreed with you that we can add lots of hooks to track every detail of the operations. But it is not free. More hooks, more overhead. If we can change the kernel to make it lightweight, why not... > > > > - Could you pls. explain in detail how to get comm, pid, or cgroup > > > > from a pinned bpffs file? > > > > > > pinned bpf prog and no user space holds FD to it? > > > It's not part of any cgroup. Nothing to print. > > > > As I explained above, even if it holds nothing, the user needs to know > > the information from it. For example, if it is expected, which one > > created it? > > See the answer above. The kernel has enough hooks already to provide > this information to user space. No kernel changes necessary. --=20 Regards Yafang