Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4536450rwb; Mon, 8 Aug 2022 02:49:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+bLYuLRZ3PAXkItEjqw9QvvkpxBpVBG9pzN6eylHp4mJKjfslhzzMGeThHReLoT1p9aEE X-Received: by 2002:aa7:db44:0:b0:43d:267c:edd9 with SMTP id n4-20020aa7db44000000b0043d267cedd9mr17266174edt.385.1659952161694; Mon, 08 Aug 2022 02:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659952161; cv=none; d=google.com; s=arc-20160816; b=nEGU5J2uLyMxffIbpOmgnevh4JpE/RNL+p38beGECMtQgoFxorjMbkNdFV/xGi+QBV gSKHEA7jpNvw5nEku8Wkyt//xucn3IMhO9lDe2AMpaghX6+A0MponapiO/rLCeGFQ77P srU12mY2MywhAbWYaZlkjq0SXaMu1HqLa4aOODdC/ClPQzHu+YZKgogplARHrSpvj2v4 jto+t1eZlgwEFo7lXnD/jPuYmjnvkAFeNbW0VWdbfRUA+KfdqUhn5PqfDAJbrqSWYrFv AFsEChFDAM6rgBQKg+/R8PeZAO1uBG+X6QD6oglt5dg+ZJjUiASdLOtjqVgrlGaqttHf dUWw== 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=7SC9sX1VIexkzEyJYdxGiKKWDAqjX7RUeviVfsqmj24=; b=Tj4mQ1PgbTGCmgYPKUQRcKqGnUS3sdwAEwI9vV7ncgzgaLIfKITQxb/eyTjohv8XTG IWw26fh0b5hCVIkch5a7Pfj1qTM6HUax6UdaKXw7qQVCCdUwVGmYD5VMGR/pya7M65XY +kpLmvytmwDTtozzj/3QPxs3fqFxe5Ac4Qms6AaEXy+q0K7dP4enQ8VDlyCgc0AHKDfX /PyhHUXUPCoBSCE4+DvtO9YQQMJKNlZFYUWGxFzKf/Yzvv+7+66HPaZQsz15IEsIiA09 InMRclr+E+hggdjpobQ6oSpFyEPSH5TZsNswQnQgISXEms1QqaoKTq6qEUIvun3O+j+2 HndA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LtuYF3pD; 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 fy3-20020a170906b7c300b007305b0156c9si8865542ejb.576.2022.08.08.02.48.56; Mon, 08 Aug 2022 02:49:21 -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=LtuYF3pD; 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 S242042AbiHHJqv (ORCPT + 99 others); Mon, 8 Aug 2022 05:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbiHHJqa (ORCPT ); Mon, 8 Aug 2022 05:46:30 -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 9192411A17 for ; Mon, 8 Aug 2022 02:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659951988; 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=7SC9sX1VIexkzEyJYdxGiKKWDAqjX7RUeviVfsqmj24=; b=LtuYF3pDdkh9ZBaycikUk0m0xVAe01tr0ZztAmFhZ479NK7BrFBD/8bAUdE9EfFUShj1kD S5vvFzGWm3bApXtTDW8LIVhoCnQ/aciwz7XWxv1QfAJHaVNMWdvE194onXOmgYh8lxwjXf EnRDoRkcRIJdDuUl/H0Ph4krC+eQuI0= 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-298-7RqlEHIBNyuL_dnjWu5pVA-1; Mon, 08 Aug 2022 05:46:25 -0400 X-MC-Unique: 7RqlEHIBNyuL_dnjWu5pVA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 21488811E81; Mon, 8 Aug 2022 09:46:25 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6CC41415116; Mon, 8 Aug 2022 09:46:24 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id CFDED1C0286; Mon, 8 Aug 2022 11:46:23 +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 , Daniel Vacek , Jiri Olsa , Song Liu , Daniel Xu , Artem Savkov Subject: [PATCH bpf-next v3 1/3] bpf: add destructive kfunc flag Date: Mon, 8 Aug 2022 11:46:21 +0200 Message-Id: <20220808094623.387348-2-asavkov@redhat.com> In-Reply-To: <20220808094623.387348-1-asavkov@redhat.com> References: <20220808094623.387348-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=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 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 */ struct btf; struct btf_member; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 096fdac70165..e52ca1631d3f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7584,6 +7584,11 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, func_name); return -EACCES; } + if (*kfunc_flags & KF_DESTRUCTIVE && !capable(CAP_SYS_BOOT)) { + verbose(env, "destructive kfunc calls require CAP_SYS_BOOT capabilities\n"); + return -EACCES; + } + acq = *kfunc_flags & KF_ACQUIRE; /* Check the arguments */ -- 2.37.1