Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3102415imw; Mon, 11 Jul 2022 01:42:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3Qi4kQbOajScIGYEPyPYwMwnwRHu9lpithlRglWzApGeMT7IcjLKBGAhjpUPOMHlNwwa1 X-Received: by 2002:a65:6b8a:0:b0:3fc:4c06:8a8d with SMTP id d10-20020a656b8a000000b003fc4c068a8dmr14801845pgw.83.1657528926866; Mon, 11 Jul 2022 01:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657528926; cv=none; d=google.com; s=arc-20160816; b=SkbezEW1zu6eTxk0YrQkJd7UgIF0pB8ej8S5xUGOL7PtdAtAVuZ4IIVq1WF7m00Z3+ Fr+jBwBjiftypmSxTPhtUPlxeIumbaN7ZL3aMt6OT6gvroarkg/iue6BPEaNRKxZ+Txt unmeDM2oKx0UQVyEDKFFqLJO7FWE7pNzEh5UxitfUZtbemFA6SYaMxnpQcA4d8dywl7F bZ0NNDRUWHhDquxjr1jgTlbmnGX3GM8QWNnik98vcs78sfPTWZdpQvpr7lyr/W73LR85 CkwIUcuNaIr17rSqk6lMtyRq8qiESwLqhDGVtlk9yb+/yJFxZWDGduaf5qdRrLVK4YpP 9eJg== 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=aKGFy03TW0CXqndqD4MQz+oIb7kOoMG9F98zOmwauWM=; b=pXiDLs+ZX4UrlwnCV5VJcnBo4N97Lus+U3eBYuy33oVBpLIp7B65f7PNi99fhtizN+ iEXbSzt1wXXJS6fexlhYvYw6VnfM458Tq7CkvmfGyxZz2+BcIzKNXEMwI3uzywjNZwPp kQaVFhfoQm6ewxfUQgt+oWWb1rDm1K1vYOYT0JxHp2+N3YxpLuM8hcWsSrhuNbIg+ULv 40aiaDQ5a8J4H+AOr7lsD83UCBvEUeCYXHao1zv3S/72wHRe66wEa7JhI0GG94gdU5Up ThC8vC1CNAvJnJbdohcA/RkZr+DlRl3XZevxxwE/loqfugy3GLLVeRNt6UTdCU1INxg7 pGng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cOYgELOF; 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 i10-20020a170902cf0a00b0016bda9d975esi9166592plg.555.2022.07.11.01.41.54; Mon, 11 Jul 2022 01:42:06 -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=cOYgELOF; 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 S230296AbiGKIdN (ORCPT + 99 others); Mon, 11 Jul 2022 04:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230213AbiGKIci (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 140ED1F627 for ; Mon, 11 Jul 2022 01:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657528353; 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=aKGFy03TW0CXqndqD4MQz+oIb7kOoMG9F98zOmwauWM=; b=cOYgELOFjjTi6eKndFpzQEINIxJaiQ7DirIAi0U/UiFkWLSdYt3O2XFcjAKStjJvXwxsqj G+JeWIisFdXgWe2JZEMjSnkElaNMxBa7hxM4gKUl1POGrlbrJo8BjXeAPRubHtvisGcSWu mmxe8GuMRH3KAVm5j8IWYdKCh6yzKg8= 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-624-gSuQ_0p3PhyNcyK48n_gNw-1; Mon, 11 Jul 2022 04:32:23 -0400 X-MC-Unique: gSuQ_0p3PhyNcyK48n_gNw-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 2F606802D1F; 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 098DC1415118; Mon, 11 Jul 2022 08:32:22 +0000 (UTC) Received: by shodan.usersys.redhat.com (Postfix, from userid 1000) id DBED31C022D; 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 0/4] bpf_panic() helper Date: Mon, 11 Jul 2022 10:32:16 +0200 Message-Id: <20220711083220.2175036-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=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. This patchset adds bpf_panic() helper to do exactly that. I realize that even though there are multiple guards present, a helper like this is contrary to BPF being "safe", so this is sent as RFC to have a discussion on whether adding destructive capabilities is deemed acceptable. Artem Savkov (4): bpf: add a sysctl to enable destructive bpf helpers bpf: add BPF_F_DESTRUCTIVE flag for BPF_PROG_LOAD bpf: add bpf_panic() helper selftests/bpf: bpf_panic selftest include/linux/bpf.h | 8 + include/uapi/linux/bpf.h | 13 ++ kernel/bpf/core.c | 1 + kernel/bpf/helpers.c | 13 ++ kernel/bpf/syscall.c | 33 +++- kernel/bpf/verifier.c | 7 + kernel/trace/bpf_trace.c | 2 + tools/include/uapi/linux/bpf.h | 13 ++ .../selftests/bpf/prog_tests/bpf_panic.c | 144 ++++++++++++++++++ 9 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_panic.c -- 2.35.3