Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5377053rwb; Mon, 8 Aug 2022 18:16:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rILEd87xTfWS+D+5ef+vbPr0ofVCcg4oyikqMeT9ow9Nin/U+RLrCMLqeP66H/C2M8vkI X-Received: by 2002:aa7:cf13:0:b0:43d:603a:b736 with SMTP id a19-20020aa7cf13000000b0043d603ab736mr20627656edy.20.1660007765093; Mon, 08 Aug 2022 18:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660007765; cv=none; d=google.com; s=arc-20160816; b=Z9s7miS4vh42fFZdYOBs2OQ26yt29zebuuPjeupdMPy3Hb7Go9K5DA+4H0AyQ2CA9c 0teSCU5xmUMHlNf93V8F/KiZQljkXwuy7zvDIMztHftw71PGsjpqf+LAXNvJyUPHaNlb tJKkL13TyPRbbynD4yNnjfj9MLw8fQ0BvKQq3znY0S3BVDGCVU7R3/USSIGaOC+GDTYK QWWg68hWVgLx35GiAArqXmr1tv8aTpsdf3+VBntXpjGxt6YcLHjalGPz2yn0Ae3W13p7 nythysUsv2S+CNc4GtLSTbjKt77Qw7NWItp4Vv/QkCyINVJ6kqsj2KIXyuASXixCDzn1 dAIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RxAt0vmII6A8aZUqkoL3eMGfHTRmNL+sO4A/bXssgaI=; b=BPc8yDLQnF7+fBO5E7wHCoBEe8NxAU4pweLae+I6eIdocHbTMSrIXe+tRY4QJFnwBU OLhpTHJeE+SOpkchAjW/+xfCt0EHK/eMSD1us9xl9FSV/TECuplmTnK1IjpusdVi3Z/D JeGejvlxHfk3rNwaoTNBvERpAqQAUofLPRB2oUc9pCXc5Uqz9Rd1qL3YXEqwCXcC6y8x OcOWTRBXj0K5sEMcbVlN2jglfQEvYekkiqMxchiWancIJhxLYXFbk6VPoU9MXla5Mr7B 5btzfJw/LDHpvhSvdPpg2icFln7P7bDi/b1IA1kbzd4ReyRGzimmmD5n5vvDE3VRWX7E mDnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f7izXbNb; 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 v11-20020a056402348b00b0043d7c648352si8646795edc.338.2022.08.08.18.15.39; Mon, 08 Aug 2022 18:16:05 -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=f7izXbNb; 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 S244755AbiHIAt2 (ORCPT + 99 others); Mon, 8 Aug 2022 20:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244457AbiHIAt1 (ORCPT ); Mon, 8 Aug 2022 20:49:27 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A433C25F7; Mon, 8 Aug 2022 17:49:25 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id g18so5794265ilk.4; Mon, 08 Aug 2022 17:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=RxAt0vmII6A8aZUqkoL3eMGfHTRmNL+sO4A/bXssgaI=; b=f7izXbNbbMPcRpY/Rm0j5riq5OjXFnpyFZNSF9U/jaN1nyuuY3FySKBoivXnZyvtTS usTnNcvFi5hW5sg70MzT8CWelhQS451hgUiOh+olYak4sKmdqMLI0YYcWfKNKf23ZoB/ UGZHqTuzpT35xm50sSai1PPOmAEGw8oA+Yw+kCYlrf+edcqFIAPwI81W18TEUwC+85VY drgDm5tvswMULunlbrIi/cFS3sJKyY/CY30SYoTFSBopTj23LYZrBD0rss6gwa/URJ9e NQIPMcXYT+beYYK1MXcKjWAWQjA1r7UjxQZQigCGuqoTGe1F2oWXgV9icsQfFBhrw/kE ReUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=RxAt0vmII6A8aZUqkoL3eMGfHTRmNL+sO4A/bXssgaI=; b=ZaJBcbt5U9PtQnorBu7mD1AIt8ZScqff9mNfqMIiqrzBR0k83YsdNhTU97wfZMXEFK UN9QDHfk64EDHfXO9ef0WudWWEWER1zR9y0Ss6BKyzv1S2YZ/w1Zmx9UCmHnW7d9R8Te r8pqTASyOORMZKiN3FMRTH/urEN48gXMeHpdRkbasob6rCk8J0rKbPtYGfOq0Au37tFg PEn5MIk8u56JpoGoBM8AIzeDLED6zecQKUqszrAtplUES2owxJOo0Tx0EH6Pv5UnjXdi wEpYbmeaoO/frHUxjj6GmYWJ4R/c5Ppgbw0GJt9ByMUWVyW/mXOOtgzshNK2e10fTKbN k6YQ== X-Gm-Message-State: ACgBeo2IRDxRvVq20dQs67YY7hV/+BsfrZacRaqkFkNDCtrAFb/jqWpQ zMJZBXGAcNA32NQwJova1noxr6Ivg8VWVMalvUQ= X-Received: by 2002:a05:6e02:198c:b0:2e0:ac33:d22 with SMTP id g12-20020a056e02198c00b002e0ac330d22mr5261136ilf.219.1660006165003; Mon, 08 Aug 2022 17:49:25 -0700 (PDT) MIME-Version: 1.0 References: <20220808094623.387348-1-asavkov@redhat.com> <20220808094623.387348-2-asavkov@redhat.com> In-Reply-To: From: Kumar Kartikeya Dwivedi Date: Tue, 9 Aug 2022 02:48:49 +0200 Message-ID: Subject: Re: [PATCH bpf-next v3 1/3] bpf: add destructive kfunc flag To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu , Daniel Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Tue, 9 Aug 2022 at 02:37, Andrii Nakryiko wrote: > > On Mon, Aug 8, 2022 at 6:33 AM Kumar Kartikeya Dwivedi wrote: > > > > On Mon, 8 Aug 2022 at 14:41, Artem Savkov wrote: > > > > > > On Mon, Aug 08, 2022 at 02:14:33PM +0200, Kumar Kartikeya Dwivedi wrote: > > > > On Mon, 8 Aug 2022 at 11:48, Artem Savkov wrote: > > > > > > > > > > Add KF_DESTRUCTIVE flag for destructive functions. Functions with this > > > > > flag set will require CAP_SYS_BOOT capabilities. > > > > > > > > > > Signed-off-by: Artem Savkov > > > > > --- > > > > > include/linux/btf.h | 1 + > > > > > kernel/bpf/verifier.c | 5 +++++ > > > > > 2 files changed, 6 insertions(+) > > > > > > > > > > diff --git a/include/linux/btf.h b/include/linux/btf.h > > > > > index cdb376d53238..51a0961c84e3 100644 > > > > > --- a/include/linux/btf.h > > > > > +++ b/include/linux/btf.h > > > > > @@ -49,6 +49,7 @@ > > > > > * for this case. > > > > > */ > > > > > #define KF_TRUSTED_ARGS (1 << 4) /* kfunc only takes trusted pointer arguments */ > > > > > +#define KF_DESTRUCTIVE (1 << 5) /* kfunc performs destructive actions */ > > > > > > > > > > > > > Please also document this flag in Documentation/bpf/kfuncs.rst. > > > > > > Ok, will do. > > > > > > > And maybe instead of KF_DESTRUCTIVE, it might be more apt to call this > > > > KF_CAP_SYS_BOOT. While it is true you had a destructive flag for > > > > programs being loaded earlier, so there was a mapping between the two > > > > UAPI and kfunc flags, what it has boiled down to is that this flag > > > > just requires CAP_SYS_BOOT (in addition to other capabilities) during > > > > load. So that name might express the intent a bit better. We might > > > > soon have similar flags encoding requirements of other capabilities on > > > > load. > > > > > > > > The flag rename is just a suggestion, up to you. > > > > > > This makes sense right now, but if going forward we'll add stricter > > > signing requirements or other prerequisites we'll either have to rename > > > the flag back, or add those as separate flags. I guess the decision here > > > > IMO we should do that when the time comes, for now it should reflect > > the current state. > > But names should be also semantically meaningful, so KF_DESTRUCTIVE > explains that kfunc can do destructive operations, which is better > than just declaring that kfunc needs CAP_SYS_BOOT, as the latter is > current implementation detail which has no bearing on kfunc definition > itself. > > Unless we anticipate we'll have another "destructive" kfunc not using > KF_DESTRUCTIVE and instead we'll add some other > KF_CAP_SYS_WHATEVERELSE? > I just found it a bit odd that KF_DESTRUCTIVE would require CAP_SYS_BOOT. When thinking about what one would write in the docs: just that KF_DESTRUCTIVE kfuncs can do destructive operations? That doesn't really capture what the flag ends up doing to the kfunc (it limits use to those who have a certain cap on program load). There can be several destructive operations (e.g. a frequently mentioned socket kill helper that may be considered equally destructive for some workload) but would probably require CAP_NET_ADMIN instead. But anyway, I didn't really want to bikeshed over this :), we can give it a better name next time something like this is added, and just go with KF_DESTRUCTIVE for now. > > To me this helper requiring cap_sys_boot is just like how some > > existing stable helpers are gated behind bpf_capable or > > perfmon_capable. > > When it requires that the program calling it be signed, we can revisit this. > > > > > depends on whether some of non-destructive bpf programs might ever require > > > CAP_SYS_BOOT capabilities or not. > > > > These are just internal kernel flags, so refactoring/renaming is not a > > big deal when it is needed. E.g. we've changed just how kfuncs are > > registered twice since the support was added not long ago :). > > > > > > > > -- > > > Artem > > >