File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
tools/testing/selftests/bpf/progs Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: GPL-2.0
22/* Copyright (c) 2024 Isovalent */
33
4- #include <linux/bpf.h>
4+ #include "vmlinux.h"
55#include <bpf/bpf_helpers.h>
6+ #include <bpf/bpf_tracing.h>
67#include "bpf_misc.h"
78
89const volatile long foo = 42 ;
@@ -66,4 +67,32 @@ int tcx6(struct __sk_buff *skb)
6667 return TCX_PASS ;
6768}
6869
70+ static inline void write_fixed (volatile void * p , __u32 val )
71+ {
72+ * (volatile __u32 * )p = val ;
73+ }
74+
75+ static inline void write_dyn (void * p , void * val , int len )
76+ {
77+ bpf_copy_from_user (p , len , val );
78+ }
79+
80+ SEC ("tc/ingress" )
81+ __description ("rodata/mark: write with unknown reg rejected" )
82+ __failure __msg ("write into map forbidden" )
83+ int tcx7 (struct __sk_buff * skb )
84+ {
85+ write_fixed ((void * )& foo , skb -> mark );
86+ return TCX_PASS ;
87+ }
88+
89+ SEC ("lsm.s/bprm_committed_creds" )
90+ __description ("rodata/mark: write with unknown reg rejected" )
91+ __failure __msg ("write into map forbidden" )
92+ int BPF_PROG (bprm , struct linux_binprm * bprm )
93+ {
94+ write_dyn ((void * )& foo , & bart , bpf_get_prandom_u32 () & 3 );
95+ return 0 ;
96+ }
97+
6998char LICENSE [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments