1 // SPDX-License-Identifier: GPL-2.0 2 3 /* 4 * Copyright 2020 Google LLC. 5 */ 6 7 #include <linux/bpf.h> 8 #include <errno.h> 9 #include <bpf/bpf_helpers.h> 10 #include <bpf/bpf_tracing.h> 11 12 char _license[] SEC("license") = "GPL"; 13 14 struct { 15 __uint(type, BPF_MAP_TYPE_TASK_STORAGE); 16 __uint(map_flags, BPF_F_NO_PREALLOC); 17 __type(key, int); 18 __type(value, int); 19 } secure_exec_task_map SEC(".maps"); 20 21 SEC("lsm/bprm_creds_for_exec") 22 int BPF_PROG(secure_exec, struct linux_binprm *bprm) 23 { 24 int *secureexec; 25 26 secureexec = bpf_task_storage_get(&secure_exec_task_map, 27 bpf_get_current_task_btf(), 0, 28 BPF_LOCAL_STORAGE_GET_F_CREATE); 29 30 if (secureexec && *secureexec) 31 bpf_bprm_opts_set(bprm, BPF_F_BPRM_SECUREEXEC); 32 33 return 0; 34 } 35