diff mbox series

[bpf,v2,1/2] bpf: support PTR_TO_MEM{,_OR_NULL} register spilling

Message ID 20210113053810.13518-1-gilad.reti@gmail.com
State New
Headers show
Series [bpf,v2,1/2] bpf: support PTR_TO_MEM{,_OR_NULL} register spilling | expand

Commit Message

Gilad Reti Jan. 13, 2021, 5:38 a.m. UTC
Add support for pointer to mem register spilling, to allow the verifier
to track pointers to valid memory addresses. Such pointers are returned
for example by a successful call of the bpf_ringbuf_reserve helper.

The patch was partially contributed by CyberArk Software, Inc.

Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it")
Suggested-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Gilad Reti <gilad.reti@gmail.com>
---
 kernel/bpf/verifier.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Yonghong Song Jan. 13, 2021, 4:05 p.m. UTC | #1
On 1/12/21 9:38 PM, Gilad Reti wrote:
> Add a test to check that the verifier is able to recognize spilling of
> PTR_TO_MEM registers, by reserving a ringbuf buffer, forcing the spill
> of a pointer holding the buffer address to the stack, filling it back
> in from the stack and writing to the memory area pointed by it.
> 
> The patch was partially contributed by CyberArk Software, Inc.
> 
> Signed-off-by: Gilad Reti <gilad.reti@gmail.com>

I didn't verify result_unpriv = ACCEPT part. I think it is correct
by checking code.

Acked-by: Yonghong Song <yhs@fb.com>
KP Singh Jan. 13, 2021, 10:28 p.m. UTC | #2
On Wed, Jan 13, 2021 at 5:05 PM Yonghong Song <yhs@fb.com> wrote:
>

>

>

> On 1/12/21 9:38 PM, Gilad Reti wrote:

> > Add a test to check that the verifier is able to recognize spilling of

> > PTR_TO_MEM registers, by reserving a ringbuf buffer, forcing the spill

> > of a pointer holding the buffer address to the stack, filling it back

> > in from the stack and writing to the memory area pointed by it.

> >

> > The patch was partially contributed by CyberArk Software, Inc.

> >

> > Signed-off-by: Gilad Reti <gilad.reti@gmail.com>

>

> I didn't verify result_unpriv = ACCEPT part. I think it is correct

> by checking code.

>

> Acked-by: Yonghong Song <yhs@fb.com>


Thanks for the description!

Acked-by: KP Singh <kpsingh@kernel.org>
KP Singh Jan. 13, 2021, 10:29 p.m. UTC | #3
On Wed, Jan 13, 2021 at 6:38 AM Gilad Reti <gilad.reti@gmail.com> wrote:
>
> Add support for pointer to mem register spilling, to allow the verifier
> to track pointers to valid memory addresses. Such pointers are returned
> for example by a successful call of the bpf_ringbuf_reserve helper.
>
> The patch was partially contributed by CyberArk Software, Inc.
>
> Fixes: 457f44363a88 ("bpf: Implement BPF ring buffer and verifier support for it")
> Suggested-by: Yonghong Song <yhs@fb.com>
> Signed-off-by: Gilad Reti <gilad.reti@gmail.com>

Acked-by: KP Singh <kpsingh@kernel.org>
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 17270b8404f1..36af69fac591 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2217,6 +2217,8 @@  static bool is_spillable_regtype(enum bpf_reg_type type)
 	case PTR_TO_RDWR_BUF:
 	case PTR_TO_RDWR_BUF_OR_NULL:
 	case PTR_TO_PERCPU_BTF_ID:
+	case PTR_TO_MEM:
+	case PTR_TO_MEM_OR_NULL:
 		return true;
 	default:
 		return false;