bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/5] bpf: allow variable-offset stack access
@ 2021-01-24 19:49 Andrei Matei
  2021-01-24 19:49 ` [PATCH bpf-next v2 1/5] " Andrei Matei
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Andrei Matei @ 2021-01-24 19:49 UTC (permalink / raw)
  To: bpf, ast; +Cc: Andrei Matei

Before this patch, variable offset access to the stack was dissalowed
for regular instructions, but was allowed for "indirect" accesses (i.e.
helpers). This patch removes the restriction, allowing reading and
writing to the stack through stack pointers with variable offsets. This
makes stack-allocated buffers more usable in programs, and brings stack
pointers closer to other types of pointers.
    
The motivation is being able to use stack-allocated buffers for data
manipulation. When the stack size limit is sufficient, allocating
buffers on the stack is simpler than per-cpu arrays, or other
alternatives.

V1 -> V2

- add support for var-offset stack writes, in addition to reads
- add a C test
- made variable offset direct reads no longer destroy spilled registers
  in the access range
- address review nits

Alexei had asked to split the work into refactoring and new
functionality. I have tried to do so, but the result seemed worse.
Particularly with the addition of write support in this V2, the lines
between refactoring and new functionality are mostly gone; the structure
changes too much. Alexei, if you disagree, I will try harder.


Andrei Matei (5):
  bpf: allow variable-offset stack access
  selftest/bpf: adjust expected verifier errors
  selftest/bpf: verifier tests for var-off access
  selftest/bpf: move utility function to tests header
  selftest/bpf: add test for var-offset stack access

 include/linux/bpf_verifier.h                  |   2 +-
 kernel/bpf/verifier.c                         | 657 ++++++++++++++----
 .../selftests/bpf/prog_tests/attach_probe.c   |  21 -
 .../selftests/bpf/prog_tests/stack_var_off.c  |  56 ++
 .../selftests/bpf/progs/test_stack_var_off.c  |  43 ++
 tools/testing/selftests/bpf/test_progs.c      |  25 +
 tools/testing/selftests/bpf/test_progs.h      |   1 +
 .../selftests/bpf/verifier/basic_stack.c      |   2 +-
 tools/testing/selftests/bpf/verifier/calls.c  |   4 +-
 .../testing/selftests/bpf/verifier/const_or.c |   4 +-
 .../bpf/verifier/helper_access_var_len.c      |  12 +-
 .../testing/selftests/bpf/verifier/int_ptr.c  |   6 +-
 .../selftests/bpf/verifier/raw_stack.c        |  10 +-
 .../selftests/bpf/verifier/stack_ptr.c        |  22 +-
 tools/testing/selftests/bpf/verifier/unpriv.c |   2 +-
 .../testing/selftests/bpf/verifier/var_off.c  | 108 ++-
 16 files changed, 768 insertions(+), 207 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/stack_var_off.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_stack_var_off.c

-- 
2.27.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-07  1:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24 19:49 [PATCH bpf-next v2 0/5] bpf: allow variable-offset stack access Andrei Matei
2021-01-24 19:49 ` [PATCH bpf-next v2 1/5] " Andrei Matei
2021-01-27 22:58   ` Alexei Starovoitov
2021-01-30 22:55     ` Andrei Matei
2021-02-02  0:22       ` Alexei Starovoitov
2021-02-07  1:11     ` Andrei Matei
2021-01-24 19:49 ` [PATCH bpf-next v2 2/5] selftest/bpf: adjust expected verifier errors Andrei Matei
2021-01-24 19:49 ` [PATCH bpf-next v2 3/5] selftest/bpf: verifier tests for var-off access Andrei Matei
2021-01-24 19:49 ` [PATCH bpf-next v2 4/5] selftest/bpf: move utility function to tests header Andrei Matei
2021-01-26  2:33   ` Andrii Nakryiko
2021-01-24 19:49 ` [PATCH bpf-next v2 5/5] selftest/bpf: add test for var-offset stack access Andrei Matei
2021-01-26  2:37   ` Andrii Nakryiko
2021-02-07  1:11     ` Andrei Matei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).