Signed BPF + IPE Policies
Subsystems (8)
cover Signed BPF + IPE Policies
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
One signing scheme, please.
BPF does not need a second signing scheme. It needs a policy framework that consumes the verdict the existing signing pipeline produces. Two parallel signing stacks is harmful UX for Cilium, bpftrace, systemd, distros, and everyone shipping signed lskels. Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
What this series adds
- prog->aux->sig (verdict + keyring) and prog->aux->is_kernel, populated by the syscall path before security_bpf_prog_load fires.
- bpf_loader_verify_metadata kfunc -- the metadata check is now kernel C code, not BPF bytecode. The verifier injects the calling prog->aux as an implicit argument via KF_IMPLICIT_ARGS.
- Loader-side prog BTF with BPF_PSEUDO_KFUNC_CALL_PROG_BTF so the kfunc CALL is reproducible across build hosts and resolved at load time.
- security_bpf_prog_load_post_integrity LSM hook, fired by the kfunc on a successful metadata check.
- IPE properties (bpf_signature, bpf_keyring, bpf_kernel) and two ops (BPF_PROG_LOAD, BPF_PROG_LOAD_POST_INTEGRITY).
This series address concerns raised by the Hornet developers:
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
The bpf_loader_verify_metadata kfunc moves the hash check from inline BPF instructions into kernel C code.
* LSMs cannot observe the verification result at hook time -- Paul Moore [4]:
prog->aux->sig.verdict and sig.keyring are populated before any LSM hook runs. Furthermore, security_bpf_prog_load_post_integrity hook fires after the in-kernel hash check for consumers that want to observe or gate the post-integrity transition.
[1] Alexei Starovoitov, NACK on Hornet (TOCTOU + layering),
https://lore.kernel.org/all/CAADnVQJ1CRvTXBU771KaYzrx-vRaWF+k164DcFOqOsCxmuL+ig@mail.gmail.com/
[2] Daniel Borkmann, NACK on Hornet v3,
https://lore.kernel.org/all/[email protected]/ [3] Blaise Boscaccy, Hornet v6 (C-side hash verification rationale), https://lore.kernel.org/all/[email protected]/ [4] Paul Moore, push for post-verifier observability, https://lore.kernel.org/all/CACYkzJ4+=3owK+ELD9Nw7Rrm-UajxXEw8kVtOTJJ+SNAXpsOpw@mail.gmail.com/
KP Singh (13):
bpf: expose signature verdict to LSMs via bpf_prog_aux
bpf: include prog BTF in the signed loader signature scope bpf, libbpf: load prog BTF in the skel_internal loader
bpf: add bpf_loader_verify_metadata kfunc
bpf: compute prog->digest at BPF_PROG_LOAD entry
bpf: resolve loader-style kfunc CALLs against prog BTF
libbpf: generate prog BTF for loader programs
bpftool gen: embed loader prog BTF in the lskel header
lsm: add bpf_prog_load_post_integrity hook
bpf: invoke security_bpf_prog_load_post_integrity from the metadata
kfunc
ipe: add BPF program signature properties
ipe: gate post-integrity BPF program loads selftests/bpf: add IPE BPF policy integration tests
include/linux/bpf.h | 19 +++ include/linux/bpf_verifier.h | 6 + include/linux/btf.h | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 + include/uapi/linux/bpf.h | 5 + kernel/bpf/btf.c | 8 + kernel/bpf/check_btf.c | 18 +- kernel/bpf/helpers.c | 65 ++++++++ kernel/bpf/syscall.c | 76 ++++++++- kernel/bpf/verifier.c | 58 ++++++- security/ipe/Kconfig | 14 ++ security/ipe/audit.c | 13 ++ security/ipe/eval.c | 57 +++++++ security/ipe/eval.h | 5 + security/ipe/hooks.c | 42 +++++ security/ipe/hooks.h | 9 + security/ipe/ipe.c | 4 + security/ipe/policy.h | 11 ++ security/ipe/policy_parser.c | 20 +++ security/security.c | 17 ++ tools/bpf/bpftool/gen.c | 21 +++ tools/bpf/bpftool/sign.c | 17 +- tools/include/uapi/linux/bpf.h | 5 + tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 +++++++++++--- tools/lib/bpf/libbpf.h | 4 +- tools/lib/bpf/skel_internal.h | 67 +++++--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 30 files changed, 775 insertions(+), 83 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.sh
Signature · 1 line
2.53.0
PATCH 1/13 bpf: expose signature verdict to LSMs via bpf_prog_aux
BPF_PROG_LOAD verifies the loader signature but does not record the outcome on the prog. LSMs and audit can read attr->signature and attr->keyring_id to infer "was this signed, against which keyring", but there is no canonical state for "loader signature + map content verified". Only the in-kernel kfunc can confirm the latter.
Add prog->aux->sig (verdict + keyring) and prog->aux->is_kernel, populated by bpf_prog_load before the LSM hook. Failed verifications reject the load before the hook runs, so it observes only UNSIGNED or OK. The bpf_loader_verify_metadata kfunc promotes to METADATA_VERIFIED later.
--- include/linux/bpf.h | 19 +++++++++++++++++++ kernel/bpf/syscall.c | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/linux/bpf.h +19 -0
@@ -1656,6 +1656,20 @@ struct bpf_stream_stage {int len; }; +enum bpf_sig_verdict { +BPF_SIG_UNSIGNED =0 , +BPF_SIG_OK ,/* loader signature verified */ +BPF_SIG_METADATA_VERIFIED ,/* loader signature + map content verified */ +}; + +enum bpf_sig_keyring { +BPF_SIG_KEYRING_NONE =0 , +BPF_SIG_KEYRING_BUILTIN , +BPF_SIG_KEYRING_SECONDARY , +BPF_SIG_KEYRING_PLATFORM , +BPF_SIG_KEYRING_USER , +}; +struct bpf_prog_aux {atomic64_t refcnt;u32 used_map_cnt;
@@ -1698,6 +1712,11 @@ struct bpf_prog_aux {bool changes_pkt_data;bool might_sleep;bool kprobe_write_ctx; +struct { +u8 verdict; +u8 keyring; + } sig; +bool is_kernel;u64 prog_array_member_cnt;/* counts how many times as member of prog_array */ struct mutex ext_mutex;/* mutex for is_extended and prog_array_member_cnt */ struct bpf_arena *arena;
kernel/bpf/syscall.c +20 -0
@@ -2798,6 +2798,20 @@ static bool is_perfmon_prog_type(enum bpf_prog_type prog_type) } } +static enum bpf_sig_keyring bpf_classify_keyring (s32 keyring_id) +{ +switch (keyring_id) { +case 0 : +return BPF_SIG_KEYRING_BUILTIN ; +case (s32 )(unsigned long )VERIFY_USE_SECONDARY_KEYRING : +return BPF_SIG_KEYRING_SECONDARY ; +case (s32 )(unsigned long )VERIFY_USE_PLATFORM_KEYRING : +return BPF_SIG_KEYRING_PLATFORM ; +default : +return BPF_SIG_KEYRING_USER ; + } +} +static int bpf_prog_verify_signature (struct bpf_prog *prog,union bpf_attr *attr,bool is_kernel) {
@@ -3027,7 +3041,13 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) err =bpf_prog_verify_signature (prog, attr, uattr.is_kernel);if (err) goto free_prog; + prog->aux->sig.verdict =BPF_SIG_OK ; + prog->aux->sig.keyring =bpf_classify_keyring (attr->keyring_id); + }else { + prog->aux->sig.verdict =BPF_SIG_UNSIGNED ; + prog->aux->sig.keyring =BPF_SIG_KEYRING_NONE ; } + prog->aux->is_kernel = uattr.is_kernel; prog->orig_prog =NULL ; prog->jited =0 ;
Signature · 1 line
2.53.0
PATCH 2/13 bpf: include prog BTF in the signed loader signature scope
In reply to KP Singhbpf_prog_verify_signature hashes only prog->insnsi, so FUNC names in prog BTF are not covered by the signature. Since we need to support kfuncs for loader programs with prog BTF information, the signature needs to cover BTF so that it can be trusted.
When attr->prog_btf_fd is set, build the verify dynptr over insns || raw_btf so the signature covers both. Fall back to insns-only otherwise so existing signed lskels keep loading. Hoist the prog_btf_fd resolution into bpf_prog_load so the BTF is available before signature verification.
--- include/linux/btf.h | 1 + kernel/bpf/btf.c | 8 +++++++ kernel/bpf/check_btf.c | 18 +++------------- kernel/bpf/syscall.c | 49 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 20 deletions(-)
include/linux/btf.h +1 -0
@@ -216,6 +216,7 @@ int btf_type_snprintf_show(const struct btf *btf, u32 type_id, void *obj,int btf_get_fd_by_id (u32 id);u32 btf_obj_id (const struct btf *btf);bool btf_is_kernel (const struct btf *btf); +const void *btf_get_raw_data (const struct btf *btf,u32 *data_size);bool btf_is_module (const struct btf *btf);bool btf_is_vmlinux (const struct btf *btf);struct module *btf_try_get_module (const struct btf *btf);
kernel/bpf/btf.c +8 -0
@@ -8322,11 +8322,19 @@ u32 btf_obj_id(const struct btf *btf)return READ_ONCE (btf->id); } +const void *btf_get_raw_data (const struct btf *btf,u32 *data_size) +{ +if (data_size) + *data_size = btf->data_size; +return btf->data; +} +bool btf_is_kernel (const struct btf *btf) {return btf->kernel_btf; } +bool btf_is_module (const struct btf *btf) {return btf->kernel_btf &&strcmp (btf->name,"vmlinux" ) !=0 ;
kernel/bpf/check_btf.c +3 -15
@@ -411,28 +411,16 @@ int bpf_check_btf_info_early(struct bpf_verifier_env *env, const union bpf_attr *attr, bpfptr_t uattr) { - struct btf *btf; -int err; - if (!attr->func_info_cnt && !attr->line_info_cnt) { if (check_abnormal_return(env)) return -EINVAL;return 0 ; } - btf =btf_get_by_fd (attr->prog_btf_fd); -if (IS_ERR (btf)) -return PTR_ERR (btf); -if (btf_is_kernel (btf)) { -btf_put (btf); -return -EACCES ; - } - env->prog->aux->btf = btf; +if (env->prog->aux->btf) +return check_btf_func_early (env, attr, uattr); - err =check_btf_func_early (env, attr, uattr); -if (err) -return err; -return 0 ; +return -EINVAL ; } int bpf_check_btf_info(struct bpf_verifier_env *env,
kernel/bpf/syscall.c +44 -5
79 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 3/13 bpf, libbpf: load prog BTF in the skel_internal loader
In reply to KP Singhbpf_load_and_run loads only the loader insns and the metadata map. To match the kernel's extended signature scope (insns || btf), the loader needs to BPF_BTF_LOAD the prog BTF before BPF_PROG_LOAD so attr->prog_btf_fd can be filled in.
Add btf and btf_sz to bpf_load_and_run_opts; when set, do the BPF_BTF_LOAD before BPF_PROG_LOAD and pass the resulting fd as attr->prog_btf_fd.
--- tools/lib/bpf/skel_internal.h | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
tools/lib/bpf/skel_internal.h +43 -1
@@ -11,6 +11,8 @@#include <linux/bpf.h> #else #include <unistd.h> +#include <fcntl.h> +#include <errno.h> #include <sys/syscall.h> #include <sys/mman.h> #include <linux/keyctl.h>
@@ -66,8 +68,10 @@ struct bpf_load_and_run_opts {struct bpf_loader_ctx *ctx;const void *data;const void *insns; +const void *btf;__u32 data_sz;__u32 insns_sz; +__u32 btf_sz;const char *errstr;void *signature;__u32 signature_sz;
@@ -88,6 +92,22 @@ static inline int skel_sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,#endif } +#ifndef __KERNEL__ +static inline int skel_sys_btf_load (union bpf_attr *attr,unsigned int size) +{ +int fd; + + fd =skel_sys_bpf (BPF_BTF_LOAD , attr, size); +if (fd >=0 && fd <3 ) { +int new_fd =fcntl (fd,F_DUPFD_CLOEXEC ,3 ); + +close (fd); + fd = new_fd; + } +return fd; +} +#endif +#ifdef __KERNEL__static inline int close (int fd) {
@@ -353,8 +373,9 @@ static inline int skel_map_freeze(int fd)static inline int bpf_load_and_run (struct bpf_load_and_run_opts *opts) { const size_t prog_load_attr_sz = offsetofend(union bpf_attr, keyring_id); + const size_t btf_load_attr_sz = offsetofend(union bpf_attr, btf_token_fd); const size_t test_run_attr_sz = offsetofend(union bpf_attr, test); -int map_fd =-1 , prog_fd =-1 , key =0 , err; +int map_fd =-1 , prog_fd =-1 , btf_fd =-1 , key =0 , err;union bpf_attr attr; err = map_fd = skel_map_create(BPF_MAP_TYPE_ARRAY, "__loader.map", 4, opts->data_sz, 1,
@@ -387,11 +408,30 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) }#endif +#ifndef __KERNEL__ +if (opts->btf && opts->btf_sz) { +memset (&attr,0 , btf_load_attr_sz); + attr.btf = (long ) opts->btf; + attr.btf_size = opts->btf_sz; + attr.btf_log_level = opts->ctx->log_level; + attr.btf_log_size = opts->ctx->log_size; + attr.btf_log_buf = opts->ctx->log_buf; + err = btf_fd =skel_sys_btf_load (&attr, btf_load_attr_sz); +if (btf_fd <0 ) { + opts->errstr ="failed to load loader BTF" ; + set_err; + goto out; + } + } +#endif +memset (&attr,0 , prog_load_attr_sz); attr.prog_type =BPF_PROG_TYPE_SYSCALL ; attr.insns = (long ) opts->insns; attr.insn_cnt = opts->insns_sz /sizeof (struct bpf_insn ); attr.license = (long )"Dual BSD/GPL" ; +if (btf_fd >=0 ) + attr.prog_btf_fd = btf_fd;#ifndef __KERNEL__ attr.signature = (long ) opts->signature; attr.signature_size = opts->signature_sz;
@@ -437,6 +477,8 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)close (map_fd);if (prog_fd >=0 )close (prog_fd); +if (btf_fd >=0 ) +close (btf_fd);return err; }
Signature · 1 line
2.53.0
PATCH 4/13 bpf: add bpf_loader_verify_metadata kfunc
In reply to KP SinghA signed loader reaches sig.verdict = BPF_SIG_OK after PKCS#7 verification, but the metadata map content the loader writes has not been checked against its expected SHA256. The map carries that SHA256 in the signed instruction stream, spilled to the loader's stack at runtime as four ld_imm64 immediates.
Assert the map is exclusive, compare its frozen content hash against the spilled SHA256, and promote sig.verdict to BPF_SIG_METADATA_VERIFIED. The verifier injects the calling prog->aux as an implicit argument via KF_IMPLICIT_ARGS so the kfunc can read the prog digest and signature verdict directly.
Drop skel_obj_get_info_by_fd from bpf_load_and_run since the kfunc computes the map hash itself via map_get_hash; the prior BPF_OBJ_GET_INFO_BY_FD call to populate map->sha is not needed.
--- kernel/bpf/helpers.c | 57 +++++++++++++++++++++++++++++++++++ tools/bpf/bpftool/sign.c | 17 ++++++++++- tools/lib/bpf/skel_internal.h | 25 --------------- 3 files changed, 73 insertions(+), 26 deletions(-)
kernel/bpf/helpers.c +57 -0
@@ -4257,6 +4257,53 @@ __bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,return -EOPNOTSUPP ; #endif /* CONFIG_SYSTEM_DATA_VERIFICATION */ } + +/** +* bpf_loader_verify_metadata - perform the signed loader's metadata-map check +* in a single kernel-side step. +* +* Asserts the metadata map is exclusive, compares its frozen content hash +* against the expected SHA256 carried in the loader's signed instruction +* stream, and promotes sig.verdict from BPF_SIG_OK to +* BPF_SIG_METADATA_VERIFIED. +* +* @map: metadata map bound to this loader via excl_prog_hash at sign time +* @hash: pointer to the expected SHA256, spilled to the loader's BPF stack +* from signed ld_imm64 immediates +* @hash__sz: byte length of @hash (must equal SHA256_DIGEST_SIZE) +* @aux__ign: verifier-supplied prog aux; BPF programs do not set it +* +* Return: 0 on success, -EPERM if not called from a signed loader, +* -EINVAL if the map is not exclusive or the hash buffer is the wrong size, +* -EBADMSG if the hash does not match. +*/ +__bpf_kfunc int bpf_loader_verify_metadata(struct bpf_map *map, +const u64 *hash,u32 hash__sz, +struct bpf_prog_aux *aux__ign) +{ +u8 sha[SHA256_DIGEST_SIZE ]; +int err; + +if (!aux__ign || aux__ign->sig.verdict !=BPF_SIG_OK ) +return -EPERM ; +if (!map->excl_prog_sha || hash__sz !=SHA256_DIGEST_SIZE ) +return -EINVAL ; +if (memcmp (map->excl_prog_sha, aux__ign->prog->digest,SHA256_DIGEST_SIZE )) +return -EPERM ; +if (!READ_ONCE (map->frozen)) +return -EPERM ; +if (!map->ops->map_get_hash) +return -EINVAL ; + err = map->ops->map_get_hash (map,SHA256_DIGEST_SIZE , sha); +if (err) +return err; +if (memcmp (sha, hash,SHA256_DIGEST_SIZE )) +return -EBADMSG ; + + aux__ign->sig.verdict =BPF_SIG_METADATA_VERIFIED ; +return 0 ; +} +#endif /* CONFIG_KEYS */ typedef int (*bpf_task_work_callback_t )(struct bpf_map *map,void *key,void *value);
@@ -4764,6 +4811,15 @@ static const struct btf_kfunc_id_set generic_kfunc_set = { .set = &generic_btf_ids, }; +BTF_KFUNCS_START(syscall_btf_ids) +BTF_ID_FLAGS(func, bpf_loader_verify_metadata, KF_SLEEPABLE | KF_IMPLICIT_ARGS) +BTF_KFUNCS_END(syscall_btf_ids) + +static const struct btf_kfunc_id_set syscall_kfunc_set = { + .owner = THIS_MODULE, + .set = &syscall_btf_ids, +}; + BTF_ID_LIST(generic_dtor_ids) BTF_ID(struct, task_struct)
@@ -4893,6 +4949,7 @@ static int __init kfunc_init(void) ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , &generic_kfunc_set); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_SYSCALL , &generic_kfunc_set); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_CGROUP_SKB , &generic_kfunc_set); + ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_SYSCALL , &syscall_kfunc_set); ret = ret ?:register_btf_id_dtor_kfuncs (generic_dtors,ARRAY_SIZE (generic_dtors),THIS_MODULE );
tools/bpf/bpftool/sign.c +16 -1
@@ -134,10 +134,24 @@ int bpftool_prog_sign(struct bpf_load_and_run_opts *opts)EVP_PKEY *private_key =NULL ;CMS_ContentInfo *cms =NULL ;long actual_sig_len =0 ; +void *signed_buf =NULL ; +size_t signed_sz;X509 *x509 =NULL ;int err =0 ; - bd_in =BIO_new_mem_buf (opts->insns, opts->insns_sz); + signed_sz = opts->insns_sz + opts->btf_sz; +if (opts->btf_sz) { + signed_buf =malloc (signed_sz); +if (!signed_buf) { + err = -ENOMEM ; + goto cleanup; + } +memcpy (signed_buf, opts->insns, opts->insns_sz); +memcpy (signed_buf + opts->insns_sz, opts->btf, opts->btf_sz); + bd_in =BIO_new_mem_buf (signed_buf, signed_sz); + }else { + bd_in =BIO_new_mem_buf (opts->insns, opts->insns_sz); + }if (!bd_in) { err = -ENOMEM ; goto cleanup;
@@ -212,6 +226,7 @@ int bpftool_prog_sign(struct bpf_load_and_run_opts *opts)X509_free (x509);EVP_PKEY_free (private_key);BIO_free (bd_in); +free (signed_buf);DISPLAY_OSSL_ERR (err <0 );return err; }
tools/lib/bpf/skel_internal.h +0 -25
@@ -335,25 +335,6 @@ static inline int skel_link_create(int prog_fd, int target_fd,return skel_sys_bpf (BPF_LINK_CREATE , &attr, attr_sz); } -static inline int skel_obj_get_info_by_fd (int fd) -{ - const size_t attr_sz = offsetofend(union bpf_attr, info); -__u8 sha[SHA256_DIGEST_LENGTH ]; -struct bpf_map_info info; -__u32 info_len =sizeof (info); -union bpf_attr attr; - -memset (&info,0 ,sizeof (info)); - info.hash = (long ) &sha; - info.hash_size =SHA256_DIGEST_LENGTH ; - -memset (&attr,0 , attr_sz); - attr.info.bpf_fd = fd; - attr.info.info = (long ) &info; - attr.info.info_len = info_len; -return skel_sys_bpf (BPF_OBJ_GET_INFO_BY_FD , &attr, attr_sz); -} -static inline int skel_map_freeze (int fd) { const size_t attr_sz = offsetofend(union bpf_attr, map_fd);
@@ -400,12 +381,6 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) set_err; goto out; } - err =skel_obj_get_info_by_fd (map_fd); -if (err <0 ) { - opts->errstr ="failed to fetch obj info" ; - set_err; - goto out; - }#endif #ifndef __KERNEL__
Signature · 1 line
2.53.0
PATCH 5/13 bpf: compute prog->digest at BPF_PROG_LOAD entry
In reply to KP Singhadd_subprog_and_kfunc relocates kfunc CALLs by patching insn->imm and src_reg, and bpf_prog_calc_tag has no rule to mask kfunc CALL fields. The tag has to be computed over the unmodified user-supplied insns to match the excl_prog_hash userspace signed, so move the call to bpf_prog_load right after signature verification.
--- kernel/bpf/syscall.c | 7 +++++++ kernel/bpf/verifier.c | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-)
kernel/bpf/syscall.c +7 -0
@@ -3086,6 +3086,13 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size) } prog->aux->is_kernel = uattr.is_kernel; +/* Hash insns now, before any verifier-side rewrite, so prog->digest +* matches the excl_prog_hash userspace computed. +*/ + err =bpf_prog_calc_tag (prog); +if (err) + goto free_prog; + prog->orig_prog =NULL ; prog->jited =0 ;
kernel/bpf/verifier.c +0 -4
@@ -18434,10 +18434,6 @@ static int check_and_resolve_insns(struct bpf_verifier_env *env)int insn_cnt = env->prog->len;int i, err; - err =bpf_prog_calc_tag (env->prog); -if (err) -return err; -for (i =0 ; i < insn_cnt; i++, insn++) {if (insn->dst_reg >=MAX_BPF_REG ) {verbose (env,"R%d is invalid\n" , insn->dst_reg);
Signature · 1 line
2.53.0
Re: [PATCH bpf-next 05/13] bpf: compute prog->digest at BPF_PROG_LOAD entry
Quoted 4 lines · KP Singh
add_subprog_and_kfuncrelocates kfunc CALLs by patchinginsn->immandsrc_reg, andbpf_prog_calc_taghas no rule to mask kfunc CALL fields.
add_subprog_and_kfunc() doesn't modify the insn stream afaict. Do you mean that bpf_check_btf_info() resolves CO-RE relos? but loader prog doesn't use CO-RE.
I don't quite see the point of the patch.
PATCH 6/13 bpf: resolve loader-style kfunc CALLs against prog BTF
In reply to KP Singhgen_loader-emitted signed loaders cannot bake vmlinux BTF ids into kfunc CALL imm at sign time. Add a new pseudo BPF_PSEUDO_KFUNC_CALL_PROG_BTF that gen_loader emits in src_reg, with imm holding the FUNC type id in the loader's own prog BTF.
In add_subprog_and_kfunc, look the FUNC up by name in vmlinux BTF, patch imm with the resolved id, and rewrite src_reg back to BPF_PSEUDO_KFUNC_CALL so downstream passes see a normal kfunc CALL. Leave standard src_reg calls unchanged.
--- include/linux/bpf_verifier.h | 6 ++++ include/uapi/linux/bpf.h | 5 ++++ kernel/bpf/verifier.c | 54 ++++++++++++++++++++++++++++++++-- tools/include/uapi/linux/bpf.h | 5 ++++ 4 files changed, 67 insertions(+), 3 deletions(-)
include/linux/bpf_verifier.h +6 -0
@@ -959,6 +959,12 @@ static inline bool bpf_pseudo_kfunc_call(const struct bpf_insn *insn) insn->src_reg ==BPF_PSEUDO_KFUNC_CALL ; } +static inline bool bpf_pseudo_kfunc_call_prog_btf (const struct bpf_insn *insn) +{ +return insn->code == (BPF_JMP |BPF_CALL ) && + insn->src_reg ==BPF_PSEUDO_KFUNC_CALL_PROG_BTF ; +} + __printf(2, 0) void bpf_verifier_vlog(struct bpf_verifier_log *log,const char *fmt,va_list args); __printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,
include/uapi/linux/bpf.h +5 -0
@@ -1382,6 +1382,11 @@ enum {* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel */ #define BPF_PSEUDO_KFUNC_CALL 2 +/* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL_PROG_BTF, +* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the program's +* prog BTF. The verifier resolves it to a vmlinux btf_id by name. +*/ +#define BPF_PSEUDO_KFUNC_CALL_PROG_BTF 3enum bpf_addr_space_cast {BPF_ADDR_SPACE_CAST =1 ,
kernel/bpf/verifier.c +51 -3
74 lines not on this page · raw message
tools/include/uapi/linux/bpf.h +5 -0
@@ -1382,6 +1382,11 @@ enum {* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel */ #define BPF_PSEUDO_KFUNC_CALL 2 +/* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL_PROG_BTF, +* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the program's +* prog BTF. The verifier resolves it to a vmlinux btf_id by name. +*/ +#define BPF_PSEUDO_KFUNC_CALL_PROG_BTF 3enum bpf_addr_space_cast {BPF_ADDR_SPACE_CAST =1 ,
Signature · 1 line
2.53.0
Re: [PATCH bpf-next 06/13] bpf: resolve loader-style kfunc CALLs against prog BTF
Quoted 89 lines · KP Singh
gen_loader-emitted signed loaders cannot bake vmlinux BTF ids into kfunc CALL imm at sign time. Add a new pseudo
BPF_PSEUDO_KFUNC_CALL_PROG_BTFthatgen_loaderemits insrc_reg, with imm holding the FUNC type id in the loader's own prog BTF.In
add_subprog_and_kfunc, look the FUNC up by name in vmlinux BTF, patch imm with the resolved id, and rewritesrc_regback toBPF_PSEUDO_KFUNC_CALLso downstream passes see a normal kfunc CALL. Leave standardsrc_regcalls unchanged.Signed-off-by KP Singh <[email protected]>--- include/linux/bpf_verifier.h | 6 ++++ include/uapi/linux/bpf.h | 5 ++++ kernel/bpf/verifier.c | 54 ++++++++++++++++++++++++++++++++-- tools/include/uapi/linux/bpf.h | 5 ++++ 4 files changed, 67 insertions(+), 3 deletions(-)include/linux/bpf_verifier.h +6
-0@@ -959,6 +959,12 @@ static inline bool bpf_pseudo_kfunc_call(const struct bpf_insn *insn) insn->src_reg ==BPF_PSEUDO_KFUNC_CALL ; } +static inline bool bpf_pseudo_kfunc_call_prog_btf (const struct bpf_insn *insn) +{ +return insn->code == (BPF_JMP |BPF_CALL ) && + insn->src_reg ==BPF_PSEUDO_KFUNC_CALL_PROG_BTF ; +} + __printf(2, 0) void bpf_verifier_vlog(struct bpf_verifier_log *log,const char *fmt,va_list args); __printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,include/uapi/linux/bpf.h +5
-0@@ -1382,6 +1382,11 @@ enum {* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel */ #define BPF_PSEUDO_KFUNC_CALL 2 +/* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL_PROG_BTF, +* bpf_call->imm == btf_id of a BTF_KIND_FUNC in the program's +* prog BTF. The verifier resolves it to a vmlinux btf_id by name. +*/ +#define BPF_PSEUDO_KFUNC_CALL_PROG_BTF 3enum bpf_addr_space_cast {BPF_ADDR_SPACE_CAST =1 ,kernel/bpf/verifier.c +29
-0@@ -3088,6 +3088,47 @@ bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog)return !!prog->aux->kfunc_tab; } +/* +* Resolve a gen_loader-emitted kfunc CALL by FUNC name in vmlinux BTF, +* then rewrite src_reg back to BPF_PSEUDO_KFUNC_CALL. Caller must have +* already filtered for BPF_PSEUDO_KFUNC_CALL_PROG_BTF. +*/ +static int resolve_loader_kfunc (struct bpf_verifier_env *env, +struct bpf_insn *insn,int insn_idx) +{ +struct btf *prog_btf = env->prog->aux->btf; +const struct btf_type *t; +const char *name; +s32 vmlinux_id; + +if (!prog_btf || !btf_vmlinux || insn->off) { +verbose (env,"kfunc call insn %d: PROG_BTF resolution requires prog BTF and insn->off == 0\n" , + insn_idx); +return -EINVAL ; + } + t =btf_type_by_id (prog_btf, insn->imm); +if (!t || !btf_type_is_func (t)) { +verbose (env,"kfunc call insn %d: imm %d is not a FUNC in prog BTF\n" , + insn_idx, insn->imm); +return -EINVAL ; + } + name =btf_name_by_offset (prog_btf, t->name_off); +if (!name || !name[0 ]) { +verbose (env,"kfunc call insn %d: prog-BTF FUNC has no name\n" , + insn_idx); +return -EINVAL ;
kernel/bpf/verifier.c bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog) · line 3129
Quoted 10 lines
kernel/bpf/verifier.c +10
-0+ } + vmlinux_id =btf_find_by_name_kind (btf_vmlinux, name,BTF_KIND_FUNC ); +if (vmlinux_id <0 ) { +verbose (env,"kfunc call insn %d: %s not found in vmlinux BTF\n" , + insn_idx, name); +return vmlinux_id; + } + insn->imm = vmlinux_id; + insn->src_reg =BPF_PSEUDO_KFUNC_CALL ; +return 0 ;
Ohh. So this patch does it.
Probably worth squashing the patches then?
Also since the resolution into kernel kfunc is by name only, it feels odd to create a fake prog BTF proto just for the name. What is an alternative?
Also note that we were discussing allowing the replacement of kfuncs by modules with the same name. This kfunc should be immutable?
PATCH 7/13 libbpf: generate prog BTF for loader programs
In reply to KP SinghFor signed loaders, build a minimal prog BTF containing one FUNC entry for bpf_loader_verify_metadata with a FUNC_PROTO of primitives (int, void *) so the bytes are reproducible across build hosts.
In emit_verify_metadata, spill four signed ld_imm64 immediates into a 32-byte stack buffer and invoke the kfunc once with (map, &buf, 32), replacing ~24 inline dword comparisons. Expose the serialized BTF on gen_loader_opts from bpf_gen__finish so bpftool gen can embed it in the lskel.
--- tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 ++++++++++++++++++++++++------- tools/lib/bpf/libbpf.h | 4 +- 3 files changed, 105 insertions(+), 28 deletions(-)
tools/lib/bpf/bpf_gen_internal.h +2 -0
@@ -52,6 +52,8 @@ struct bpf_gen {int fd_array;int nr_fd_array;int hash_insn_offset[SHA256_DWORD_SIZE ]; +struct btf *loader_btf; +int loader_btf_func_id; };void bpf_gen__init (struct bpf_gen *gen,int log_level,int nr_progs,int nr_maps);
tools/lib/bpf/gen_loader.c +100 -27
179 lines not on this page · raw message
tools/lib/bpf/libbpf.h +3 -1
@@ -1899,9 +1899,11 @@ struct gen_loader_opts {__u32 data_sz;__u32 insns_sz;bool gen_hash; +const void *btf; +__u32 btf_sz; }; -#define gen_loader_opts__last_field gen_hash +#define gen_loader_opts__last_field btf_sz LIBBPF_API int bpf_object__gen_loader(struct bpf_object *obj,struct gen_loader_opts *opts);
Signature · 1 line
2.53.0
PATCH 8/13 bpftool gen: embed loader prog BTF in the lskel header
In reply to KP SinghExtend the signed lskel codegen to include the loader prog BTF in the generated header and the PKCS#7 signature scope. The loader needs this BTF at load time so the kernel can resolve kfunc calls by name.
Lskels generated without -S are unchanged; the new codegen is gated on opts.btf_sz.
--- tools/bpf/bpftool/gen.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/bpf/bpftool/gen.c +21 -0
@@ -793,6 +793,8 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *hif (sign_progs) { sopts.insns = opts.insns; sopts.insns_sz = opts.insns_sz; + sopts.btf = opts.btf; + sopts.btf_sz = opts.btf_sz; sopts.excl_prog_hash = prog_sha; sopts.excl_prog_hash_sz =sizeof (prog_sha); sopts.signature = sig_buf;
@@ -822,6 +824,17 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h \n\ \";\n"); +if (opts.btf_sz) { +codegen ("\ +\n\ +static const char opts_btf[] __attribute__((__aligned__(8))) = \"\\\n\ +" ); +print_hex (opts.btf, opts.btf_sz); +codegen ("\ +\n\ +\";\n" ); + } + codegen("\ \n\ opts.signature = (void *)opts_sig; \n\
@@ -830,6 +843,14 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h opts.excl_prog_hash_sz = sizeof(opts_excl_hash) - 1; \n\ opts.keyring_id = skel->keyring_id; \n\ "); + + if (opts.btf_sz) { +codegen ("\ +\n\ +opts.btf = (void *)opts_btf; \n\ +opts.btf_sz = sizeof(opts_btf) - 1; \n\ +" ); + } } codegen("\
Signature · 1 line
2.53.0
PATCH 9/13 lsm: add bpf_prog_load_post_integrity hook
In reply to KP SinghAdd a companion to security_bpf_prog_load. The existing hook fires at PROG_LOAD entry where the verdict is at most BPF_SIG_OK; the new hook fires from bpf_loader_verify_metadata after the in-kernel metadata check, just before sig.verdict is promoted to BPF_SIG_METADATA_VERIFIED. Policy LSMs that want to gate on metadata verification (not just signature presence) register here.
--- include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 ++++++ security/security.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+)
include/linux/lsm_hook_defs.h +1 -0
@@ -446,6 +446,7 @@ LSM_HOOK(int, 0, bpf_map_create, struct bpf_map *map, union bpf_attr *attr, LSM_HOOK(void, LSM_RET_VOID, bpf_map_free, struct bpf_map *map) LSM_HOOK(int, 0, bpf_prog_load, struct bpf_prog *prog, union bpf_attr *attr, struct bpf_token *token, bool kernel) +LSM_HOOK(int, 0, bpf_prog_load_post_integrity, struct bpf_prog *prog) LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free, struct bpf_prog *prog) LSM_HOOK(int, 0, bpf_token_create, struct bpf_token *token, union bpf_attr *attr, const struct path *path)
include/linux/security.h +6 -0
@@ -2305,6 +2305,7 @@ extern int security_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,extern void security_bpf_map_free (struct bpf_map *map);extern int security_bpf_prog_load (struct bpf_prog *prog,union bpf_attr *attr,struct bpf_token *token,bool kernel); +extern int security_bpf_prog_load_post_integrity (struct bpf_prog *prog);extern void security_bpf_prog_free (struct bpf_prog *prog);extern int security_bpf_token_create (struct bpf_token *token,union bpf_attr *attr,const struct path *path);
@@ -2343,6 +2344,11 @@ static inline int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *return 0 ; } +static inline int security_bpf_prog_load_post_integrity (struct bpf_prog *prog) +{ +return 0 ; +} +static inline void security_bpf_prog_free (struct bpf_prog *prog) { }
security/security.c +17 -0
@@ -5383,6 +5383,23 @@ int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,return rc; } +/** +* security_bpf_prog_load_post_integrity() - Notify LSMs that a signed loader +* has just verified its metadata map. +* @prog: the loader BPF program whose metadata check passed. +* +* Invoked by bpf_loader_verify_metadata() after the kernel-side hash check +* succeeds, before prog->aux->sig_verdict is promoted to +* BPF_SIG_METADATA_VERIFIED. A non-zero return aborts the kfunc and leaves +* the verdict at BPF_SIG_OK. +* +* Return: 0 on success, negative errno to deny. +*/ +int security_bpf_prog_load_post_integrity (struct bpf_prog *prog) +{ +return call_int_hook (bpf_prog_load_post_integrity, prog); +} +/** * security_bpf_token_create() - Check if creating of BPF token is allowed * @token: BPF token object
Signature · 1 line
2.53.0
Paul Moore
maintainerRe: [PATCH bpf-next 09/13] lsm: add bpf_prog_load_post_integrity hook
Quoted 14 lines · KP Singh
Add a companion to
security_bpf_prog_load. The existing hook fires atPROG_LOADentry where the verdict is at mostBPF_SIG_OK; the new hook fires frombpf_loader_verify_metadataafter the in-kernel metadata check, just before sig.verdict is promoted toBPF_SIG_METADATA_VERIFIED. Policy LSMs that want to gate on metadata verification (not just signature presence) register here.Signed-off-by KP Singh <[email protected]>--- include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 ++++++ security/security.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+)
...
Quoted 6 lines
security/security.c +6
-0+/** +* security_bpf_prog_load_post_integrity() - Notify LSMs that a signed loader +* has just verified its metadata map. +* @prog: the loader BPF program whose metadata check passed. +* +* Invoked by bpf_loader_verify_metadata() after the kernel-side hash check
security/security.c int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr, · line 5401
Quoted 10 lines
security/security.c +10
-0+* succeeds, before prog->aux->sig_verdict is promoted to +* BPF_SIG_METADATA_VERIFIED. A non-zero return aborts the kfunc and leaves +* the verdict at BPF_SIG_OK. +* +* Return: 0 on success, negative errno to deny. +*/ +int security_bpf_prog_load_post_integrity (struct bpf_prog *prog) +{ +return call_int_hook (bpf_prog_load_post_integrity, prog); +}
Since you're using essentially the same LSM infrastructure and IPE work that Blaise, Fan, and I developed for policy-based enforcement of BPF signature verification, perhaps this is where we can find some common ground to start working together once again.
I would be happy to support and maintain a security_bpf_prog_load_post_integrity() kfunc wrapper as part of the LSM framework, similar to what the VFS folks do with fs/bpf_fs_kfuncs.c, so that either a lskel loader, or a BPF LSM program if you like, could register a BPF integrity verification verdict with the LSM. This would provide a single unified approach for LSMs, including BPF LSMs, to build their BPF program integrity controls regardless of what the system builder, or admin, chooses for a BPF signature verification scheme: the loader based scheme you developed, or Hornet.
There is no technical reason we can't support these things, e.g. multiple coexisting verification schemes supported by a single LSM enforcement interface, we just need to be willing to accept that we have different needs and show a willingness to accept different solutions as a result.
Signature · 1 line
paul-moore.com
PATCH 10/13 bpf: invoke security_bpf_prog_load_post_integrity from the metadata kfunc
In reply to KP SinghCall security_bpf_prog_load_post_integrity from bpf_loader_verify_metadata just before promoting prog->aux->sig.verdict from BPF_SIG_OK to BPF_SIG_METADATA_VERIFIED. This lets policy LSMs deny the metadata-verified transition.
A non-zero return aborts the kfunc and leaves the verdict at BPF_SIG_OK; observers that key off METADATA_VERIFIED never see a verdict the LSM denied.
--- kernel/bpf/helpers.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/bpf/helpers.c +8 -0
@@ -4300,6 +4300,14 @@ __bpf_kfunc int bpf_loader_verify_metadata(struct bpf_map *map,if (memcmp (sha, hash,SHA256_DIGEST_SIZE ))return -EBADMSG ; +/* Metadata integrity is decided by the checks above; the LSM hook +* is an observer of that verdict and may apply policy (e.g. deny), +* but cannot vouch for integrity it did not verify itself. +*/ + err =security_bpf_prog_load_post_integrity (aux__ign->prog); +if (err) +return err; + aux__ign->sig.verdict =BPF_SIG_METADATA_VERIFIED ;return 0 ; }
Signature · 1 line
2.53.0
PATCH 11/13 ipe: add BPF program signature properties
In reply to KP SinghWire IPE to the BPF signing verdict stored in prog->aux->sig before security_bpf_prog_load fires. Add three properties on a new IPE op BPF_PROG_LOAD:
bpf_signature= UNSIGNED | OK | METADATA_VERIFIED
bpf_keyring= BUILTIN | SECONDARY | PLATFORM | USER
bpf_kernel= TRUE | FALSE
Example policy:
op=BPF_PROG_LOAD bpf_signature=UNSIGNED action=DENY op=BPF_PROG_LOAD bpf_signature=OK action=ALLOW
Gated by CONFIG_IPE_PROP_BPF_SIGNATURE (depends on BPF_SYSCALL).
--- security/ipe/Kconfig | 14 +++++++++ security/ipe/audit.c | 11 +++++++ security/ipe/eval.c | 57 ++++++++++++++++++++++++++++++++++++ security/ipe/eval.h | 5 ++++ security/ipe/hooks.c | 36 +++++++++++++++++++++++ security/ipe/hooks.h | 7 +++++ security/ipe/ipe.c | 3 ++ security/ipe/policy.h | 10 +++++++ security/ipe/policy_parser.c | 19 ++++++++++++ 9 files changed, 162 insertions(+)
security/ipe/Kconfig +14 -0
@@ -13,6 +13,7 @@ menuconfig SECURITY_IPE select IPE_PROP_DM_VERITY_SIGNATURE if DM_VERITY && DM_VERITY_VERIFY_ROOTHASH_SIG select IPE_PROP_FS_VERITY if FS_VERITY select IPE_PROP_FS_VERITY_BUILTIN_SIG if FS_VERITY && FS_VERITY_BUILTIN_SIGNATURES + select IPE_PROP_BPF_SIGNATURE if BPF_SYSCALL help This option enables the Integrity Policy Enforcement LSM allowing users to define a policy to enforce a trust-based access
@@ -95,6 +96,19 @@ config IPE_PROP_FS_VERITY_BUILTIN_SIG if unsure, answer Y. +config IPE_PROP_BPF_SIGNATURE + bool "Enable support for BPF program signature verdicts" + depends on BPF_SYSCALL + help + This option enables the 'bpf_signature', 'bpf_keyring' and + 'bpf_kernel' properties within IPE policies. The properties + These allow + policy rules to gate BPF program loads based on the loader's + signature verdict, the keyring used for verification, and + whether the load originated in kernel mode. + + if unsure, answer Y. + endmenu config SECURITY_IPE_KUNIT_TEST
security/ipe/audit.c +11 -0
@@ -41,6 +41,7 @@ static const char *const audit_op_names[__IPE_OP_MAX + 1] = {"KEXEC_INITRAMFS" ,"POLICY" ,"X509_CERT" , +"BPF_PROG_LOAD" , "UNKNOWN", };
@@ -51,6 +52,7 @@ static const char *const audit_hook_names[__IPE_HOOK_MAX] = {"MPROTECT" ,"KERNEL_READ" ,"KERNEL_LOAD" , + "BPF_PROG_LOAD", }; static const char *const audit_prop_names[__IPE_PROP_MAX] = {
@@ -62,6 +64,15 @@ static const char *const audit_prop_names[__IPE_PROP_MAX] = {"fsverity_digest=" ,"fsverity_signature=FALSE" ,"fsverity_signature=TRUE" , +"bpf_signature=UNSIGNED" , +"bpf_signature=OK" , +"bpf_signature=METADATA_VERIFIED" , +"bpf_keyring=BUILTIN" , +"bpf_keyring=SECONDARY" , +"bpf_keyring=PLATFORM" , +"bpf_keyring=USER" , +"bpf_kernel=FALSE" , + "bpf_kernel=TRUE", };/**
security/ipe/eval.c +57 -0
75 lines not on this page · raw message
security/ipe/eval.h +5 -0
@@ -52,6 +52,11 @@ struct ipe_eval_ctx {#ifdef CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG const struct ipe_inode *ipe_inode;#endif /* CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG */ +#ifdef CONFIG_IPE_PROP_BPF_SIGNATURE +u8 bpf_verdict;/* enum bpf_sig_verdict */ +u8 bpf_keyring;/* enum bpf_sig_keyring */ +bool bpf_kernel; +#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ };enum ipe_match {
security/ipe/hooks.c +36 -0
@@ -312,6 +312,42 @@ int ipe_bdev_setintegrity(struct block_device *bdev, enum lsm_integrity_type typ }#endif /* CONFIG_IPE_PROP_DM_VERITY */ +#ifdef CONFIG_IPE_PROP_BPF_SIGNATURE +/** +* ipe_bpf_prog_load() - IPE hook for BPF program load. +* @prog: The BPF program being loaded. +* @attr: BPF syscall attributes. +* @token: BPF token. +* @kernel: Whether the load originated in kernel mode. +* +* Return: %0 on success, %-EACCES if denied by policy. +*/ +int ipe_bpf_prog_load (struct bpf_prog *prog,union bpf_attr *attr, +struct bpf_token *token,bool kernel) +{ +struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ; + +ipe_build_eval_ctx (&ctx,NULL ,IPE_OP_BPF_PROG_LOAD , +IPE_HOOK_BPF_PROG_LOAD ); + ctx.bpf_verdict = prog->aux->sig.verdict; + ctx.bpf_keyring = prog->aux->sig.keyring; + ctx.bpf_kernel = kernel; +return ipe_evaluate_event (&ctx); +} + +int ipe_bpf_prog_load_post_integrity (struct bpf_prog *prog) +{ +struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ; + +ipe_build_eval_ctx (&ctx,NULL ,IPE_OP_BPF_PROG_LOAD_POST_INTEGRITY , +IPE_HOOK_BPF_PROG_LOAD_POST_INTEGRITY ); + ctx.bpf_verdict =BPF_SIG_METADATA_VERIFIED ; + ctx.bpf_keyring = prog->aux->sig.keyring; + ctx.bpf_kernel = prog->aux->is_kernel; +return ipe_evaluate_event (&ctx); +} +#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ +#ifdef CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG /** * ipe_inode_setintegrity() - save integrity data from a inode to IPE's LSM blob.
security/ipe/hooks.h +7 -0
@@ -10,6 +10,7 @@#include <linux/security.h> #include <linux/blk_types.h> #include <linux/fsverity.h> +#include <linux/bpf.h> enum ipe_hook_type {IPE_HOOK_BPRM_CHECK =0 ,
@@ -18,6 +19,7 @@ enum ipe_hook_type {IPE_HOOK_MPROTECT ,IPE_HOOK_KERNEL_READ ,IPE_HOOK_KERNEL_LOAD , +IPE_HOOK_BPF_PROG_LOAD , __IPE_HOOK_MAX };
@@ -52,4 +54,9 @@ int ipe_inode_setintegrity(const struct inode *inode, enum lsm_integrity_type ty const void *value, size_t size);#endif /* CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG */ +#ifdef CONFIG_IPE_PROP_BPF_SIGNATURE +int ipe_bpf_prog_load (struct bpf_prog *prog,union bpf_attr *attr, +struct bpf_token *token,bool kernel); +#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ +#endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +3 -0
@@ -60,6 +60,9 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {#ifdef CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG LSM_HOOK_INIT(inode_setintegrity, ipe_inode_setintegrity),#endif /* CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG */ +#ifdef CONFIG_IPE_PROP_BPF_SIGNATURE + LSM_HOOK_INIT(bpf_prog_load, ipe_bpf_prog_load), +#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ };/**
security/ipe/policy.h +10 -0
@@ -17,6 +17,7 @@ enum ipe_op_type {IPE_OP_KEXEC_INITRAMFS ,IPE_OP_POLICY ,IPE_OP_X509 , +IPE_OP_BPF_PROG_LOAD , __IPE_OP_MAX, };
@@ -39,6 +40,15 @@ enum ipe_prop_type {IPE_PROP_FSV_DIGEST ,IPE_PROP_FSV_SIG_FALSE ,IPE_PROP_FSV_SIG_TRUE , +IPE_PROP_BPF_SIG_UNSIGNED , +IPE_PROP_BPF_SIG_OK , +IPE_PROP_BPF_SIG_METADATA_VERIFIED , +IPE_PROP_BPF_KEYRING_BUILTIN , +IPE_PROP_BPF_KEYRING_SECONDARY , +IPE_PROP_BPF_KEYRING_PLATFORM , +IPE_PROP_BPF_KEYRING_USER , +IPE_PROP_BPF_KERNEL_FALSE , +IPE_PROP_BPF_KERNEL_TRUE , __IPE_PROP_MAX };
security/ipe/policy_parser.c +19 -0
@@ -237,6 +237,7 @@ static const match_table_t operation_tokens = { {IPE_OP_KEXEC_INITRAMFS, "op=KEXEC_INITRAMFS"}, {IPE_OP_POLICY, "op=POLICY"}, {IPE_OP_X509, "op=X509_CERT"}, + {IPE_OP_BPF_PROG_LOAD, "op=BPF_PROG_LOAD"}, {IPE_OP_INVALID, NULL} };
@@ -281,6 +282,15 @@ static const match_table_t property_tokens = { {IPE_PROP_FSV_DIGEST, "fsverity_digest=%s"}, {IPE_PROP_FSV_SIG_FALSE, "fsverity_signature=FALSE"}, {IPE_PROP_FSV_SIG_TRUE, "fsverity_signature=TRUE"}, + {IPE_PROP_BPF_SIG_UNSIGNED, "bpf_signature=UNSIGNED"}, + {IPE_PROP_BPF_SIG_OK, "bpf_signature=OK"}, + {IPE_PROP_BPF_SIG_METADATA_VERIFIED, "bpf_signature=METADATA_VERIFIED"}, + {IPE_PROP_BPF_KEYRING_BUILTIN, "bpf_keyring=BUILTIN"}, + {IPE_PROP_BPF_KEYRING_SECONDARY, "bpf_keyring=SECONDARY"}, + {IPE_PROP_BPF_KEYRING_PLATFORM, "bpf_keyring=PLATFORM"}, + {IPE_PROP_BPF_KEYRING_USER, "bpf_keyring=USER"}, + {IPE_PROP_BPF_KERNEL_FALSE, "bpf_kernel=FALSE"}, + {IPE_PROP_BPF_KERNEL_TRUE, "bpf_kernel=TRUE"}, {IPE_PROP_INVALID, NULL} };
@@ -331,6 +341,15 @@ static int parse_property(char *t, struct ipe_rule *r)case IPE_PROP_DMV_SIG_TRUE :case IPE_PROP_FSV_SIG_FALSE :case IPE_PROP_FSV_SIG_TRUE : +case IPE_PROP_BPF_SIG_UNSIGNED : +case IPE_PROP_BPF_SIG_OK : +case IPE_PROP_BPF_SIG_METADATA_VERIFIED : +case IPE_PROP_BPF_KEYRING_BUILTIN : +case IPE_PROP_BPF_KEYRING_SECONDARY : +case IPE_PROP_BPF_KEYRING_PLATFORM : +case IPE_PROP_BPF_KEYRING_USER : +case IPE_PROP_BPF_KERNEL_FALSE : +case IPE_PROP_BPF_KERNEL_TRUE : p->type = token;break ;default :
Signature · 1 line
2.53.0
PATCH 12/13 ipe: gate post-integrity BPF program loads
In reply to KP SinghRegister on security_bpf_prog_load_post_integrity and expose a new IPE op BPF_PROG_LOAD_POST_INTEGRITY. Kept distinct from BPF_PROG_LOAD so policies need not reason about the same rule firing at two timings with different verdict states.
--- security/ipe/audit.c | 2 ++ security/ipe/hooks.c | 6 ++++++ security/ipe/hooks.h | 2 ++ security/ipe/ipe.c | 1 + security/ipe/policy.h | 1 + security/ipe/policy_parser.c | 1 + 6 files changed, 13 insertions(+)
security/ipe/audit.c +2 -0
@@ -42,6 +42,7 @@ static const char *const audit_op_names[__IPE_OP_MAX + 1] = {"POLICY" ,"X509_CERT" ,"BPF_PROG_LOAD" , +"BPF_PROG_LOAD_POST_INTEGRITY" , "UNKNOWN", };
@@ -53,6 +54,7 @@ static const char *const audit_hook_names[__IPE_HOOK_MAX] = {"KERNEL_READ" ,"KERNEL_LOAD" ,"BPF_PROG_LOAD" , + "BPF_PROG_LOAD_POST_INTEGRITY", }; static const char *const audit_prop_names[__IPE_PROP_MAX] = {
security/ipe/hooks.c +6 -0
@@ -335,6 +335,12 @@ int ipe_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,return ipe_evaluate_event (&ctx); } +/** +* ipe_bpf_prog_load_post_integrity() - IPE hook for post-integrity verdict. +* @prog: The loader BPF program. +* +* Return: %0 on success, %-EACCES if denied by policy. +*/ int ipe_bpf_prog_load_post_integrity (struct bpf_prog *prog) {struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ;
security/ipe/hooks.h +2 -0
@@ -20,6 +20,7 @@ enum ipe_hook_type {IPE_HOOK_KERNEL_READ ,IPE_HOOK_KERNEL_LOAD ,IPE_HOOK_BPF_PROG_LOAD , +IPE_HOOK_BPF_PROG_LOAD_POST_INTEGRITY , __IPE_HOOK_MAX };
@@ -57,6 +58,7 @@ int ipe_inode_setintegrity(const struct inode *inode, enum lsm_integrity_type ty#ifdef CONFIG_IPE_PROP_BPF_SIGNATURE int ipe_bpf_prog_load (struct bpf_prog *prog,union bpf_attr *attr,struct bpf_token *token,bool kernel); +int ipe_bpf_prog_load_post_integrity (struct bpf_prog *prog);#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ #endif /* _IPE_HOOKS_H */
security/ipe/ipe.c +1 -0
@@ -62,6 +62,7 @@ static struct security_hook_list ipe_hooks[] __ro_after_init = {#endif /* CONFIG_IPE_PROP_FS_VERITY_BUILTIN_SIG */ #ifdef CONFIG_IPE_PROP_BPF_SIGNATURE LSM_HOOK_INIT(bpf_prog_load, ipe_bpf_prog_load), + LSM_HOOK_INIT(bpf_prog_load_post_integrity, ipe_bpf_prog_load_post_integrity),#endif /* CONFIG_IPE_PROP_BPF_SIGNATURE */ };
security/ipe/policy.h +1 -0
@@ -18,6 +18,7 @@ enum ipe_op_type {IPE_OP_POLICY ,IPE_OP_X509 ,IPE_OP_BPF_PROG_LOAD , +IPE_OP_BPF_PROG_LOAD_POST_INTEGRITY , __IPE_OP_MAX, };
security/ipe/policy_parser.c +1 -0
@@ -238,6 +238,7 @@ static const match_table_t operation_tokens = { {IPE_OP_POLICY, "op=POLICY"}, {IPE_OP_X509, "op=X509_CERT"}, {IPE_OP_BPF_PROG_LOAD, "op=BPF_PROG_LOAD"}, + {IPE_OP_BPF_PROG_LOAD_POST_INTEGRITY, "op=BPF_PROG_LOAD_POST_INTEGRITY"}, {IPE_OP_INVALID, NULL} };
Signature · 1 line
2.53.0
PATCH 13/13 selftests/bpf: add IPE BPF policy integration tests
In reply to KP SinghSmoke test for the IPE BPF signing properties and ops added in the preceding patches. The test primes the kernel config with IPE knobs, writes a boot policy, and boots vmtest.sh to verify that signed lskels load, unsigned loads are denied, and the policy audit lines match.
Manual only for now, not wired into the selftests Makefile.
--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 2 files changed, 158 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.sh
tools/testing/selftests/bpf/test_signed_bpf_ipe.sh new file +156 -0
@@ -0,0 +1,156 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# IPE BPF policy integration tests. + +if [ "${1:-}" = "--in-vm" ]; then + set -u + fail=0 + record() { + id=$1; verdict=$2; shift 2 + printf '%s %s %s\n' "$verdict" "$id" "$*" + [ "$verdict" = FAIL ] && fail=$((fail + 1)) + return 0 + } + + mountpoint -q /sys/kernel/security 2>/dev/null \ + || mount -t securityfs none /sys/kernel/security 2>/dev/null || true + if [ -d /sys/kernel/security/ipe ]; then + record T0 PASS "securityfs/ipe present" + elif grep -qw ipe /sys/kernel/security/lsm 2>/dev/null; then + record T0 PASS "ipe in /sys/kernel/security/lsm" + elif [ -r /sys/module/ipe/parameters/enforce ]; then + record T0 PASS "ipe module parameters present" + else + record T0 FAIL "no sign that IPE LSM is loaded" + fi + + if ./test_progs -t atomics 2>&1 | grep -qE '^#[0-9]+[[:space:]]+atomics:OK$'; then + record T1 PASS "atomics signed lskel loaded" + else + record T1 FAIL "atomics signed lskel did not load" + fi + + if dmesg | grep -q 'ipe_op=BPF_PROG_LOAD ipe_hook=BPF_PROG_LOAD'; then + record T2 PASS "ipe_op=BPF_PROG_LOAD audit line found" + else + record T2 FAIL "no ipe_op=BPF_PROG_LOAD audit lines in dmesg" + fi + + if dmesg | grep 'ipe_op=BPF_PROG_LOAD' \ + | grep -q 'bpf_signature=UNSIGNED action=DENY'; then + record T3 PASS "deny-UNSIGNED rule matched" + else + record T3 FAIL "deny-UNSIGNED rule never matched" + fi + + mountpoint -q /sys/kernel/security 2>/dev/null \ + || mount -t securityfs none /sys/kernel/security 2>/dev/null || true + content= + for d in /sys/kernel/security/ipe/policies/*/; do + [ -d "$d" ] || continue + if [ -r "$d/policy" ]; then + content=$(cat "$d/policy" 2>/dev/null || true) + break + fi + done + if [ -z "$content" ]; then + record T5 SKIP "could not read /sys/kernel/security/ipe/policies/*/policy" + elif echo "$content" | grep -q '^op=BPF_PROG_LOAD_POST_INTEGRITY'; then + record T5 PASS "post-integrity rule present in active policy" + else + record T5 FAIL "active policy does not contain a BPF_PROG_LOAD_POST_INTEGRITY rule" + fi + + ENFORCE=/sys/kernel/security/ipe/enforce + mountpoint -q /sys/kernel/security 2>/dev/null \ + || mount -t securityfs none /sys/kernel/security 2>/dev/null || true + + if [ ! -w "$ENFORCE" ]; then + record T4 SKIP "$ENFORCE not writable" + elif ! echo 1 > "$ENFORCE" 2>/dev/null; then + record T4 SKIP "could not toggle IPE to enforce=1" + else + out=$(./test_progs -t bind_perm 2>&1 || true) + if echo "$out" | grep -q -- '-EACCES\|errno 13'; then + record T4 PASS "unsigned load denied with -EACCES under enforce=1" + else + record T4 FAIL "no -EACCES seen from unsigned load under enforce=1" + echo "$out" | tail -10 | sed 's/^/ T4: /' + fi + echo 0 > "$ENFORCE" 2>/dev/null || true + fi + + if [ "$fail" -eq 0 ]; then + echo ALL_TESTS_PASSED + else + echo FAIL_COUNT "$fail" + fi + exit 0 +fi + +set -euo pipefail + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +KERNEL_DIR=$(cd "$SCRIPT_DIR/../../../.." && pwd) +VMTEST="$SCRIPT_DIR/vmtest.sh" + +POLICY_PATH=${IPE_TEST_POLICY:-/tmp/ipe_bpf_test_policy} + +red() { printf '\033[31m%s\033[0m\n' "$*"; } +green() { printf '\033[32m%s\033[0m\n' "$*"; } +bold() { printf '\033[1m%s\033[0m\n' "$*"; } + +bold "=== IPE BPF policy integration tests ===" + +tmpfile=$(mktemp -p "$(dirname "$POLICY_PATH")" \ + ".$(basename "$POLICY_PATH").XXXXXX") +cat > "$tmpfile" <<EOF +policy_name="ipe_bpf_test" policy_version=0.0.1 +op=BPF_PROG_LOAD bpf_signature=OK action=ALLOW +op=BPF_PROG_LOAD bpf_signature=UNSIGNED action=DENY +op=BPF_PROG_LOAD_POST_INTEGRITY action=ALLOW +DEFAULT op=BPF_PROG_LOAD action=ALLOW +DEFAULT op=BPF_PROG_LOAD_POST_INTEGRITY action=ALLOW +DEFAULT action=ALLOW +EOF +mv "$tmpfile" "$POLICY_PATH" +echo "policy written to $POLICY_PATH" + +export OUTPUT_DIR=${OUTPUT_DIR:-$HOME/.bpf_selftests_ipe} +CFG="$OUTPUT_DIR/latest.config" +mkdir -p "$OUTPUT_DIR" +if [ ! -f "$CFG" ]; then + PLATFORM=$(uname -m) + for src in "$KERNEL_DIR/tools/testing/selftests/bpf/config" \ + "$KERNEL_DIR/tools/testing/selftests/bpf/config.vm" \ + "$KERNEL_DIR/tools/testing/selftests/bpf/config.$PLATFORM"; do + [ -f "$src" ] && cat "$src" >> "$CFG" + done +fi +"$KERNEL_DIR/scripts/config" --file "$CFG" \ + --enable SECURITY_IPE \ + --enable IPE_PROP_BPF_SIGNATURE \ + --set-str IPE_BOOT_POLICY "$POLICY_PATH" +lsm=$("$KERNEL_DIR/scripts/config" --file "$CFG" --state LSM 2>/dev/null) +if [ -z "$lsm" ] || [ "$lsm" = "undef" ]; then + "$KERNEL_DIR/scripts/config" --file "$CFG" --set-str LSM "bpf,ipe" +elif ! echo ",${lsm}," | grep -q ',ipe,'; then + "$KERNEL_DIR/scripts/config" --file "$CFG" --set-str LSM "${lsm},ipe" +fi +touch "$CFG" + +RUN_OUT=$(mktemp -t ipe_test_run.XXXXXX) +trap 'rm -f "$RUN_OUT"' EXIT +export VMTEST_EXTRA_CMDLINE="ipe.enforce=0 ipe.success_audit=1" +"$VMTEST" -- ./test_signed_bpf_ipe.sh --in-vm 2>&1 | tee "$RUN_OUT" + +if grep -q 'ALL_TESTS_PASSED' "$RUN_OUT"; then + green "=== all IPE policy integration tests PASSED ===" + grep -E '^(PASS|FAIL|SKIP) T[0-9]+' "$RUN_OUT" || true + exit 0 +else + red "=== IPE policy integration tests FAILED ===" + grep -E '^(PASS|FAIL|SKIP) T[0-9]+' "$RUN_OUT" || true + exit 1 +fi
tools/testing/selftests/bpf/vmtest.sh +2 -2
@@ -61,7 +61,7 @@ DEFAULT_COMMAND="./test_progs" MOUNT_DIR="mnt" LOCAL_ROOTFS_IMAGE="" ROOTFS_IMAGE="root.img" -OUTPUT_DIR="$HOME/.bpf_selftests" +OUTPUT_DIR="${OUTPUT_DIR:-$HOME/.bpf_selftests}" KCONFIG_REL_PATHS=("tools/testing/selftests/bpf/config" "tools/testing/selftests/bpf/config.vm" "tools/testing/selftests/bpf/config.${PLATFORM}")
@@ -294,7 +294,7 @@ EOF -m 4G \ -drive file="${rootfs_img}",format=raw,index=1,media=disk,if=virtio,cache=none \ -kernel "${kernel_bzimage}" \ - -append "root=/dev/vda rw console=${QEMU_CONSOLE}" + -append "root=/dev/vda rw console=${QEMU_CONSOLE} ${VMTEST_EXTRA_CMDLINE:-}" } copy_logs()
Signature · 1 line
2.53.0
Paul Moore
maintainerQuoted 6 lines · KP Singh
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
One signing scheme, please.
This is why we tried working with you and Alexei for quite some time, providing requirements, patches, reviews, and code suggestions. Unfortunately, our input was not reflected in the signing scheme that was merged into Linus' tree, so we have had to get creative to meet our our needs and those of others.
The good news is that the Hornet signatures are compatible with the existing BPF signing scheme; a Hornet signed BPF program can be successfully verified by your signing scheme, in current kernels, as well as the Hornet LSM. Which, while were on the topic of compatibility, it looks like your proposed changes in this patchset would break compatibility with existing signed BPF programs, am I reading the patchset right in this regard?
Quoted 4 lines
BPF does not need a second signing scheme. It needs a policy framework that consumes the verdict the existing signing pipeline produces. Two parallel signing stacks is harmful UX for Cilium, bpftrace, systemd, distros, and everyone shipping signed lskels.
Once again, if one signs BPF programs using the Hornet signing tools provided in Blaise's patches, the resulting signed BPF can be loaded and verified using both the existing BPF signature verification code and Hornet. It is also easy to disable Hornet and/or IPE at kernel boot using the "lsm=" command line parameter, and of course one can always tailor the IPE policy to meet specific needs. Although you surely must be aware of that as your own patchset borrows heavily from Blaise's original code, albeit without any attribution.
Quoted 2 lines
Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed the TOCTOU that Alexei identified. On a related note, Blaise and I were working with Eric Biggers today - thank you again Eric! - on identifying some additional issues and I expect Blaise will have another patch early next week which leverages security_bpf_prog() to simplify the Hornet code and address some additional issues.
Quoted 8 lines
What this series adds
-
prog->aux->sig(verdict + keyring) andprog->aux->is_kernel, populated by the syscall path beforesecurity_bpf_prog_loadfires.
-bpf_loader_verify_metadatakfunc -- the metadata check is now kernel C code, not BPF bytecode. The verifier injects the callingprog->auxas an implicit argument viaKF_IMPLICIT_ARGS.
I think there may have been a misunderstanding regarding the "kernel C" comments. Our desire was to not have to trust the lskel loader to do any of the BPF signature verification; perfoming the verification of both the lskel loader and the original BPF program map in the native kernel's C code flows, without relying on triggering by the loader. This greatly simplifies things from a security perspective.
Quoted 5 lines
- Loader-side prog BTF with
BPF_PSEUDO_KFUNC_CALL_PROG_BTFso the kfunc CALL is reproducible across build hosts and resolved at load time.
-security_bpf_prog_load_post_integrityLSM hook, fired by the kfunc on a successful metadata check.
Does a kfunc calling a LSM hook open the door to a potential recursion issue involving a BPF LSM?
Quoted 10 lines
- IPE properties (
bpf_signature,bpf_keyring,bpf_kernel) and two ops (BPF_PROG_LOAD,BPF_PROG_LOAD_POST_INTEGRITY).This series address concerns raised by the Hornet developers:
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
The
bpf_loader_verify_metadatakfunc moves the hash check from inline BPF instructions into kernel C code.
Please see my comments above. While the kfunc is written in C, it is still reliant on the loader calling that kfunc.
Of course there is still also the usbility issue of not being able to return an error status to userspace at load time regarding the verification success of both the loader and the original BPF program map.
Quoted 67 lines
* LSMs cannot observe the verification result at hook time -- Paul Moore [4]:
prog->aux->sig.verdictand sig.keyring are populated before any LSM hook runs. Furthermore,security_bpf_prog_load_post_integrityhook fires after the in-kernel hash check for consumers that want to observe or gate the post-integrity transition.[1] Alexei Starovoitov, NACK on Hornet (TOCTOU + layering),
https://lore.kernel.org/all/CAADnVQJ1CRvTXBU771KaYzrx-vRaWF+k164DcFOqOsCxmuL+ig@mail.gmail.com/
[2] Daniel Borkmann, NACK on Hornet v3,https://lore.kernel.org/all/[email protected]/ [3] Blaise Boscaccy, Hornet v6 (C-side hash verification rationale), https://lore.kernel.org/all/[email protected]/ [4] Paul Moore, push for post-verifier observability, https://lore.kernel.org/all/CACYkzJ4+=3owK+ELD9Nw7Rrm-UajxXEw8kVtOTJJ+SNAXpsOpw@mail.gmail.com/KP Singh (13):
bpf: expose signature verdict to LSMs viabpf_prog_aux
bpf: include prog BTF in the signed loader signature scope bpf, libbpf: load prog BTF in theskel_internalloader
bpf: addbpf_loader_verify_metadatakfunc
bpf: computeprog->digestatBPF_PROG_LOADentry
bpf: resolve loader-style kfunc CALLs against prog BTF
libbpf: generate prog BTF for loader programs
bpftool gen: embed loader prog BTF in the lskel header
lsm: addbpf_prog_load_post_integrityhook
bpf: invokesecurity_bpf_prog_load_post_integrityfrom the metadata
kfunc
ipe: add BPF program signature properties
ipe: gate post-integrity BPF program loads selftests/bpf: add IPE BPF policy integration testsinclude/linux/bpf.h | 19 +++ include/linux/bpf_verifier.h | 6 + include/linux/btf.h | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 + include/uapi/linux/bpf.h | 5 + kernel/bpf/btf.c | 8 + kernel/bpf/check_btf.c | 18 +- kernel/bpf/helpers.c | 65 ++++++++ kernel/bpf/syscall.c | 76 ++++++++- kernel/bpf/verifier.c | 58 ++++++- security/ipe/Kconfig | 14 ++ security/ipe/audit.c | 13 ++ security/ipe/eval.c | 57 +++++++ security/ipe/eval.h | 5 + security/ipe/hooks.c | 42 +++++ security/ipe/hooks.h | 9 + security/ipe/ipe.c | 4 + security/ipe/policy.h | 11 ++ security/ipe/policy_parser.c | 20 +++ security/security.c | 17 ++ tools/bpf/bpftool/gen.c | 21 +++ tools/bpf/bpftool/sign.c | 17 +- tools/include/uapi/linux/bpf.h | 5 + tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 +++++++++++--- tools/lib/bpf/libbpf.h | 4 +- tools/lib/bpf/skel_internal.h | 67 +++++--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 30 files changed, 775 insertions(+), 83 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.sh
Quoted 2 lines
--
2.53.0
--
paul-moore.com
Quoted 7 lines · Paul Moore
Quoted 5 lines · KP Singh
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
Quoted 7 lines
Quoted 1 line
One signing scheme, please.
This is why we tried working with you and Alexei for quite some time, providing requirements, patches, reviews, and code suggestions. Unfortunately, our input was not reflected in the signing scheme that was merged into Linus' tree, so we have had to get creative to meet our our needs and those of others.
Is your idea of creativity to circumvent working with the BPF maintainers and community?
Quoted 8 lines
The good news is that the Hornet signatures are compatible with the existing BPF signing scheme; a Hornet signed BPF program can be successfully verified by your signing scheme, in current kernels, as well as the Hornet LSM. Which, while were on the topic of compatibility, it looks like your proposed changes in this patchset would break compatibility with existing signed BPF programs, am I reading the patchset right in this regard?
No, they won't.
Quoted 15 lines
Quoted 5 lines
BPF does not need a second signing scheme. It needs a policy framework that consumes the verdict the existing signing pipeline produces. Two parallel signing stacks is harmful UX for Cilium, bpftrace, systemd, distros, and everyone shipping signed lskels.
Once again, if one signs BPF programs using the Hornet signing tools provided in Blaise's patches, the resulting signed BPF can be loaded and verified using both the existing BPF signature verification code and Hornet. It is also easy to disable Hornet and/or IPE at kernel boot using the "lsm=" command line parameter, and of course one can always tailor the IPE policy to meet specific needs. Although you surely must be aware of that as your own patchset borrows heavily from Blaise's original code, albeit without any attribution.
Quoted 4 lines
Quoted 2 lines
Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed
Please record the NACK from Daniel and me.
Quoted 22 lines
the TOCTOU that Alexei identified. On a related note, Blaise and I were working with Eric Biggers today - thank you again Eric! - on identifying some additional issues and I expect Blaise will have another patch early next week which leverages
security_bpf_prog()to simplify the Hornet code and address some additional issues.Quoted 8 lines
What this series adds
-
prog->aux->sig(verdict + keyring) andprog->aux->is_kernel, populated by the syscall path beforesecurity_bpf_prog_loadfires.
-bpf_loader_verify_metadatakfunc -- the metadata check is now kernel C code, not BPF bytecode. The verifier injects the callingprog->auxas an implicit argument viaKF_IMPLICIT_ARGS.I think there may have been a misunderstanding regarding the "kernel C" comments. Our desire was to not have to trust the lskel loader to do any of the BPF signature verification; perfoming the verification of both the lskel loader and the original BPF program map in the native kernel's C code flows, without relying on triggering by the loader. This greatly simplifies things from a security perspective.
Quoted 8 lines
Quoted 5 lines
- Loader-side prog BTF with
BPF_PSEUDO_KFUNC_CALL_PROG_BTFso the kfunc CALL is reproducible across build hosts and resolved at load time.
-security_bpf_prog_load_post_integrityLSM hook, fired by the kfunc on a successful metadata check.Does a kfunc calling a LSM hook open the door to a potential recursion issue involving a BPF LSM?
What's the concern here? LSM hooks can fire from BPF kfuncs and helpers for a while now.
Quoted 6 lines
Quoted 6 lines
- IPE properties (
bpf_signature,bpf_keyring,bpf_kernel) and two ops (BPF_PROG_LOAD,BPF_PROG_LOAD_POST_INTEGRITY).This series address concerns raised by the Hornet developers:
Quoted 8 lines
Quoted 5 lines
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
The
bpf_loader_verify_metadatakfunc moves the hash check from inline BPF instructions into kernel C code.Please see my comments above. While the kfunc is written in C, it is still reliant on the loader calling that kfunc.
Yes, that's the idea of transitive trust here. Ultimately you signed the loader with your key. The mechanism proposed here allows verification of any dynamic metadata, it does not need to be hermetic to the loader, provided the digest of the metadata is incorporated into the loader's signed payload.
- KP
Quoted 78 lines
Of course there is still also the usbility issue of not being able to return an error status to userspace at load time regarding the verification success of both the loader and the original BPF program map.
Quoted 67 lines
* LSMs cannot observe the verification result at hook time -- Paul Moore [4]:
prog->aux->sig.verdictand sig.keyring are populated before any LSM hook runs. Furthermore,security_bpf_prog_load_post_integrityhook fires after the in-kernel hash check for consumers that want to observe or gate the post-integrity transition.[1] Alexei Starovoitov, NACK on Hornet (TOCTOU + layering),
https://lore.kernel.org/all/CAADnVQJ1CRvTXBU771KaYzrx-vRaWF+k164DcFOqOsCxmuL+ig@mail.gmail.com/
[2] Daniel Borkmann, NACK on Hornet v3,https://lore.kernel.org/all/[email protected]/ [3] Blaise Boscaccy, Hornet v6 (C-side hash verification rationale), https://lore.kernel.org/all/[email protected]/ [4] Paul Moore, push for post-verifier observability, https://lore.kernel.org/all/CACYkzJ4+=3owK+ELD9Nw7Rrm-UajxXEw8kVtOTJJ+SNAXpsOpw@mail.gmail.com/KP Singh (13):
bpf: expose signature verdict to LSMs viabpf_prog_aux
bpf: include prog BTF in the signed loader signature scope bpf, libbpf: load prog BTF in theskel_internalloader
bpf: addbpf_loader_verify_metadatakfunc
bpf: computeprog->digestatBPF_PROG_LOADentry
bpf: resolve loader-style kfunc CALLs against prog BTF
libbpf: generate prog BTF for loader programs
bpftool gen: embed loader prog BTF in the lskel header
lsm: addbpf_prog_load_post_integrityhook
bpf: invokesecurity_bpf_prog_load_post_integrityfrom the metadata
kfunc
ipe: add BPF program signature properties
ipe: gate post-integrity BPF program loads selftests/bpf: add IPE BPF policy integration testsinclude/linux/bpf.h | 19 +++ include/linux/bpf_verifier.h | 6 + include/linux/btf.h | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 + include/uapi/linux/bpf.h | 5 + kernel/bpf/btf.c | 8 + kernel/bpf/check_btf.c | 18 +- kernel/bpf/helpers.c | 65 ++++++++ kernel/bpf/syscall.c | 76 ++++++++- kernel/bpf/verifier.c | 58 ++++++- security/ipe/Kconfig | 14 ++ security/ipe/audit.c | 13 ++ security/ipe/eval.c | 57 +++++++ security/ipe/eval.h | 5 + security/ipe/hooks.c | 42 +++++ security/ipe/hooks.h | 9 + security/ipe/ipe.c | 4 + security/ipe/policy.h | 11 ++ security/ipe/policy_parser.c | 20 +++ security/security.c | 17 ++ tools/bpf/bpftool/gen.c | 21 +++ tools/bpf/bpftool/sign.c | 17 +- tools/include/uapi/linux/bpf.h | 5 + tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 +++++++++++--- tools/lib/bpf/libbpf.h | 4 +- tools/lib/bpf/skel_internal.h | 67 +++++--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 30 files changed, 775 insertions(+), 83 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.shQuoted 2 lines
--
2.53.0--
paul-moore.com
Paul Moore
maintainerQuoted 9 lines · KP Singh
Quoted 8 lines · Paul Moore
Quoted 6 lines · KP Singh
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
One signing scheme, please.
Quoted 8 lines
Quoted 5 lines
This is why we tried working with you and Alexei for quite some time, providing requirements, patches, reviews, and code suggestions. Unfortunately, our input was not reflected in the signing scheme that was merged into Linus' tree, so we have had to get creative to meet our our needs and those of others.
Is your idea of creativity to circumvent working with the BPF maintainers and community?
My previous comment should answer that.
Quoted 9 lines
Quoted 9 lines
Once again, if one signs BPF programs using the Hornet signing tools provided in Blaise's patches, the resulting signed BPF can be loaded and verified using both the existing BPF signature verification code and Hornet. It is also easy to disable Hornet and/or IPE at kernel boot using the "lsm=" command line parameter, and of course one can always tailor the IPE policy to meet specific needs. Although you surely must be aware of that as your own patchset borrows heavily from Blaise's original code, albeit without any attribution.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed
Please record the NACK from Daniel and me.
Send me the commit IDs of the patch(es) you wish to NACK and I'll add it. Daniel will need to do the same; I generally don't accept metadata tags from third parties, whether positive or negative.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
-
security_bpf_prog_load_post_integrityLSM hook, fired by the kfunc on a successful metadata check.Does a kfunc calling a LSM hook open the door to a potential recursion issue involving a BPF LSM?
What's the concern here? LSM hooks can fire from BPF kfuncs and helpers for a while now.
I was under the impression that BPF wanted to prevent things like infinite recursion, from a safety/security perspective, perhaps not.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
- IPE properties (
bpf_signature,bpf_keyring,bpf_kernel) and two ops (BPF_PROG_LOAD,BPF_PROG_LOAD_POST_INTEGRITY).This series address concerns raised by the Hornet developers:
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
The
bpf_loader_verify_metadatakfunc moves the hash check from inline BPF instructions into kernel C code.
Quoted 8 lines
Quoted 2 lines
Please see my comments above. While the kfunc is written in C, it is still reliant on the loader calling that kfunc.
Yes, that's the idea of transitive trust here. Ultimately you signed the loader with your key. The mechanism proposed here allows verification of any dynamic metadata, it does not need to be hermetic to the loader, provided the digest of the metadata is incorporated into the loader's signed payload.
We've talked about this many, many times already and the differences in our security requirements are well established. You've satisfied your security goals with the signing scheme Alexei merged, we are working to satisfy our security requirements with Hornet. While Hornet requires compliance with your signing scheme, there is no requirement for you to use Hornet to utilize your signing scheme.
Signature · 1 line
paul-moore.com
Quoted 3 lines · Paul Moore
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed the TOCTOU that Alexei identified.
It wasn't addressed. You simply ignored my feedback. sashiko spotted it too.
All other sashiko bugs were ignored as well. You merged buggy insecure code.
Paul Moore
maintainerQuoted 6 lines · Alexei Starovoitov
Quoted 3 lines · Paul Moore
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed the TOCTOU that Alexei identified.
It wasn't addressed. You simply ignored my feedback.
Blaise most certainly did update his patches based on your feedback. Perhaps there were multiple issues that weren't communicated well?
Quoted 2 lines
sashiko spotted it too.
All other sashiko bugs were ignored as well.
Link? I didn't see any feedback from sashiko feedback on list and to the best of my knowledge it hasn't been enabled for LSM patches.
--
paul-moore.com
Paul Moore
maintainerQuoted 8 lines · Paul Moore
Quoted 3 lines · Alexei Starovoitov
sashiko spotted it too.
All other sashiko bugs were ignored as well.Link? I didn't see any feedback from sashiko feedback on list and to the best of my knowledge it hasn't been enabled for LSM patches.
https://sashiko.dev/#/patchset/20260507191416.2984054-1-bboscaccy%40linux.microsoft.com
Blaise, I know you've got another patch coming soon - please take a look at the link above and see if there is anything else that needs to be addressed.
--
paul-moore.com
Quoted 7 lines · Paul Moore
Quoted 6 lines · Paul Moore
Quoted 3 lines · Alexei Starovoitov
sashiko spotted it too.
All other sashiko bugs were ignored as well.
Quoted 8 lines
Quoted 2 lines
Link? I didn't see any feedback from sashiko feedback on list and to the best of my knowledge it hasn't been enabled for LSM patches.
https://sashiko.dev/#/patchset/20260507191416.2984054-1-bboscaccy%40linux.microsoft.com
Blaise, I know you've got another patch coming soon - please take a look at the link above and see if there is anything else that needs to be addressed.
Yeah, it found a few things I corrected. It's hooked into the bpf list, not the lsm list currently. With all melodrama and bravado aside, The TOCTOU issue it found wasn't the actual attack vector and it completely missed the real one that Eric found. It seems to be lacking the multi-step reasoning that vuln researchers actually use.
Most of it looked like AI slop, and I'm not too keen on providing more free training material for AI folks to run inference on, so I didn't respond directly to the bot spam emails.
Sashiko seems to take major issue with the existing user keyring verification too *shrug*.
I'll take a second look when I'm back home next week and see if there is anything real leftover after this patchset.
-blaise
Quoted 2 lines
--
paul-moore.com
Quoted 10 lines · Paul Moore
Quoted 6 lines · Alexei Starovoitov
Quoted 3 lines · Paul Moore
Blaise has recorded Alexei's NACK on the Hornet patchset and addressed the TOCTOU that Alexei identified.
It wasn't addressed. You simply ignored my feedback.
Quoted 8 lines
Blaise most certainly did update his patches based on your feedback. Perhaps there were multiple issues that weren't communicated well?
Quoted 2 lines
sashiko spotted it too.
All other sashiko bugs were ignored as well.Link? I didn't see any feedback from sashiko feedback on list and to the best of my knowledge it hasn't been enabled for LSM patches.
Check your emails. sashiko replied multiple times to all of Blaise's versions and found lots of issues.
Quoted 29 lines · KP Singh
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
One signing scheme, please.
BPF does not need a second signing scheme. It needs a policy framework that consumes the verdict the existing signing pipeline produces. Two parallel signing stacks is harmful UX for Cilium, bpftrace, systemd, distros, and everyone shipping signed lskels. Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
What this series adds
-
prog->aux->sig(verdict + keyring) andprog->aux->is_kernel, populated by the syscall path beforesecurity_bpf_prog_loadfires.
-bpf_loader_verify_metadatakfunc -- the metadata check is now kernel C code, not BPF bytecode. The verifier injects the callingprog->auxas an implicit argument viaKF_IMPLICIT_ARGS.
- Loader-side prog BTF withBPF_PSEUDO_KFUNC_CALL_PROG_BTFso the kfunc CALL is reproducible across build hosts and resolved at load time.
-security_bpf_prog_load_post_integrityLSM hook, fired by the kfunc on a successful metadata check.
- IPE properties (bpf_signature,bpf_keyring,bpf_kernel) and two ops (BPF_PROG_LOAD,BPF_PROG_LOAD_POST_INTEGRITY).
Quoted 5 lines
This series address concerns raised by the Hornet developers:
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
That's a gross misrepresentation of some of my previous statements on the subject. We can go back and forth on this until the cows home with increasing vitriolic rhetoric, but that's really just a waste of everyone's time. Your "trusted loader" design flat-out doesn't work for our security requirements, and those of others. You keep screaming that we need to "write our own trusted loader" and that isn't really solving anything.
You just posted a trusted loader bugfix here.
https://lore.kernel.org/linux-security-module/[email protected]/
What's your path for that now and in the future? How are you getting people to rebuild their out-of-tree trusted loaders if there is a bug in them? Are you expecting sysadmins to subscribe to the bpf mailing list and watch for patches to libbpf and then rebuild an entire corpus of eBPF lskel programs?
What if there is a security vulnerability or a CVE in the generated code that gets emitted, how are you handling that? We have processes in place to handle updates, bugfixes and vulnerabilities in the kernel. None exist for your "trusted loader" paradigm. You can publish a CVE for libbpf, but there is no way to publish a CVE for an infinite number of random unknown bpf program in the wild or to notify users that their programs are effected, or for them to know which programs are actually effected and which ones aren't.
Also as an aside, it looks like some of this patchset is copy-pasted
from https://lore.kernel.org/linux-security-module/[email protected]/
Which is fine of course, since this is open source software and all, but
attribution would be appreciated if you use my code in the future :)
-blaise
Quoted 73 lines
The
bpf_loader_verify_metadatakfunc moves the hash check from inline BPF instructions into kernel C code.* LSMs cannot observe the verification result at hook time -- Paul Moore [4]:
prog->aux->sig.verdictand sig.keyring are populated before any LSM hook runs. Furthermore,security_bpf_prog_load_post_integrityhook fires after the in-kernel hash check for consumers that want to observe or gate the post-integrity transition.[1] Alexei Starovoitov, NACK on Hornet (TOCTOU + layering),
https://lore.kernel.org/all/CAADnVQJ1CRvTXBU771KaYzrx-vRaWF+k164DcFOqOsCxmuL+ig@mail.gmail.com/
[2] Daniel Borkmann, NACK on Hornet v3,https://lore.kernel.org/all/[email protected]/ [3] Blaise Boscaccy, Hornet v6 (C-side hash verification rationale), https://lore.kernel.org/all/[email protected]/ [4] Paul Moore, push for post-verifier observability, https://lore.kernel.org/all/CACYkzJ4+=3owK+ELD9Nw7Rrm-UajxXEw8kVtOTJJ+SNAXpsOpw@mail.gmail.com/KP Singh (13):
bpf: expose signature verdict to LSMs viabpf_prog_aux
bpf: include prog BTF in the signed loader signature scope bpf, libbpf: load prog BTF in theskel_internalloader
bpf: addbpf_loader_verify_metadatakfunc
bpf: computeprog->digestatBPF_PROG_LOADentry
bpf: resolve loader-style kfunc CALLs against prog BTF
libbpf: generate prog BTF for loader programs
bpftool gen: embed loader prog BTF in the lskel header
lsm: addbpf_prog_load_post_integrityhook
bpf: invokesecurity_bpf_prog_load_post_integrityfrom the metadata
kfunc
ipe: add BPF program signature properties
ipe: gate post-integrity BPF program loads selftests/bpf: add IPE BPF policy integration testsinclude/linux/bpf.h | 19 +++ include/linux/bpf_verifier.h | 6 + include/linux/btf.h | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 + include/uapi/linux/bpf.h | 5 + kernel/bpf/btf.c | 8 + kernel/bpf/check_btf.c | 18 +- kernel/bpf/helpers.c | 65 ++++++++ kernel/bpf/syscall.c | 76 ++++++++- kernel/bpf/verifier.c | 58 ++++++- security/ipe/Kconfig | 14 ++ security/ipe/audit.c | 13 ++ security/ipe/eval.c | 57 +++++++ security/ipe/eval.h | 5 + security/ipe/hooks.c | 42 +++++ security/ipe/hooks.h | 9 + security/ipe/ipe.c | 4 + security/ipe/policy.h | 11 ++ security/ipe/policy_parser.c | 20 +++ security/security.c | 17 ++ tools/bpf/bpftool/gen.c | 21 +++ tools/bpf/bpftool/sign.c | 17 +- tools/include/uapi/linux/bpf.h | 5 + tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 +++++++++++--- tools/lib/bpf/libbpf.h | 4 +- tools/lib/bpf/skel_internal.h | 67 +++++--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 30 files changed, 775 insertions(+), 83 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.shSignature · 1 line
2.53.0
Quoted 38 lines · On Sat, 23 May 2026, 18:34 Blaise Boscaccy, <[email protected]>…
Quoted 29 lines · KP Singh
This series continues the "Signed BPF programs" work and adds the missing pieces needed for an LSM to do policy enforcement and addresses the concerns raised by the developers of Hornet.
One signing scheme, please.
BPF does not need a second signing scheme. It needs a policy framework that consumes the verdict the existing signing pipeline produces. Two parallel signing stacks is harmful UX for Cilium, bpftrace, systemd, distros, and everyone shipping signed lskels. Hornet has been NACK'd repeatedly by the BPF maintainers [1][2] on layering and TOCTOU grounds.
What this series adds
-
prog->aux->sig(verdict + keyring) andprog->aux->is_kernel, populated by the syscall path beforesecurity_bpf_prog_loadfires.
-bpf_loader_verify_metadatakfunc -- the metadata check is now kernel C code, not BPF bytecode. The verifier injects the callingprog->auxas an implicit argument viaKF_IMPLICIT_ARGS.
- Loader-side prog BTF withBPF_PSEUDO_KFUNC_CALL_PROG_BTFso the kfunc CALL is reproducible across build hosts and resolved at load time.
-security_bpf_prog_load_post_integrityLSM hook, fired by the kfunc on a successful metadata check.
- IPE properties (bpf_signature,bpf_keyring,bpf_kernel) and two ops (BPF_PROG_LOAD,BPF_PROG_LOAD_POST_INTEGRITY).Quoted 5 lines
This series address concerns raised by the Hornet developers:
* The metadata hash check should be in kernel C, not BPF bytecode -- Blaise Boscaccy [3]:
Quoted 5 lines
That's a gross misrepresentation of some of my previous statements on the subject. We can go back and forth on this until the cows home with increasing vitriolic rhetoric, but that's really just a waste of
everyone's time. Your "trusted loader" design flat-out doesn't work for
I totally agree, I have wasted a lot of time arguing with you and it's up to the maintainers and Linus to decide here.
Quoted 4 lines
our security requirements, and those of others. You keep screaming that we need to "write our own trusted loader" and that isn't really solving anything.
Quoted 8 lines
You just posted a trusted loader bugfix here.
https://lore.kernel.org/linux-security-module/[email protected]/What's your path for that now and in the future? How are you getting people to rebuild their out-of-tree trusted loaders if there is a bug in them? Are you expecting sysadmins to subscribe to the bpf mailing list and watch for patches to libbpf and then rebuild an entire corpus of eBPF lskel programs?
How do you get people to update their software? Don't you folks update libraries? If users write their own loaders, they are responsible for vulnerability management, just as they are for any other piece of software. Not all trusted software lives in the kernel (eg. systemd, privileged daemons, software with access to sensitive credentials).
Your arguments are illogical and abrasive. Furthermore, your requirements are a moving target and you haven't explained the threat model supporting them, despite repeated requests.
Quoted 10 lines
What if there is a security vulnerability or a CVE in the generated code that gets emitted, how are you handling that? We have processes in place to handle updates, bugfixes and vulnerabilities in the kernel. None exist for your "trusted loader" paradigm. You can publish a CVE for libbpf, but there is no way to publish a CVE for an infinite number of random unknown bpf program in the wild or to notify users that their programs are effected, or for them to know which programs are actually effected and which ones aren't.
Quoted 4 lines
Also as an aside, it looks like some of this patchset is copy-pasted
from https://lore.kernel.org/linux-security-module/[email protected]/
Which is fine of course, since this is open source software and all, but
attribution would be appreciated if you use my code in the future :)
There are only so many ways to write IPE policies, but I am happy to add attribution, I will add it in the next rev.
- KP
Quoted 79 lines
-blaise
Quoted 73 lines
The
bpf_loader_verify_metadatakfunc moves the hash check from inline BPF instructions into kernel C code.* LSMs cannot observe the verification result at hook time -- Paul Moore [4]:
prog->aux->sig.verdictand sig.keyring are populated before any LSM hook runs. Furthermore,security_bpf_prog_load_post_integrityhook fires after the in-kernel hash check for consumers that want to observe or gate the post-integrity transition.[1] Alexei Starovoitov, NACK on Hornet (TOCTOU + layering),
https://lore.kernel.org/all/CAADnVQJ1CRvTXBU771KaYzrx-vRaWF+k164DcFOqOsCxmuL+ig@mail.gmail.com/
[2] Daniel Borkmann, NACK on Hornet v3,https://lore.kernel.org/all/[email protected]/ [3] Blaise Boscaccy, Hornet v6 (C-side hash verification rationale), https://lore.kernel.org/all/[email protected]/ [4] Paul Moore, push for post-verifier observability, https://lore.kernel.org/all/CACYkzJ4+=3owK+ELD9Nw7Rrm-UajxXEw8kVtOTJJ+SNAXpsOpw@mail.gmail.com/KP Singh (13):
bpf: expose signature verdict to LSMs viabpf_prog_aux
bpf: include prog BTF in the signed loader signature scope bpf, libbpf: load prog BTF in theskel_internalloader
bpf: addbpf_loader_verify_metadatakfunc
bpf: computeprog->digestatBPF_PROG_LOADentry
bpf: resolve loader-style kfunc CALLs against prog BTF
libbpf: generate prog BTF for loader programs
bpftool gen: embed loader prog BTF in the lskel header
lsm: addbpf_prog_load_post_integrityhook
bpf: invokesecurity_bpf_prog_load_post_integrityfrom the metadata
kfunc
ipe: add BPF program signature properties
ipe: gate post-integrity BPF program loads selftests/bpf: add IPE BPF policy integration testsinclude/linux/bpf.h | 19 +++ include/linux/bpf_verifier.h | 6 + include/linux/btf.h | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/security.h | 6 + include/uapi/linux/bpf.h | 5 + kernel/bpf/btf.c | 8 + kernel/bpf/check_btf.c | 18 +- kernel/bpf/helpers.c | 65 ++++++++ kernel/bpf/syscall.c | 76 ++++++++- kernel/bpf/verifier.c | 58 ++++++- security/ipe/Kconfig | 14 ++ security/ipe/audit.c | 13 ++ security/ipe/eval.c | 57 +++++++ security/ipe/eval.h | 5 + security/ipe/hooks.c | 42 +++++ security/ipe/hooks.h | 9 + security/ipe/ipe.c | 4 + security/ipe/policy.h | 11 ++ security/ipe/policy_parser.c | 20 +++ security/security.c | 17 ++ tools/bpf/bpftool/gen.c | 21 +++ tools/bpf/bpftool/sign.c | 17 +- tools/include/uapi/linux/bpf.h | 5 + tools/lib/bpf/bpf_gen_internal.h | 2 + tools/lib/bpf/gen_loader.c | 127 +++++++++++--- tools/lib/bpf/libbpf.h | 4 +- tools/lib/bpf/skel_internal.h | 67 +++++--- .../selftests/bpf/test_signed_bpf_ipe.sh | 156 ++++++++++++++++++ tools/testing/selftests/bpf/vmtest.sh | 4 +- 30 files changed, 775 insertions(+), 83 deletions(-) create mode 100755 tools/testing/selftests/bpf/test_signed_bpf_ipe.sh--
2.53.0