Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5795180rwb; Tue, 9 Aug 2022 04:22:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR67ThNrTlKjGq5tNRp+qhD8MkejP9kD8QrzGp0VR36Fieb0xmQOn0FSZhzJC/iByBnG1Y5h X-Received: by 2002:a17:902:f609:b0:168:dcbe:7c4d with SMTP id n9-20020a170902f60900b00168dcbe7c4dmr22609742plg.169.1660044164430; Tue, 09 Aug 2022 04:22:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660044164; cv=none; d=google.com; s=arc-20160816; b=ZEjSZ88Dsvr2a1OjGLm8aN2bxxfhmmbSyY97vKixeUyUKp4UGewDYVYcQiGHVcw1z0 HLuPO0/5f6oYMrzkq+FiVKw3e9OpdGFQlRPhl2m7ViaR9+nXZB6/G1IPEhnCNYKpSgVu dl7BchklXeMonvF+hBtmg6xX3s5IGinFHBmZrX+zZJv+S8WVebw1N9tqExukUWoKh2Ou O1Ka8XX2Z1n37CaJQw+d4xVMBkavNe+Fm+FScrTqEvUhgEbk3jIzO94U0lXcLuJP+5N/ kFXB0PSfyqEHppCyHru+/rCOSRRkC3UaG6f4aV+aaU68zcyj3+jjDRw4lXjZevDQY6VH zLSQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=xTyqe2j7rpO6EUBF4khPbbfDOmMZA+TQt5p8dEfCV6c=; b=dpX6pCStAAPt22v+H8xZjbn4ERrydXU20aE4Y/PLxyUChPIyD503BRQihW/Blty63b vj5h3xkvSFWbazFMInUNg51RzyuEXy9g2tkusGJZfuApT2ACvgqaBvonTB4eoUM0iCnU 2w6AMQmGO2DOj7nIH1ZislBbNFn4/s/wkRIy9yuN6P8A6Hd0rv9IoMMzCi2JBsE6kwWF BsVWPGYU61D7m1wo5vIkwORfbb5Mp79OiPMoDoZBRi+zRl9XP4EmVMG7cERiPjXG+P00 ztOtqIqM9NfrtMOjjdM4DJmnylFQbi5I7WjSd6r6VthiOs3ea82r285pHrs9UqKQj9dG REog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/KFxq1f"; 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 b4-20020a655784000000b0041bc27c45besi13542220pgr.615.2022.08.09.04.22.27; Tue, 09 Aug 2022 04:22:44 -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="S/KFxq1f"; 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 S242746AbiHIKxr (ORCPT + 99 others); Tue, 9 Aug 2022 06:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242264AbiHIKx3 (ORCPT ); Tue, 9 Aug 2022 06:53:29 -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 6A8752DCE for ; Tue, 9 Aug 2022 03:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660042407; 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; bh=xTyqe2j7rpO6EUBF4khPbbfDOmMZA+TQt5p8dEfCV6c=; b=S/KFxq1fD+HX1WCTDbDbBY6wOYMDgqMNhwfduC4e/54elzY7GM6q4EdCj2Dz25tkzvh/zE tjLq+dyf6ZGHvpipCbNRyGLOY+I/afgoGxAiWU8899xAROln15JMljhIPy0OZbT31lQnPc ef6I7GhrFyQFzRm+q7iR4bNPKjPG/Rw= 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-652-zuYQ5ramMXawJslZnWPevA-1; Tue, 09 Aug 2022 06:53:19 -0400 X-MC-Unique: zuYQ5ramMXawJslZnWPevA-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 2F1D5280D223; Tue, 9 Aug 2022 10:53:19 +0000 (UTC) Received: from shodan.usersys.redhat.com (unknown [10.43.17.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E77C69459C; Tue, 9 Aug 2022 10:53:18 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id DA7E81C02A9; Tue, 9 Aug 2022 12:53:17 +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 v4 0/3] destructive bpf_kfuncs Date: Tue, 9 Aug 2022 12:53:14 +0200 Message-Id: <20220809105317.436682-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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 eBPF is often used for kernel debugging, and one of the widely used and powerful debugging techniques is post-mortem debugging with a full memory dump. Triggering a panic at exactly the right moment allows the user to get such a dump and thus a better view at the system's state. Right now the only way to do this in BPF is to signal userspace to trigger kexec/panic. This is suboptimal as going through userspace requires context changes and adds significant delays taking system further away from "the right moment". On a single-cpu system the situation is even worse because BPF program won't even be able to block the thread of interest. This patchset tries to solve this problem by allowing properly marked tracing bpf programs to call crash_kexec() kernel function. The only requirement for now to run programs calling crash_kexec() or other destructive kfuncs is CAP_SYS_BOOT capability. When signature checking for bpf programs is available it is possible that stricter rules will be applied to programs utilizing destructive kfuncs. Changes in v4: - Added description for KF_DESTRUCTIVE flag to documentation Changes in v3: - moved kfunc set registration to kernel/bpf/helpers.c Changes in v2: - BPF_PROG_LOAD flag dropped as it doesn't fully achieve it's aim of preventing accidental execution of destructive bpf programs - selftest moved to the end of patchset - switched to kfunc destructive flag instead of a separate set Changes from RFC: - sysctl knob dropped - using crash_kexec() instead of panic() - using kfuncs instead of adding a new helper Artem Savkov (3): bpf: add destructive kfunc flag bpf: export crash_kexec() as destructive kfunc selftests/bpf: add destructive kfunc test Documentation/bpf/kfuncs.rst | 9 +++++ include/linux/btf.h | 1 + kernel/bpf/helpers.c | 21 +++++++++++ kernel/bpf/verifier.c | 5 +++ net/bpf/test_run.c | 5 +++ .../selftests/bpf/prog_tests/kfunc_call.c | 36 +++++++++++++++++++ .../bpf/progs/kfunc_call_destructive.c | 14 ++++++++ 7 files changed, 91 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/kfunc_call_destructive.c -- 2.37.1