Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2582236imi; Mon, 25 Jul 2022 02:34:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLYYLP6udUwvlc0dNQm7of/FETvcRBssturg2rbbtPWxjCsr4ogxBQq0GrYW+1cI7iSikz X-Received: by 2002:a17:902:8508:b0:16c:46ff:53c8 with SMTP id bj8-20020a170902850800b0016c46ff53c8mr11622442plb.29.1658741652017; Mon, 25 Jul 2022 02:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658741652; cv=none; d=google.com; s=arc-20160816; b=c1rjIeEGPj0jEFEQuipDa+lLfvvrewrcG0uTy+aL3ZhY0yXPZeSn4ac7YjUelacDB2 eC722CzmWNdSeU5u10AC3prkVvD6R097hBQpmcogNF99zLFp0NK7AitKgdUJQeimAZoy sVc/Jy3lot8IfgBRW+VvXjWdjnttFN0d0wwJ7ibHxVuISTMT7AMDKSuP2of6p0rB0N2Y dNGdwgw0xt4H63J3CpHzLfs0stbW297PcEVsDTLsQ+HjXbwQSNYWGo4EDARgCBPkKxU+ I9rEi4FgWJMJX9OTCbh6UrWBgCpW1yHoniwNYbAciBjKbqgmu3mjsWAcjXw4srMFYC1z 7GTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=1QVqQ+wSo/PH7nffVgYDKhPQVUQyQA66yhZRbwATq3k=; b=WwcG2IzIGai/4ORExo97HV1I64h9V7/6s7/aUMC+v8K1YB9JgidkNP3U5GN5Ifgvpg xwvwlnYzaiONXBu7iZs2stJUe3/kwpv91+1XrS6JnA+t7XQ4PNYP21DpKj7d2GVBWMlH zKuXClBTwxOhPP0oxA417Vt/ROZMwwsFEun8U2uAewCMg9ItVD4eyNuxTUAXxJbN/qhX h4PQUoen5aekQC+iRkbhQWhvvc8RGh2rIAkNrXT1JW9yW3UnTFJzOO2reyTrsmMXhA23 7ZDH+Xrvlbt/ayN6s6x0LVf21nqn9fKyQAaRnmXb+2ld3ouLMQcZCl5q85eJI4xyInK5 +uJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bTWvMeT9; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i187-20020a62c1c4000000b0052b83e5c075si14254448pfg.88.2022.07.25.02.33.56; Mon, 25 Jul 2022 02:34:12 -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=@redhat.com header.s=mimecast20190719 header.b=bTWvMeT9; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234038AbiGYJ1h (ORCPT + 99 others); Mon, 25 Jul 2022 05:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233595AbiGYJ1f (ORCPT ); Mon, 25 Jul 2022 05:27:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B624A15A33 for ; Mon, 25 Jul 2022 02:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658741253; 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: in-reply-to:in-reply-to:references:references; bh=1QVqQ+wSo/PH7nffVgYDKhPQVUQyQA66yhZRbwATq3k=; b=bTWvMeT9akuYOGtqQveq3ZnduF7aX1bhXMKCE1KxkyJ0yrIop96DBzbZFPr1rqmZiFr3dG LJR56s3rX1VZqskmdPEX019MNgNHpjYgvsMQvPt5Vg8qYkyiPyW+DzoJz/05CfbvmWMLNt 1pq6LicKstitSuC0/LDU36GrKiI528Y= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-fb8431ylMo-6xzubwJD8BA-1; Mon, 25 Jul 2022 05:27:27 -0400 X-MC-Unique: fb8431ylMo-6xzubwJD8BA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A9E43801F51; Mon, 25 Jul 2022 09:27:27 +0000 (UTC) Received: from samus.usersys.redhat.com (unknown [10.43.17.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8315618EB5; Mon, 25 Jul 2022 09:27:25 +0000 (UTC) Date: Mon, 25 Jul 2022 11:27:23 +0200 From: Artem Savkov To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf , Network Development , LKML , Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu Subject: Re: [PATCH bpf-next 1/4] bpf: add BPF_F_DESTRUCTIVE flag for BPF_PROG_LOAD Message-ID: Mail-Followup-To: Alexei Starovoitov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf , Network Development , LKML , Andrea Arcangeli , Daniel Vacek , Jiri Olsa , Song Liu References: <20220720114652.3020467-1-asavkov@redhat.com> <20220720114652.3020467-2-asavkov@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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, Jul 21, 2022 at 09:32:51PM -0700, Alexei Starovoitov wrote: > On Thu, Jul 21, 2022 at 9:18 PM Artem Savkov wrote: > > > > On Thu, Jul 21, 2022 at 07:02:07AM -0700, Alexei Starovoitov wrote: > > > On Wed, Jul 20, 2022 at 4:47 AM Artem Savkov wrote: > > > > > > > > +/* If BPF_F_DESTRUCTIVE is used in BPF_PROG_LOAD command, the loaded program > > > > + * will be able to perform destructive operations such as calling bpf_panic() > > > > + * helper. > > > > + */ > > > > +#define BPF_F_DESTRUCTIVE (1U << 6) > > > > > > I don't understand what value this flag provides. > > > > > > bpf prog won't be using kexec accidentally. > > > Requiring user space to also pass this flag seems pointless. > > > > bpf program likely won't. But I think it is not uncommon for people to > > run bpftrace scripts they fetched off the internet to run them without > > fully reading the code. So the idea was to provide intermediate tools > > like that with a common way to confirm user's intent without > > implementing their own guards around dangerous calls. > > If that is not a good enough of a reason to add the flag I can drop it. > > The intent makes sense, but bpftrace will set the flag silently. > Since bpftrace compiles the prog it knows what helpers are being > called, so it will have to pass that extra flag automatically anyway. > You can argue that bpftrace needs to require a mandatory cmdline flag > from users to run such scripts, but even if you convince the bpftrace > community to do that everybody else might just ignore that request. > Any tool (even libbpf) can scan the insns and provide flags. > > Long ago we added the 'kern_version' field to the prog_load command. > The intent was to tie bpf prog with kernel version. > Soon enough people started querying the kernel and put that > version in there ignoring SEC("version") that bpf prog had. > It took years to clean that up. > BPF_F_DESTRUCTIVE flag looks similar to me. > Good intent, but unlikely to achieve the goal. Good point, I only thought of those who would like to use this, not the ones who would try to work around it. > Do you have other ideas to achieve the goal: > 'cannot run destructive prog by accident' ? > > If we had an UI it would be a question 'are you sure? please type: yes'. > > I hate to propose the following, since it will delay your patch > for a long time, but maybe we should only allow signed bpf programs > to be destructive? Anything I can think of is likely to be as easily defeated as the flag, requirement for destructive programs to be signed is not. So I like the idea. However I think that if bpf program signature checking is disabled on the system then destructive programs should be able to run with just CAP_SYS_BOOT. So maybe we can treat everything as this case until we have the ability to sign bpf programs? -- Artem