All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: Yonghong Song <yhs@fb.com>, Hou Tao <hotforest@gmail.com>,
	Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	<netdev@vger.kernel.org>, <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 2/2] selftests/bpf: check whether s32 is sufficient for kfunc offset
Date: Tue, 8 Feb 2022 10:47:28 +0800	[thread overview]
Message-ID: <c8ae6afe-d383-12b9-10df-57dc1da9b566@huawei.com> (raw)
In-Reply-To: <585256c2-318f-3895-8175-e7d7cbe1cd4f@fb.com>

Hi,

On 2/8/2022 2:33 AM, Yonghong Song wrote:
>
>
> On 2/5/22 8:31 PM, Hou Tao wrote:
>> In add_kfunc_call(), bpf_kfunc_desc->imm with type s32 is used to
>> represent the offset of called kfunc from __bpf_call_base, so
>> add a test to ensure that the offset will not be overflowed.
>>
>> Signed-off-by: Hou Tao <houtao1@huawei.com>
>> ---
>>   .../selftests/bpf/prog_tests/ksyms_module.c   | 42 +++++++++++++++++++
>>   1 file changed, 42 insertions(+)
>>
[...]
>> +    /* Ensure kfunc call is supported */
>> +    skel = test_ksyms_module__open_and_load();
>> +    if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open"))
>> +        return;
>> +
>> +    err = kallsyms_find("bpf_testmod_test_mod_kfunc", &kfunc_addr);
>> +    if (!ASSERT_OK(err, "find kfunc addr"))
>> +        goto cleanup;
>> +
>> +    err = kallsyms_find("__bpf_call_base", &base_addr);
>> +    if (!ASSERT_OK(err, "find base addr"))
>> +        goto cleanup;
>> +
>> +    used_offset = kfunc_addr - base_addr;
>> +    actual_offset = kfunc_addr - base_addr;
>> +    ASSERT_EQ((long long)used_offset, actual_offset, "kfunc offset
>> overflowed");
>
> I am a little bit confused about motivation here. Maybe I missed something. If
> we indeed have kfunc offset overflow,
> should kernel verifier just reject the program? Specially,
> we should make the above test_ksyms_module__open_and_load()
> fail?
In add_kfunc_call(), the calculation of imm doesn't consider the overflow
of s32. So test_ksyms_module__open_and_load() will succeed. I think the
better solution is to put the overflow check in add_kfunc_call(), so will
drop this patch and add the overflow check in add_kfunc_call() instead.

Regards,
Tao

[...]

      reply	other threads:[~2022-02-08  2:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-06  4:31 [PATCH bpf-next v4 0/2] selftests: add test for kfunc call Hou Tao
2022-02-06  4:31 ` [PATCH bpf-next v4 1/2] selftests/bpf: do not export subtest as standalone test Hou Tao
2022-02-07 18:17   ` Yonghong Song
2022-02-08  1:36     ` Hou Tao
2022-02-06  4:31 ` [PATCH bpf-next v4 2/2] selftests/bpf: check whether s32 is sufficient for kfunc offset Hou Tao
2022-02-07 18:33   ` Yonghong Song
2022-02-08  2:47     ` Hou Tao [this message]

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=c8ae6afe-d383-12b9-10df-57dc1da9b566@huawei.com \
    --to=houtao1@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hotforest@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.