Author | Tokens | Token Proportion | Commits | Commit Proportion |
---|---|---|---|---|
Eduard Zingerman | 1158 | 98.81% | 1 | 33.33% |
Andrei Matei | 14 | 1.19% | 2 | 66.67% |
Total | 1172 | 3 |
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
// SPDX-License-Identifier: GPL-2.0 /* Converted from tools/testing/selftests/bpf/verifier/helper_value_access.c */ #include <linux/bpf.h> #include <bpf/bpf_helpers.h> #include "bpf_misc.h" struct other_val { long long foo; long long bar; }; struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(max_entries, 1); __type(key, long long); __type(value, struct other_val); } map_hash_16b SEC(".maps"); #define MAX_ENTRIES 11 struct test_val { unsigned int index; int foo[MAX_ENTRIES]; }; struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(max_entries, 1); __type(key, long long); __type(value, struct test_val); } map_hash_48b SEC(".maps"); struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(max_entries, 1); __type(key, long long); __type(value, long long); } map_hash_8b SEC(".maps"); SEC("tracepoint") __description("helper access to map: full range") __success __naked void access_to_map_full_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r2 = %[sizeof_test_val]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(sizeof_test_val, sizeof(struct test_val)) : __clobber_all); } SEC("tracepoint") __description("helper access to map: partial range") __success __naked void access_to_map_partial_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r2 = 8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b) : __clobber_all); } /* Call a function taking a pointer and a size which doesn't allow the size to * be zero (i.e. bpf_trace_printk() declares the second argument to be * ARG_CONST_SIZE, not ARG_CONST_SIZE_OR_ZERO). We attempt to pass zero for the * size and expect to fail. */ SEC("tracepoint") __description("helper access to map: empty range") __failure __msg("R2 invalid zero-sized read: u64=[0,0]") __naked void access_to_map_empty_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r2 = 0; \ call %[bpf_trace_printk]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_trace_printk), __imm_addr(map_hash_48b) : __clobber_all); } /* Like the test above, but this time the size register is not known to be zero; * its lower-bound is zero though, which is still unacceptable. */ SEC("tracepoint") __description("helper access to map: possibly-empty ange") __failure __msg("R2 invalid zero-sized read: u64=[0,4]") __naked void access_to_map_possibly_empty_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ /* Read an unknown value */ \ r7 = *(u64*)(r0 + 0); \ /* Make it small and positive, to avoid other errors */ \ r7 &= 4; \ r2 = 0; \ r2 += r7; \ call %[bpf_trace_printk]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_trace_printk), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: out-of-bound range") __failure __msg("invalid access to map value, value_size=48 off=0 size=56") __naked void map_out_of_bound_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) + 8) : __clobber_all); } SEC("tracepoint") __description("helper access to map: negative range") __failure __msg("R2 min value is negative") __naked void access_to_map_negative_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r2 = -8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): full range") __success __naked void via_const_imm_full_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo)), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): partial range") __success __naked void via_const_imm_partial_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = 8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): empty range") __failure __msg("R2 invalid zero-sized read") __naked void via_const_imm_empty_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = 0; \ call %[bpf_trace_printk]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_trace_printk), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): out-of-bound range") __failure __msg("invalid access to map value, value_size=48 off=4 size=52") __naked void imm_out_of_bound_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo) + 8), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): negative range (> adjustment)") __failure __msg("R2 min value is negative") __naked void const_imm_negative_range_adjustment_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = -8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const imm): negative range (< adjustment)") __failure __msg("R2 min value is negative") __naked void const_imm_negative_range_adjustment_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r1 += %[test_val_foo]; \ r2 = -1; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): full range") __success __naked void via_const_reg_full_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = %[test_val_foo]; \ r1 += r3; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo)), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): partial range") __success __naked void via_const_reg_partial_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = %[test_val_foo]; \ r1 += r3; \ r2 = 8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): empty range") __failure __msg("R2 invalid zero-sized read") __naked void via_const_reg_empty_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = 0; \ r1 += r3; \ r2 = 0; \ call %[bpf_trace_printk]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_trace_printk), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): out-of-bound range") __failure __msg("invalid access to map value, value_size=48 off=4 size=52") __naked void reg_out_of_bound_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = %[test_val_foo]; \ r1 += r3; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo) + 8), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): negative range (> adjustment)") __failure __msg("R2 min value is negative") __naked void const_reg_negative_range_adjustment_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = %[test_val_foo]; \ r1 += r3; \ r2 = -8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via const reg): negative range (< adjustment)") __failure __msg("R2 min value is negative") __naked void const_reg_negative_range_adjustment_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = %[test_val_foo]; \ r1 += r3; \ r2 = -1; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via variable): full range") __success __naked void map_via_variable_full_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[test_val_foo] goto l0_%=; \ r1 += r3; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo)), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via variable): partial range") __success __naked void map_via_variable_partial_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[test_val_foo] goto l0_%=; \ r1 += r3; \ r2 = 8; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via variable): empty range") __failure __msg("R2 invalid zero-sized read") __naked void map_via_variable_empty_range(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[test_val_foo] goto l0_%=; \ r1 += r3; \ r2 = 0; \ call %[bpf_trace_printk]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_trace_printk), __imm_addr(map_hash_48b), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via variable): no max check") __failure __msg("R1 unbounded memory access") __naked void via_variable_no_max_check_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ r1 += r3; \ r2 = 1; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to adjusted map (via variable): wrong max check") __failure __msg("invalid access to map value, value_size=48 off=4 size=45") __naked void via_variable_wrong_max_check_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[test_val_foo] goto l0_%=; \ r1 += r3; \ r2 = %[__imm_0]; \ r3 = 0; \ call %[bpf_probe_read_kernel]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_probe_read_kernel), __imm_addr(map_hash_48b), __imm_const(__imm_0, sizeof(struct test_val) - offsetof(struct test_val, foo) + 1), __imm_const(test_val_foo, offsetof(struct test_val, foo)) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using <, good access") __success __naked void bounds_check_using_good_access_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 < 32 goto l1_%=; \ r0 = 0; \ l0_%=: exit; \ l1_%=: r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using <, bad access") __failure __msg("R1 unbounded memory access") __naked void bounds_check_using_bad_access_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 < 32 goto l1_%=; \ r1 += r3; \ l0_%=: r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ l1_%=: r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using <=, good access") __success __naked void bounds_check_using_good_access_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 <= 32 goto l1_%=; \ r0 = 0; \ l0_%=: exit; \ l1_%=: r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using <=, bad access") __failure __msg("R1 unbounded memory access") __naked void bounds_check_using_bad_access_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 <= 32 goto l1_%=; \ r1 += r3; \ l0_%=: r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ l1_%=: r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<, good access") __success __naked void check_using_s_good_access_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 s< 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s< 0 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<, good access 2") __success __naked void using_s_good_access_2_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 s< 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s< -3 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<, bad access") __failure __msg("R1 min value is negative") __naked void check_using_s_bad_access_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u64*)(r0 + 0); \ if r3 s< 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s< -3 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<=, good access") __success __naked void check_using_s_good_access_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 s<= 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s<= 0 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<=, good access 2") __success __naked void using_s_good_access_2_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 s<= 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s<= -3 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("helper access to map: bounds check using s<=, bad access") __failure __msg("R1 min value is negative") __naked void check_using_s_bad_access_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_48b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r1 = r0; \ r3 = *(u64*)(r0 + 0); \ if r3 s<= 32 goto l1_%=; \ l2_%=: r0 = 0; \ l0_%=: exit; \ l1_%=: if r3 s<= -3 goto l2_%=; \ r1 += r3; \ r0 = 0; \ *(u8*)(r1 + 0) = r0; \ r0 = 0; \ exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_48b) : __clobber_all); } SEC("tracepoint") __description("map lookup helper access to map") __success __naked void lookup_helper_access_to_map(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b) : __clobber_all); } SEC("tracepoint") __description("map update helper access to map") __success __naked void update_helper_access_to_map(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r4 = 0; \ r3 = r0; \ r2 = r0; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_update_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_map_update_elem), __imm_addr(map_hash_16b) : __clobber_all); } SEC("tracepoint") __description("map update helper access to map: wrong size") __failure __msg("invalid access to map value, value_size=8 off=0 size=16") __naked void access_to_map_wrong_size(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_8b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r4 = 0; \ r3 = r0; \ r2 = r0; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_update_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm(bpf_map_update_elem), __imm_addr(map_hash_16b), __imm_addr(map_hash_8b) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const imm)") __success __naked void adjusted_map_via_const_imm(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r2 += %[other_val_bar]; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(other_val_bar, offsetof(struct other_val, bar)) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const imm): out-of-bound 1") __failure __msg("invalid access to map value, value_size=16 off=12 size=8") __naked void imm_out_of_bound_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r2 += %[__imm_0]; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(__imm_0, sizeof(struct other_val) - 4) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const imm): out-of-bound 2") __failure __msg("invalid access to map value, value_size=16 off=-4 size=8") __naked void imm_out_of_bound_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r2 += -4; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const reg)") __success __naked void adjusted_map_via_const_reg(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = %[other_val_bar]; \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(other_val_bar, offsetof(struct other_val, bar)) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const reg): out-of-bound 1") __failure __msg("invalid access to map value, value_size=16 off=12 size=8") __naked void reg_out_of_bound_1(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = %[__imm_0]; \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(__imm_0, sizeof(struct other_val) - 4) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via const reg): out-of-bound 2") __failure __msg("invalid access to map value, value_size=16 off=-4 size=8") __naked void reg_out_of_bound_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = -4; \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via variable)") __success __naked void to_adjusted_map_via_variable(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[other_val_bar] goto l0_%=; \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(other_val_bar, offsetof(struct other_val, bar)) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via variable): no max check") __failure __msg("R2 unbounded memory access, make sure to bounds check any such access") __naked void via_variable_no_max_check_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = *(u32*)(r0 + 0); \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b) : __clobber_all); } SEC("tracepoint") __description("map helper access to adjusted map (via variable): wrong max check") __failure __msg("invalid access to map value, value_size=16 off=9 size=8") __naked void via_variable_wrong_max_check_2(void) { asm volatile (" \ r2 = r10; \ r2 += -8; \ r1 = 0; \ *(u64*)(r2 + 0) = r1; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ if r0 == 0 goto l0_%=; \ r2 = r0; \ r3 = *(u32*)(r0 + 0); \ if r3 > %[__imm_0] goto l0_%=; \ r2 += r3; \ r1 = %[map_hash_16b] ll; \ call %[bpf_map_lookup_elem]; \ l0_%=: exit; \ " : : __imm(bpf_map_lookup_elem), __imm_addr(map_hash_16b), __imm_const(__imm_0, offsetof(struct other_val, bar) + 1) : __clobber_all); } char _license[] SEC("license") = "GPL";
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with Cregit http://github.com/cregit/cregit
Version 2.0-RC1