BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: thinker.li@gmail.com
Cc: sinquersw@gmail.com, kuifeng@meta.com, bpf@vger.kernel.org,
	ast@kernel.org, song@kernel.org, kernel-team@meta.com,
	andrii@kernel.org
Subject: Re: [PATCH bpf-next v5 2/2] selftests/bpf: Test case for lacking CFI stub functions.
Date: Thu, 22 Feb 2024 13:03:21 -0800	[thread overview]
Message-ID: <7a926464-5819-440e-b558-901b6cd70788@linux.dev> (raw)
In-Reply-To: <20240222021105.1180475-3-thinker.li@gmail.com>

On 2/21/24 6:11 PM, thinker.li@gmail.com wrote:
> +static struct bpf_test_no_cfi_ops __bpf_test_no_cfi_ops = {
> +	.fn_1 = bpf_test_no_cfi_ops__fn_1,
> +	.fn_2 = bpf_test_no_cfi_ops__fn_2,
> +};
> +
> +static struct bpf_struct_ops bpf_bpf_test_no_cif_ops = {

nit. I shortened this to test_no_cif_ops.

> +	.verifier_ops = &dummy_verifier_ops,
> +	.init = dummy_init,
> +	.init_member = dummy_init_member,
> +	.reg = dummy_reg,
> +	.unreg = dummy_unreg,
> +	.name = "bpf_test_no_cfi_ops",
> +	.owner = THIS_MODULE,
> +};
> +
> +static int bpf_test_no_cfi_init(void)
> +{
> +	int ret;
> +
> +	ret = register_bpf_struct_ops(&bpf_bpf_test_no_cif_ops,
> +				      bpf_test_no_cfi_ops);
> +	if (!ret)
> +		return -EINVAL;
> +
> +	bpf_bpf_test_no_cif_ops.cfi_stubs = &__bpf_test_no_cfi_ops;
> +	ret = register_bpf_struct_ops(&bpf_bpf_test_no_cif_ops,
> +				      bpf_test_no_cfi_ops);
> +	return ret;
> +}
> +
> +static void bpf_test_no_cfi_exit(void)
> +{
> +}
> +
> +module_init(bpf_test_no_cfi_init);
> +module_exit(bpf_test_no_cfi_exit);
> +
> +MODULE_AUTHOR("Kuifeng Lee");
> +MODULE_DESCRIPTION("BPF no cfi_stubs test module");
> +MODULE_LICENSE("Dual BSD/GPL");
> +
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c
> new file mode 100644
> index 000000000000..f16d4dcccacf
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_no_cfi.c
> @@ -0,0 +1,38 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
> +#include <test_progs.h>
> +#include <testing_helpers.h>
> +
> +static void load_bpf_test_no_cfi(void)
> +{
> +	int fd;
> +	int err;
> +
> +	fd = open("bpf_test_no_cfi.ko", O_RDONLY);
> +	if (!ASSERT_GT(fd, 0, "open")) {
> +		close(fd);

Removed close(fd) here. Also fixed the above ASSERT_GT test. Applied.

The patchwork has picked up the submitter name as "Thinker Lee". I fixed that up 
this time for the cover letter (the merge commit). Not sure where it came from 
and could be due to the nameless sender "from" in the email.

Please write the full name when sending out patch, e.g. "git send-email 
--from="Kui-Feng Lee <thinker.li@gmail.com>" ..."



> +		return;
> +	}
> +
> +	/* The module will try to register a struct_ops type without
> +	 *  cfi_stubs and with cfi_stubs.
> +	 *
> +	 * The one without cfi_stub should fail. The module will be loaded
> +	 * successfully only if the result of the registration is as
> +	 * expected, or it fails.
> +	 */
> +	err = finit_module(fd, "", 0);
> +	close(fd);
> +	if (!ASSERT_OK(err, "finit_module"))
> +		return;
> +
> +	err = delete_module("bpf_test_no_cfi", 0);
> +	ASSERT_OK(err, "delete_module");
> +}
> +


  reply	other threads:[~2024-02-22 21:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22  2:11 [PATCH bpf-next v5 0/2] Check cfi_stubs before registering a struct_ops type thinker.li
2024-02-22  2:11 ` [PATCH bpf-next v5 1/2] bpf: " thinker.li
2024-02-22  2:11 ` [PATCH bpf-next v5 2/2] selftests/bpf: Test case for lacking CFI stub functions thinker.li
2024-02-22 21:03   ` Martin KaFai Lau [this message]
2024-02-22 20:50 ` [PATCH bpf-next v5 0/2] Check cfi_stubs before registering a struct_ops type patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a926464-5819-440e-b558-901b6cd70788@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=sinquersw@gmail.com \
    --cc=song@kernel.org \
    --cc=thinker.li@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox