Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1261771imi; Fri, 1 Jul 2022 06:27:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sUp08HjfFu+ArCZ6v1U4P6Ou4RDgZRDNWmQprO4TQkwRYIFUAqg+V1oZnebKk4JieN7q1V X-Received: by 2002:a17:90b:4c0a:b0:1ec:d3b2:ed22 with SMTP id na10-20020a17090b4c0a00b001ecd3b2ed22mr16982208pjb.2.1656682022178; Fri, 01 Jul 2022 06:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656682022; cv=none; d=google.com; s=arc-20160816; b=W7g/RwwWdtjOWrSZX5muhmK+pdnHFnkxLzxzBHY/O6DzTmPEobHeaKCxAoyhxG+L5H 9RXL+KZ4cVpzgIXb0fNfu1g659v3fvKJKby04RWVkgEIw/W9E940rX4ZTIBuFUSE6ImM MLlAE9FRRy/58T4s/TSup1pjT+8Goh8cDjtgvBqIOckVQeOx/fDsbluPhmSOwKztdIx0 nMEE+89rk2P4sd2EyN0hvT1svLWP02h9e1KhhtnAN1hFXVJcbhlMKaXvnVjQuZ1ngdjh AAZz+tYx2L6QSp78i92IZzS2ALjqsQXSaoFfz+7IjItF2MQMXRee9Nezs2nVFNZRrfEp Rdag== 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=b7R8ql7cF0yekbAJkH0ry0LqcE+e1poUS0Q2MROPNF0=; b=m3Yccgb0P2LdwaoVilt5Dvn9VQa2vYnMDnd8h0Yk/Fju5pMFz2bGmXa/2WFaLpya9c R/1Rg9lkJ5O9WS7f+6oEIQ/A8WDOKTOvFxBM/r1SmpzpW3Y2cGqZZeWvTJYvY2UQyUzD FbHAQJdHaoL6M4is6IYWHpYn+VCo/5joirgSBjrlnuealPc1aT9BbMZQ18I+ez6V6Uik rUPI1sOvtofzjD/WCjwqTOjT1IV7ERbr5LTYA9e24tmnep2HaUGxCQyCPUZ2+OGx2qNu SCAosn1bQmuLA7mURGkr9suNV9b9O97VjWl44e07hgeE8mN/IgnGOXpoNk0rsrYHcqMR HJag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=nFJFvKzV; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mu12-20020a17090b388c00b001eccde9cdefsi8019800pjb.83.2022.07.01.06.26.50; Fri, 01 Jul 2022 06:27:02 -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=@canonical.com header.s=20210705 header.b=nFJFvKzV; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236043AbiGANJl (ORCPT + 99 others); Fri, 1 Jul 2022 09:09:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235574AbiGANJh (ORCPT ); Fri, 1 Jul 2022 09:09:37 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2B9BDC for ; Fri, 1 Jul 2022 06:09:35 -0700 (PDT) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 101EB3F1EB for ; Fri, 1 Jul 2022 13:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1656680973; bh=b7R8ql7cF0yekbAJkH0ry0LqcE+e1poUS0Q2MROPNF0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nFJFvKzVFguG/jvo33cUjRiMVV2u8Mj+FwMoi1lUFKyxQrVpsESCFT8GF8/d4SVCJ ojcTMI2oZylRPXsvSRf9u98//jPmNh7+JRVO0eEU+Y0suBVEEAuI+NXPCV+ByvXWlI EGrZ/gIc5qoGHFloQnJB6B4787qMTprg9AOrFoUuE5ik+nrNmev9RQ4UGeQsQtHMbt bqRbsszNWWMonSs5G/mxENzDzbZV1tg4pp90pc9lro0MorCmdBs8qD+BP1Z4o1XKGt jpdJRL6snTPg2pckeojNc9SDx/TlxEBy2RMKnJXj7PMiaYhVYOgzmwW1E6M8yy2Zou SapVYJu+V7Fng== Received: by mail-pl1-f200.google.com with SMTP id m17-20020a170902d19100b0016a0e65a433so1430425plb.8 for ; Fri, 01 Jul 2022 06:09:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b7R8ql7cF0yekbAJkH0ry0LqcE+e1poUS0Q2MROPNF0=; b=ZcrOQ6Olmhp/GyW48ZghcDGJ6lQwzrtIh45SdSNR6oXV33+m8jauDQxy5/uKzJPvZq Qe/c1WBGSBMS16WExw22Jzn+2IHE+1c2r/8yMwhC2/Wupn8FB7crSapEV2B9OR+Jj5qR 2pU+YuZOUy5DLXdNYcL7T/N3gWlO/49p5zeEH/gdTWAHNUk9Ci/HBviMYEBAsfjU0sNu mwkcv+tcIQizWb3MQqPfbMzx+RpNUNDS2N/YAJM/g16hDOcvKk9pIS5lzX7mkkXVjkyw IuoXpTER5ogxKftsyGYUeUq7v9Ov6PoDFzIMfcidGSPsNqXU+20n/ZRmNfSPf/P2mZC0 Yz4Q== X-Gm-Message-State: AJIora/VvxD7h+hrYDIM7CFTnoJyE1AGKMexNx+OMxSITJPv3YqyfAAn owA/ZJyEIlk94vf/nOKCnfGFsJ52xy/NSVVq4wQoAkZI6sWM+Cjqe1JdwyP1LF4KDKeWlSCLDk/ r2p274TKYESH1tXbU85NKYxglnjvUzATOx1KOzG8/ X-Received: by 2002:a17:903:2c2:b0:168:e323:d471 with SMTP id s2-20020a17090302c200b00168e323d471mr20824058plk.147.1656680968725; Fri, 01 Jul 2022 06:09:28 -0700 (PDT) X-Received: by 2002:a17:903:2c2:b0:168:e323:d471 with SMTP id s2-20020a17090302c200b00168e323d471mr20824037plk.147.1656680968462; Fri, 01 Jul 2022 06:09:28 -0700 (PDT) Received: from localhost.localdomain (223-137-32-253.emome-ip.hinet.net. [223.137.32.253]) by smtp.gmail.com with ESMTPSA id cp2-20020a170902e78200b0015e8d4eb1d7sm15489395plb.33.2022.07.01.06.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 06:09:27 -0700 (PDT) From: Po-Hsu Lin To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: memxor@gmail.com, linux-kernel@vger.kernel.org, ast@kernel.org, po-hsu.lin@canonical.com Subject: [PATCH stable 5.15 1/1] selftests/bpf: Add test_verifier support to fixup kfunc call insns Date: Fri, 1 Jul 2022 21:08:58 +0800 Message-Id: <20220701130858.282569-2-po-hsu.lin@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220701130858.282569-1-po-hsu.lin@canonical.com> References: <20220701130858.282569-1-po-hsu.lin@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 From: Kumar Kartikeya Dwivedi commit 0201b80772ac2b712bbbfe783cdb731fdfb4247e upstream. This allows us to add tests (esp. negative tests) where we only want to ensure the program doesn't pass through the verifier, and also verify the error. The next commit will add the tests making use of this. Signed-off-by: Kumar Kartikeya Dwivedi Link: https://lore.kernel.org/r/20220114163953.1455836-9-memxor@gmail.com Signed-off-by: Alexei Starovoitov [PHLin: backport due to lack of fixup_map_timer] Signed-off-by: Po-Hsu Lin --- tools/testing/selftests/bpf/test_verifier.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 3a9e332..68a9a89 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -63,6 +64,11 @@ static bool unpriv_disabled = false; static int skips; static bool verbose = false; +struct kfunc_btf_id_pair { + const char *kfunc; + int insn_idx; +}; + struct bpf_test { const char *descr; struct bpf_insn insns[MAX_INSNS]; @@ -88,6 +94,7 @@ struct bpf_test { int fixup_map_event_output[MAX_FIXUPS]; int fixup_map_reuseport_array[MAX_FIXUPS]; int fixup_map_ringbuf[MAX_FIXUPS]; + struct kfunc_btf_id_pair fixup_kfunc_btf_id[MAX_FIXUPS]; /* Expected verifier log output for result REJECT or VERBOSE_ACCEPT. * Can be a tab-separated sequence of expected strings. An empty string * means no log verification. @@ -718,6 +725,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type, int *fixup_map_event_output = test->fixup_map_event_output; int *fixup_map_reuseport_array = test->fixup_map_reuseport_array; int *fixup_map_ringbuf = test->fixup_map_ringbuf; + struct kfunc_btf_id_pair *fixup_kfunc_btf_id = test->fixup_kfunc_btf_id; if (test->fill_helper) { test->fill_insns = calloc(MAX_TEST_INSNS, sizeof(struct bpf_insn)); @@ -903,6 +911,26 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type, fixup_map_ringbuf++; } while (*fixup_map_ringbuf); } + + /* Patch in kfunc BTF IDs */ + if (fixup_kfunc_btf_id->kfunc) { + struct btf *btf; + int btf_id; + + do { + btf_id = 0; + btf = btf__load_vmlinux_btf(); + if (btf) { + btf_id = btf__find_by_name_kind(btf, + fixup_kfunc_btf_id->kfunc, + BTF_KIND_FUNC); + btf_id = btf_id < 0 ? 0 : btf_id; + } + btf__free(btf); + prog[fixup_kfunc_btf_id->insn_idx].imm = btf_id; + fixup_kfunc_btf_id++; + } while (fixup_kfunc_btf_id->kfunc); + } } struct libcap { -- 2.7.4