@@ -584,7 +584,9 @@ enum landlock_hook_id {
#define _LANDLOCK_FLAG_ORIGIN_MASK ((1 << 3) - 1)
/* context of function access flags */
-#define _LANDLOCK_FLAG_ACCESS_MASK ((1ULL << 0) - 1)
+#define LANDLOCK_FLAG_ACCESS_UPDATE (1 << 0)
+#define LANDLOCK_FLAG_ACCESS_DEBUG (1 << 1)
+#define _LANDLOCK_FLAG_ACCESS_MASK ((1ULL << 2) - 1)
/* Handle check flags */
#define LANDLOCK_FLAG_FS_DENTRY (1 << 0)
@@ -202,11 +202,57 @@ static int landlock_run_prog(enum landlock_hook_id hook_id, __u64 args[6])
static const struct bpf_func_proto *bpf_landlock_func_proto(
enum bpf_func_id func_id, union bpf_prog_subtype *prog_subtype)
{
+ bool access_update = !!(prog_subtype->landlock_hook.access &
+ LANDLOCK_FLAG_ACCESS_UPDATE);
+ bool access_debug = !!(prog_subtype->landlock_hook.access &
+ LANDLOCK_FLAG_ACCESS_DEBUG);
+
switch (func_id) {
case BPF_FUNC_landlock_cmp_fs_prop_with_struct_file:
return &bpf_landlock_cmp_fs_prop_with_struct_file_proto;
case BPF_FUNC_landlock_cmp_fs_beneath_with_struct_file:
return &bpf_landlock_cmp_fs_beneath_with_struct_file_proto;
+
+ /* access_update */
+ case BPF_FUNC_map_lookup_elem:
+ if (access_update)
+ return &bpf_map_lookup_elem_proto;
+ return NULL;
+ case BPF_FUNC_map_update_elem:
+ if (access_update)
+ return &bpf_map_update_elem_proto;
+ return NULL;
+ case BPF_FUNC_map_delete_elem:
+ if (access_update)
+ return &bpf_map_delete_elem_proto;
+ return NULL;
+ case BPF_FUNC_tail_call:
+ if (access_update)
+ return &bpf_tail_call_proto;
+ return NULL;
+
+ /* access_debug */
+ case BPF_FUNC_trace_printk:
+ if (access_debug)
+ return bpf_get_trace_printk_proto();
+ return NULL;
+ case BPF_FUNC_get_prandom_u32:
+ if (access_debug)
+ return &bpf_get_prandom_u32_proto;
+ return NULL;
+ case BPF_FUNC_get_current_pid_tgid:
+ if (access_debug)
+ return &bpf_get_current_pid_tgid_proto;
+ return NULL;
+ case BPF_FUNC_get_current_uid_gid:
+ if (access_debug)
+ return &bpf_get_current_uid_gid_proto;
+ return NULL;
+ case BPF_FUNC_get_current_comm:
+ if (access_debug)
+ return &bpf_get_current_comm_proto;
+ return NULL;
+
default:
return NULL;
}
@@ -348,6 +394,14 @@ static inline bool bpf_landlock_is_valid_subtype(
if (prog_subtype->landlock_hook.access & ~_LANDLOCK_FLAG_ACCESS_MASK)
return false;
+ /* check access flags */
+ if (prog_subtype->landlock_hook.access & LANDLOCK_FLAG_ACCESS_UPDATE &&
+ !capable(CAP_SYS_ADMIN))
+ return false;
+ if (prog_subtype->landlock_hook.access & LANDLOCK_FLAG_ACCESS_DEBUG &&
+ !capable(CAP_SYS_ADMIN))
+ return false;
+
return true;
}
For now, the update and debug accesses are only accessible to a process with CAP_SYS_ADMIN. This could change in the future. The capability check is statically done when loading an eBPF program, according to the current process. If the process has enough rights and set the appropriate access flags, then the dedicated functions or data will be accessible. With the update access, the following functions are available: * bpf_map_lookup_elem * bpf_map_update_elem * bpf_map_delete_elem * bpf_tail_call With the debug access, the following functions are available: * bpf_trace_printk * bpf_get_prandom_u32 * bpf_get_current_pid_tgid * bpf_get_current_uid_gid * bpf_get_current_comm Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: David S. Miller <davem@davemloft.net> Cc: Kees Cook <keescook@chromium.org> Cc: Sargun Dhillon <sargun@sargun.me> --- include/uapi/linux/bpf.h | 4 +++- security/landlock/lsm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-)