[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250130-dauer-stich-21e0f1f09568@brauner>
Date: Thu, 30 Jan 2025 16:32:11 +0100
From: Christian Brauner <brauner@...nel.org>
To: Juntong Deng <juntong.deng@...look.com>
Cc: ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me, haoluo@...gle.com,
jolsa@...nel.org, memxor@...il.com, snorcht@...il.com, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH bpf-next v9 4/5] bpf: Make fs kfuncs available for
SYSCALL program type
On Mon, Jan 27, 2025 at 11:46:53PM +0000, Juntong Deng wrote:
> Currently fs kfuncs are only available for LSM program type, but fs
> kfuncs are general and useful for scenarios other than LSM.
>
> This patch makes fs kfuncs available for SYSCALL program type.
>
> Signed-off-by: Juntong Deng <juntong.deng@...look.com>
> ---
I still have a hard time understanding what syscall program types do and
why we should want to allow the usage of all current fs functions that
were added for LSMs specifically to such program types. I can't say
anything about this until I have a rough understanding what a syscall
bpf program allows you to do and what it's used for. Preferably some
example.
> fs/bpf_fs_kfuncs.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index 4a810046dcf3..8a7e9ed371de 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c
> @@ -26,8 +26,6 @@ __bpf_kfunc_start_defs();
> * acquired by this BPF kfunc will result in the BPF program being rejected by
> * the BPF verifier.
> *
> - * This BPF kfunc may only be called from BPF LSM programs.
> - *
> * Internally, this BPF kfunc leans on get_task_exe_file(), such that calling
> * bpf_get_task_exe_file() would be analogous to calling get_task_exe_file()
> * directly in kernel context.
> @@ -49,8 +47,6 @@ __bpf_kfunc struct file *bpf_get_task_exe_file(struct task_struct *task)
> * passed to this BPF kfunc. Attempting to pass an unreferenced file pointer, or
> * any other arbitrary pointer for that matter, will result in the BPF program
> * being rejected by the BPF verifier.
> - *
> - * This BPF kfunc may only be called from BPF LSM programs.
> */
> __bpf_kfunc void bpf_put_file(struct file *file)
> {
> @@ -70,8 +66,6 @@ __bpf_kfunc void bpf_put_file(struct file *file)
> * reference, or else the BPF program will be outright rejected by the BPF
> * verifier.
> *
> - * This BPF kfunc may only be called from BPF LSM programs.
> - *
> * Return: A positive integer corresponding to the length of the resolved
> * pathname in *buf*, including the NUL termination character. On error, a
> * negative integer is returned.
> @@ -184,7 +178,8 @@ BTF_KFUNCS_END(bpf_fs_kfunc_set_ids)
> static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)
> {
> if (!btf_id_set8_contains(&bpf_fs_kfunc_set_ids, kfunc_id) ||
> - prog->type == BPF_PROG_TYPE_LSM)
> + prog->type == BPF_PROG_TYPE_LSM ||
> + prog->type == BPF_PROG_TYPE_SYSCALL)
> return 0;
> return -EACCES;
> }
> @@ -197,7 +192,10 @@ static const struct btf_kfunc_id_set bpf_fs_kfunc_set = {
>
> static int __init bpf_fs_kfuncs_init(void)
> {
> - return register_btf_kfunc_id_set(BPF_PROG_TYPE_LSM, &bpf_fs_kfunc_set);
> + int ret;
> +
> + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_LSM, &bpf_fs_kfunc_set);
> + return ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &bpf_fs_kfunc_set);
> }
>
> late_initcall(bpf_fs_kfuncs_init);
> --
> 2.39.5
>
Powered by blists - more mailing lists