Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3118496imw; Mon, 11 Jul 2022 02:07:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZ0svfLRz9AlPGmUwGkqB2ddSatB9DJuXUOZOGO598bZEF1Nb8uMvlTWbJ9hPVx7RGaw20 X-Received: by 2002:aa7:cf08:0:b0:43a:6d32:f71d with SMTP id a8-20020aa7cf08000000b0043a6d32f71dmr23304833edy.192.1657530469618; Mon, 11 Jul 2022 02:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657530469; cv=none; d=google.com; s=arc-20160816; b=YFsMl9wDK8TceRsYE6n0dthjkIyS4bJWzkdnYBFhTzGydJOy7H8aEZGRRV/Ck6PNnw 8pgCKWNQUWdWq88VpWeL/q5h81uipu7QSDjqefTRYiNeWvCRL21Bq7bdU3RPeCKLi5Dv Z5KjEHZ7UGYzDHSx+4BGi1yrsP1iWx+qAIAhoX2wTvzDraeXEAPYIj/HIAK+lDxMKbRh uU4+6+TFZqicfQMPRzve18A5CQxofFzn6zMsCffHueda478sxZ53TDKQpcS8antrFTVa oIwSlV6hwHbQzP0j4Ffmn79x8s5y30IQGLt27/1eXwoLEiyWFGztkQX9tSWTZBuoyieM WJmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YEy+JbF4/MHQmoWPD6TNS3XHUSO00yIucme0xMgXZWk=; b=pSI8Srr8um72CF5ghlLfMuovXusPE83AleeaYzw9irPH7ENkSmFUSozKW8l9IbAwXF Q6MyXLqJsOBf3onJmnTVUxAitwpwhS4F+om863Y+zuLK87HeuFq/L3RRkIgAKxjpXLy6 UycIAV3prRR7crnZr1itpP0qL6lCJf2y+eDwGxBBxHWP2gsKESZrLx6ZseeIvPymwuAE ywfFU+HVHGaBJtvuKOB+/SQo37+lDPFDjWovBM4FixZtzW9EksTxmerT5nFBeXnl2UA6 Tt4S7dys0Qd2QsuAkHu+3T2/i4/aJbbmZ/y42rHtKAr+bOr5wRAxKjVYfdk4HzT5jHMc 4oaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WyNR1nNm; 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 l2-20020aa7d942000000b00435abcf8f71si9454427eds.142.2022.07.11.02.07.24; Mon, 11 Jul 2022 02:07:49 -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=WyNR1nNm; 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 S230258AbiGKIdS (ORCPT + 99 others); Mon, 11 Jul 2022 04:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbiGKIci (ORCPT ); Mon, 11 Jul 2022 04:32:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF1A11F61D for ; Mon, 11 Jul 2022 01:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657528354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YEy+JbF4/MHQmoWPD6TNS3XHUSO00yIucme0xMgXZWk=; b=WyNR1nNmvAZYom/NAZ6kt+MC8bdHsNPTNmD65NCeQ1zsgfIEC6PJ0jMNiw0fX8+r5CxSUO PEPq4RZR/Y4nSwlQOycFVke7s8vQ5UnhQ7hv2NkTNPx1I+4s2a83wQVabpDKkiUmU8p2bh 2dnHmPAn0xsjkOcfWNPyIBuCjH//wl0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-C_R0PKqGPtiBMFNB8fnwxA-1; Mon, 11 Jul 2022 04:32:23 -0400 X-MC-Unique: C_R0PKqGPtiBMFNB8fnwxA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3097C80029D; Mon, 11 Jul 2022 08:32:23 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 097E01121314; Mon, 11 Jul 2022 08:32:22 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id F1F241C0258; Mon, 11 Jul 2022 10:32:21 +0200 (CEST) From: Artem Savkov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrea Arcangeli , Artem Savkov Subject: [RFC PATCH bpf-next 2/4] bpf: add BPF_F_DESTRUCTIVE flag for BPF_PROG_LOAD Date: Mon, 11 Jul 2022 10:32:18 +0200 Message-Id: <20220711083220.2175036-3-asavkov@redhat.com> In-Reply-To: <20220711083220.2175036-1-asavkov@redhat.com> References: <20220711083220.2175036-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Add a BPF_F_DESTRUCTIVE will be required to be supplied to BPF_PROG_LOAD for programs to utilize destructive helpers such as bpf_panic(). Signed-off-by: Artem Savkov --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 6 ++++++ kernel/bpf/syscall.c | 4 +++- tools/include/uapi/linux/bpf.h | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 77972724bed7..43c008e3587a 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1041,6 +1041,7 @@ struct bpf_prog_aux { bool sleepable; bool tail_call_reachable; bool xdp_has_frags; + bool destructive; bool use_bpf_prog_pack; /* BTF_KIND_FUNC_PROTO for valid attach_btf_id */ const struct btf_type *attach_func_proto; diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index e81362891596..4423874b5da4 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1121,6 +1121,12 @@ enum bpf_link_type { */ #define BPF_F_XDP_HAS_FRAGS (1U << 5) +/* 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) + /* link_create.kprobe_multi.flags used in LINK_CREATE command for * BPF_TRACE_KPROBE_MULTI attach type to create return probe. */ diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 1ce6541d90e1..779feac2dc7d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2449,7 +2449,8 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) BPF_F_TEST_STATE_FREQ | BPF_F_SLEEPABLE | BPF_F_TEST_RND_HI32 | - BPF_F_XDP_HAS_FRAGS)) + BPF_F_XDP_HAS_FRAGS | + BPF_F_DESTRUCTIVE)) return -EINVAL; if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && @@ -2536,6 +2537,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) prog->aux->offload_requested = !!attr->prog_ifindex; prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE; prog->aux->xdp_has_frags = attr->prog_flags & BPF_F_XDP_HAS_FRAGS; + prog->aux->destructive = attr->prog_flags & BPF_F_DESTRUCTIVE; err = security_bpf_prog_alloc(prog->aux); if (err) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index e81362891596..4423874b5da4 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1121,6 +1121,12 @@ enum bpf_link_type { */ #define BPF_F_XDP_HAS_FRAGS (1U << 5) +/* 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) + /* link_create.kprobe_multi.flags used in LINK_CREATE command for * BPF_TRACE_KPROBE_MULTI attach type to create return probe. */ -- 2.35.3