bprm_opts.c (723B)
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 12char _license[] SEC("license") = "GPL"; 13 14struct { 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 21SEC("lsm/bprm_creds_for_exec") 22int 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}