lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5525A04E-70F7-4E13-AB12-A6905FB3697A@meta.com>
Date: Tue, 4 Nov 2025 21:59:59 +0000
From: Song Liu <songliubraving@...a.com>
To: Amery Hung <ameryhung@...il.com>
CC: "bpf@...r.kernel.org" <bpf@...r.kernel.org>,
        "netdev@...r.kernel.org"
	<netdev@...r.kernel.org>,
        "alexei.starovoitov@...il.com"
	<alexei.starovoitov@...il.com>,
        "andrii@...nel.org" <andrii@...nel.org>,
        "daniel@...earbox.net" <daniel@...earbox.net>,
        "tj@...nel.org"
	<tj@...nel.org>,
        "martin.lau@...nel.org" <martin.lau@...nel.org>,
        Kernel Team
	<kernel-team@...a.com>,
        "roman.gushchin@...ux.dev" <roman.gushchin@...ux.dev>
Subject: Re: [PATCH bpf-next v5 2/7] bpf: Support associating BPF program with
 struct_ops



> On Nov 4, 2025, at 9:26 AM, Amery Hung <ameryhung@...il.com> wrote:
> 
> Add a new BPF command BPF_PROG_ASSOC_STRUCT_OPS to allow associating
> a BPF program with a struct_ops map. This command takes a file
> descriptor of a struct_ops map and a BPF program and set
> prog->aux->st_ops_assoc to the kdata of the struct_ops map.
> 
> The command does not accept a struct_ops program nor a non-struct_ops
> map. Programs of a struct_ops map is automatically associated with the
> map during map update. If a program is shared between two struct_ops
> maps, prog->aux->st_ops_assoc will be poisoned to indicate that the
> associated struct_ops is ambiguous. The pointer, once poisoned, cannot
> be reset since we have lost track of associated struct_ops. For other
> program types, the associated struct_ops map, once set, cannot be
> changed later. This restriction may be lifted in the future if there is
> a use case.
> 
> A kernel helper bpf_prog_get_assoc_struct_ops() can be used to retrieve
> the associated struct_ops pointer. The returned pointer, if not NULL, is
> guaranteed to be valid and point to a fully updated struct_ops struct.
> For struct_ops program reused in multiple struct_ops map, the return
> will be NULL.
> 
> To make sure the returned pointer to be valid, the command increases the
> refcount of the map for every associated non-struct_ops programs. For
> struct_ops programs, the destruction of a struct_ops map already waits for
> its BPF programs to finish running. A later patch will further make sure
> the map will not be freed when an async callback schedule from struct_ops
> is running.
> 
> struct_ops implementers should note that the struct_ops returned may or
> may not be attached. The struct_ops implementer will be responsible for
> tracking and checking the state of the associated struct_ops map if the
> use case requires an attached struct_ops.
> 
> Signed-off-by: Amery Hung <ameryhung@...il.com>
> ---
> include/linux/bpf.h            | 16 ++++++
> include/uapi/linux/bpf.h       | 17 +++++++
> kernel/bpf/bpf_struct_ops.c    | 90 ++++++++++++++++++++++++++++++++++
> kernel/bpf/core.c              |  3 ++
> kernel/bpf/syscall.c           | 46 +++++++++++++++++
> tools/include/uapi/linux/bpf.h | 17 +++++++
> 6 files changed, 189 insertions(+)
> 
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index a47d67db3be5..0f71030c03e1 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1726,6 +1726,8 @@ struct bpf_prog_aux {
> struct rcu_head rcu;
> };
> struct bpf_stream stream[2];
> + struct mutex st_ops_assoc_mutex;
> + struct bpf_map *st_ops_assoc;
> };

In the bpf-oom thread, we agreed (mostly agreed?) that we will allow 
attaching a struct_ops map multiple times. 

To match this design, shall we associate a BPF program with a 
bpf_struct_ops_link instead of bpf_map? This requires one more 
pointer deref to get the pointer to the struct_ops map. But the 
solution will be more future proof. 

Does this make sense?

Thanks,
Song



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ