Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2426978imn; Tue, 2 Aug 2022 02:20:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tu4th/4IYBbPXn+Cd7FNIziX6RHwMCCQXuy66mIULuoHrMBdP20nm4bZW9ZJrFzUTYnajb X-Received: by 2002:a63:7e48:0:b0:41a:d6c9:7b4f with SMTP id o8-20020a637e48000000b0041ad6c97b4fmr16154148pgn.81.1659432024359; Tue, 02 Aug 2022 02:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659432024; cv=none; d=google.com; s=arc-20160816; b=OUcUj/d+yLz8LxIDP9uFjzyABCZL5fMLf2XhTwzYqBMgrXzvlMiRC1Hx+TcBUkYCWk gIVJLhhF+/9DuSkSEVKb3udaZ4xcfz7OOsbOnk7tI9sAwLlqDM6qYI/h0jFDBJmEbygR IBpRA1UuqtARmrud+sbOHN4GDyvwP35LOqAwAkpy7dKJvKOVEtJ6RadCLHkpmQux/+QV Meant7WLHVMYpwzTFWgZshrxAD5VGNqYA1lx13V6oYcVMcjpTG6r3/x0lyisnMIH/obr hzAofcY8ZJSKw2Pfw6Ce9+VfMHLq9+eReBfW1tOfK33C/UM39SbKga7vZD33a9z1GNtq n9jA== 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=8SOINSRv0lSmbOTTZ6/R5mAtck6H0iUHXeANGpWfrm4=; b=GiwbV4cu88PfC1ziTEFimyzhSKSgObJ9z3d2wGZ9SwTGYw0rstLStiD/Vk7LtwBBhJ r+i/qy1fYny2u+VEaaU/ojtcSJUaRwUwHa4K9RvTdLK0rSZmGnwH8poBOVBO9qCUuwsz pztBRD+9guFvXwBtqsbA98DCgRk6JtYhHFu/rf2853nNOXLPlhW5OMQ8ClVdPsiJbBHN Fx/XqtqswYiQCq7ZBFXtvPactgCbZIL7NQBmUqTFQnhkjP49Op71Tx+h8oleOw6kMFDp w57XdbgVfP9Z2mCR12mpSy8drUtvMjFIu4glxO8GtOtu6IcgjLWO9eBNrsxbzwTEMSEz CR3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rwa+qECW; 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 b9-20020a170902d88900b0016d9e47d2fasi14800601plz.71.2022.08.02.02.20.10; Tue, 02 Aug 2022 02:20:24 -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=Rwa+qECW; 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 S236336AbiHBJK6 (ORCPT + 99 others); Tue, 2 Aug 2022 05:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236275AbiHBJKp (ORCPT ); Tue, 2 Aug 2022 05:10:45 -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 2822A15A3D for ; Tue, 2 Aug 2022 02:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659431444; 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=8SOINSRv0lSmbOTTZ6/R5mAtck6H0iUHXeANGpWfrm4=; b=Rwa+qECW3zrXydRZm3Y/fVzrMMK3GVaZBkDk1UiaRuQELqfNlFXLgLEEYbWYvT4Xca2sWC tPsEBVW2jXKnzdn0f+DdIyaeJJG7Jc0wO6TEYXDjynBCv4b7a9vlSd9APhMdCR5uPzMXb/ nHYdxeTkdkc9wBY/RltIcOG+Zcrcl38= 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-394-4WC0f5O5OXeUuFp1yppU3g-1; Tue, 02 Aug 2022 05:10:33 -0400 X-MC-Unique: 4WC0f5O5OXeUuFp1yppU3g-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 C82AF2801761; Tue, 2 Aug 2022 09:10:32 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86E6C1121314; Tue, 2 Aug 2022 09:10:32 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id 81A8C1C0151; Tue, 2 Aug 2022 11:10:31 +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 v2 1/3] bpf: add destructive kfunc flag Date: Tue, 2 Aug 2022 11:10:28 +0200 Message-Id: <20220802091030.3742334-2-asavkov@redhat.com> In-Reply-To: <20220802091030.3742334-1-asavkov@redhat.com> References: <20220802091030.3742334-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 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 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.35.3