Skip to content

Commit cf2d0a5

Browse files
author
Alexei Starovoitov
committed
Merge branch 'allow variable-offset stack acces'
Andrei Matei says: ==================== 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. V2 -> V3 - var-offset writes mark all the stack slots in range as initialized, so that future reads are not rejected. - rewrote the C test to not use uprobes, as per Andrii's suggestion. - addressed other review comments from Alexei. 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 ==================== Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents ee5cc03 + 0fd7562 commit cf2d0a5

File tree

14 files changed

+742
-186
lines changed

14 files changed

+742
-186
lines changed

include/linux/bpf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ static inline bool bpf_allow_ptr_leaks(void)
12901290
return perfmon_capable();
12911291
}
12921292

1293+
static inline bool bpf_allow_uninit_stack(void)
1294+
{
1295+
return perfmon_capable();
1296+
}
1297+
12931298
static inline bool bpf_allow_ptr_to_map_access(void)
12941299
{
12951300
return perfmon_capable();

include/linux/bpf_verifier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct bpf_func_state {
195195
* 0 = main function, 1 = first callee.
196196
*/
197197
u32 frameno;
198-
/* subprog number == index within subprog_stack_depth
198+
/* subprog number == index within subprog_info
199199
* zero == main subprog
200200
*/
201201
u32 subprogno;
@@ -404,6 +404,7 @@ struct bpf_verifier_env {
404404
u32 used_btf_cnt; /* number of used BTF objects */
405405
u32 id_gen; /* used to generate unique reg IDs */
406406
bool allow_ptr_leaks;
407+
bool allow_uninit_stack;
407408
bool allow_ptr_to_map_access;
408409
bool bpf_capable;
409410
bool bypass_spec_v1;

0 commit comments

Comments
 (0)