mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
Similar to bpf_local_storage for sockets and inodes add local storage for task_struct. The life-cycle of storage is managed with the life-cycle of the task_struct. i.e. the storage is destroyed along with the owning task with a callback to the bpf_task_storage_free from the task_free LSM hook. The BPF LSM allocates an __rcu pointer to the bpf_local_storage in the security blob which are now stackable and can co-exist with other LSMs. The userspace map operations can be done by using a pid fd as a key passed to the lookup, update and delete operations. Signed-off-by: KP Singh <kpsingh@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20201106103747.2780972-3-kpsingh@chromium.org
86 lines
1.8 KiB
C
86 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
* Copyright (C) 2020 Google LLC.
|
|
*/
|
|
|
|
#ifndef _LINUX_BPF_LSM_H
|
|
#define _LINUX_BPF_LSM_H
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/bpf.h>
|
|
#include <linux/lsm_hooks.h>
|
|
|
|
#ifdef CONFIG_BPF_LSM
|
|
|
|
#define LSM_HOOK(RET, DEFAULT, NAME, ...) \
|
|
RET bpf_lsm_##NAME(__VA_ARGS__);
|
|
#include <linux/lsm_hook_defs.h>
|
|
#undef LSM_HOOK
|
|
|
|
struct bpf_storage_blob {
|
|
struct bpf_local_storage __rcu *storage;
|
|
};
|
|
|
|
extern struct lsm_blob_sizes bpf_lsm_blob_sizes;
|
|
|
|
int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
|
|
const struct bpf_prog *prog);
|
|
|
|
static inline struct bpf_storage_blob *bpf_inode(
|
|
const struct inode *inode)
|
|
{
|
|
if (unlikely(!inode->i_security))
|
|
return NULL;
|
|
|
|
return inode->i_security + bpf_lsm_blob_sizes.lbs_inode;
|
|
}
|
|
|
|
static inline struct bpf_storage_blob *bpf_task(
|
|
const struct task_struct *task)
|
|
{
|
|
if (unlikely(!task->security))
|
|
return NULL;
|
|
|
|
return task->security + bpf_lsm_blob_sizes.lbs_task;
|
|
}
|
|
|
|
extern const struct bpf_func_proto bpf_inode_storage_get_proto;
|
|
extern const struct bpf_func_proto bpf_inode_storage_delete_proto;
|
|
extern const struct bpf_func_proto bpf_task_storage_get_proto;
|
|
extern const struct bpf_func_proto bpf_task_storage_delete_proto;
|
|
void bpf_inode_storage_free(struct inode *inode);
|
|
void bpf_task_storage_free(struct task_struct *task);
|
|
|
|
#else /* !CONFIG_BPF_LSM */
|
|
|
|
static inline int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog,
|
|
const struct bpf_prog *prog)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline struct bpf_storage_blob *bpf_inode(
|
|
const struct inode *inode)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline struct bpf_storage_blob *bpf_task(
|
|
const struct task_struct *task)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void bpf_inode_storage_free(struct inode *inode)
|
|
{
|
|
}
|
|
|
|
static inline void bpf_task_storage_free(struct task_struct *task)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_BPF_LSM */
|
|
|
|
#endif /* _LINUX_BPF_LSM_H */
|