Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6770848rwb; Wed, 10 Aug 2022 00:20:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR55jKN2E6tyE+A1ICERARsOWG7HPxi9Fv6OddLTj8rzaHSvFv0+suz5cARvq9yGtGr6Hups X-Received: by 2002:aa7:982f:0:b0:52d:9787:c5c5 with SMTP id q15-20020aa7982f000000b0052d9787c5c5mr26303109pfl.24.1660116039335; Wed, 10 Aug 2022 00:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660116039; cv=none; d=google.com; s=arc-20160816; b=R0jnaHkDNE2dg/5wY9rP6W3YovdwXiiSyuyAkjjM8A5igWkt4jrOwomhDc5W7Ke96l 1pkEtBtzyXZuR+HUQBy1ry28j8GrSBWg9oB0gaP45zTOCkgho7pPV3eirSrUNxMa1Y2Q UKjEqKR43cqElqnKbSQQ7UTcC79VrNbQBeLkLAyP+wyW5bZoCZ1Qo1DQ4PBBT46MBfCG 1heY9HwWWhSOVJv2bSqWz5mHBAuRJ5QNhTqOHFzTKjZ95u3z3hRSMgeeF+1KlY9hS1x4 D/TzbtP9Dw7Bt/AI6C+8yqBsP4/GEx19Q9rZXLn5r7z1OJnxpxF6zz/hpKFRF3tOa0lM Cpsg== 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=s/g1jGP9DmVuf1qGmI16BGeQdTRGm51fgmAVNuH3Cg8=; b=tAqMVVkavPti9j/WX33NOlbmO56KMgPM5vpNBCwcXWsWowgeNtHHx5gwjUdmP99+S0 1MxW1rIDBsXq7/gmz1fEolkRkyYhBarfEwSDd8W+pHEou5ZedVtqnxfI3HaztTs6jo/E rKBCcvik5OQuxkZy9Ur2N6iTsYNA4xRUFO9QUky3Cewfb60yk99hPkR1NycTJrZ/U+Xa jnD3sRy7OuAeXFEQx6BMTJE2hlMSoiNQhXZc2DSWyDYkO+Tidh6HoNQVQHwn2uAqscg0 iMftGojiaEkQDz9H+uCfVY+bnAjSl3fu0MLKKar/EyplSfL3lP/NeuCvs1aMYA+SOlTM JWuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="fcZG0t7/"; 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 g20-20020a056a0023d400b005256b0ab23bsi809281pfc.191.2022.08.10.00.20.26; Wed, 10 Aug 2022 00:20:39 -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="fcZG0t7/"; 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 S231482AbiHJG7h (ORCPT + 99 others); Wed, 10 Aug 2022 02:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbiHJG7R (ORCPT ); Wed, 10 Aug 2022 02:59:17 -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 DE5EF72EFA for ; Tue, 9 Aug 2022 23:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660114753; 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=s/g1jGP9DmVuf1qGmI16BGeQdTRGm51fgmAVNuH3Cg8=; b=fcZG0t7/HGtd0hIjm7lxpGpGvZoSrbGs+F428w1C7cBIAdTo9YqV4hJWpKI3hzEHN4nqKC lzZ1HlUNHryDKXCBAEmBZAbnZC88MUfJF9ZbhM2z41GD7XqwSqsIXwWOVcmn5ata439tY3 NFu0Df9aPNPD2ZakLrascWQUlleyjjE= 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-125-fIfyWb7CPO-V6M-yVKGyoQ-1; Wed, 10 Aug 2022 02:59:09 -0400 X-MC-Unique: fIfyWb7CPO-V6M-yVKGyoQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25D513C0F394; Wed, 10 Aug 2022 06:59:08 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6DC1C15BA1; Wed, 10 Aug 2022 06:59:07 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id D768D1C00A9; Wed, 10 Aug 2022 08:59:06 +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 , Kumar Kartikeya Dwivedi , Artem Savkov Subject: [PATCH bpf-next v5 1/3] bpf: add destructive kfunc flag Date: Wed, 10 Aug 2022 08:59:03 +0200 Message-Id: <20220810065905.475418-2-asavkov@redhat.com> In-Reply-To: <20220810065905.475418-1-asavkov@redhat.com> References: <20220810065905.475418-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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,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 KF_DESTRUCTIVE flag for destructive functions. Functions with this flag set will require CAP_SYS_BOOT capabilities. Signed-off-by: Artem Savkov --- Documentation/bpf/kfuncs.rst | 9 +++++++++ include/linux/btf.h | 3 ++- kernel/bpf/verifier.c | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/bpf/kfuncs.rst b/Documentation/bpf/kfuncs.rst index c8b21de1c772..781731749e55 100644 --- a/Documentation/bpf/kfuncs.rst +++ b/Documentation/bpf/kfuncs.rst @@ -152,6 +152,15 @@ ensure the integrity of the operation being performed on the expected object. The KF_SLEEPABLE flag is used for kfuncs that may sleep. Such kfuncs can only be called by sleepable BPF programs (BPF_F_SLEEPABLE). +2.4.7 KF_DESTRUCTIVE flag +-------------------------- + +The KF_DESTRUCTIVE flag is used to indicate functions calling which is +destructive to the system. For example such a call can result in system +rebooting or panicking. Due to this additional restrictions apply to these +calls. At the moment they only require CAP_SYS_BOOT capability, but more can be +added later. + 2.5 Registering the kfuncs -------------------------- diff --git a/include/linux/btf.h b/include/linux/btf.h index 976cbdd2981f..ad93c2d9cc1c 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -49,7 +49,8 @@ * for this case. */ #define KF_TRUSTED_ARGS (1 << 4) /* kfunc only takes trusted pointer arguments */ -#define KF_SLEEPABLE (1 << 5) /* kfunc may sleep */ +#define KF_SLEEPABLE (1 << 5) /* kfunc may sleep */ +#define KF_DESTRUCTIVE (1 << 6) /* kfunc performs destructive actions */ struct btf; struct btf_member; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 28b02dc67a2a..2c1f8069f7b7 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