1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2024 Isovalent */ 3 4 #include <linux/bpf.h> 5 #include <bpf/bpf_helpers.h> 6 #include "bpf_misc.h" 7 8 const volatile long foo = 42; 9 long bar; 10 long bart = 96; 11 12 SEC("tc/ingress") 13 __description("rodata/strtol: write rejected") 14 __failure __msg("write into map forbidden") 15 int tcx1(struct __sk_buff *skb) 16 { 17 char buff[] = { '8', '4', '\0' }; 18 bpf_strtol(buff, sizeof(buff), 0, (long *)&foo); 19 return TCX_PASS; 20 } 21 22 SEC("tc/ingress") 23 __description("bss/strtol: write accepted") 24 __success 25 int tcx2(struct __sk_buff *skb) 26 { 27 char buff[] = { '8', '4', '\0' }; 28 bpf_strtol(buff, sizeof(buff), 0, &bar); 29 return TCX_PASS; 30 } 31 32 SEC("tc/ingress") 33 __description("data/strtol: write accepted") 34 __success 35 int tcx3(struct __sk_buff *skb) 36 { 37 char buff[] = { '8', '4', '\0' }; 38 bpf_strtol(buff, sizeof(buff), 0, &bart); 39 return TCX_PASS; 40 } 41 42 SEC("tc/ingress") 43 __description("rodata/mtu: write rejected") 44 __failure __msg("write into map forbidden") 45 int tcx4(struct __sk_buff *skb) 46 { 47 bpf_check_mtu(skb, skb->ifindex, (__u32 *)&foo, 0, 0); 48 return TCX_PASS; 49 } 50 51 SEC("tc/ingress") 52 __description("bss/mtu: write accepted") 53 __success 54 int tcx5(struct __sk_buff *skb) 55 { 56 bpf_check_mtu(skb, skb->ifindex, (__u32 *)&bar, 0, 0); 57 return TCX_PASS; 58 } 59 60 SEC("tc/ingress") 61 __description("data/mtu: write accepted") 62 __success 63 int tcx6(struct __sk_buff *skb) 64 { 65 bpf_check_mtu(skb, skb->ifindex, (__u32 *)&bart, 0, 0); 66 return TCX_PASS; 67 } 68 69 char LICENSE[] SEC("license") = "GPL"; 70