BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	Gilad Reti <gilad.reti@gmail.com>, KP Singh <kpsingh@kernel.org>
Cc: bpf <bpf@vger.kernel.org>, Shuah Khan <shuah@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	<linux-kselftest@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] selftests/bpf: add verifier test for PTR_TO_MEM spill
Date: Tue, 12 Jan 2021 08:59:12 -0800
Message-ID: <eadd9b0f-aff5-99e2-e425-4b798d7a85c4@fb.com> (raw)
In-Reply-To: <60034a79-573f-125c-76b0-17e04941a155@iogearbox.net>



On 1/12/21 7:43 AM, Daniel Borkmann wrote:
> On 1/12/21 4:35 PM, Gilad Reti wrote:
>> On Tue, Jan 12, 2021 at 4:56 PM KP Singh <kpsingh@kernel.org> wrote:
>>> On Tue, Jan 12, 2021 at 10:16 AM Gilad Reti <gilad.reti@gmail.com> 
>>> wrote:
>>>>
>>>> Add test to check that the verifier is able to recognize spilling of
>>>> PTR_TO_MEM registers.
>>>
>>> It would be nice to have some explanation of what the test does to
>>> recognize the spilling of the PTR_TO_MEM registers in the commit
>>> log as well.
>>>
>>> Would it be possible to augment an existing test_progs
>>> program like tools/testing/selftests/bpf/progs/test_ringbuf.c to test
>>> this functionality?
> 
> How would you guarantee that LLVM generates the spill/fill, via inline asm?

You can make the following change to force the return value ("sample" 
here) of bpf_ringbuf_reserve() to spill on the stack.

diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf.c 
b/tools/testing/selftests/bpf/progs/test_ringbuf.c
index 8ba9959b036b..011521170856 100644
--- a/tools/testing/selftests/bpf/progs/test_ringbuf.c
+++ b/tools/testing/selftests/bpf/progs/test_ringbuf.c
@@ -40,7 +40,7 @@ SEC("tp/syscalls/sys_enter_getpgid")
  int test_ringbuf(void *ctx)
  {
         int cur_pid = bpf_get_current_pid_tgid() >> 32;
-       struct sample *sample;
+       struct sample * volatile sample;
         int zero = 0;

         if (cur_pid != pid)

This change will cause verifier failure without Patch #1.

> 
>> It may be possible, but from what I understood from Daniel's comment here
>>
>> https://lore.kernel.org/bpf/17629073-4fab-a922-ecc3-25b019960f44@iogearbox.net/ 
>>
>>
>> the test should be a part of the verifier tests (which is reasonable
>> to me since it is
>> a verifier bugfix)
> 
> Yeah, the test_verifier case as you have is definitely the most straight
> forward way to add coverage in this case.

      parent reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  9:15 Gilad Reti
2021-01-12 14:55 ` KP Singh
2021-01-12 15:35   ` Gilad Reti
2021-01-12 15:43     ` Daniel Borkmann
2021-01-12 16:17       ` KP Singh
2021-01-12 16:24         ` Gilad Reti
2021-01-12 16:59       ` Yonghong Song [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=eadd9b0f-aff5-99e2-e425-4b798d7a85c4@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gilad.reti@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git