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: <CAEf4BzZ1sgg26wjrBi2MNAaTT767Kjv7qxS5RY8SVX6O0uaPsg@mail.gmail.com>
Date: Mon, 30 Sep 2024 15:44:02 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: i@...k3r.moe
Cc: bpf@...r.kernel.org, Andrii Nakryiko <andrii@...nel.org>, 
	Alexei Starovoitov <ast@...nel.org>, netdev@...r.kernel.org
Subject: Re: [PATCH bpf-next v2 1/2] libbpf: do not resolve size on duplicate FUNCs

On Sun, Sep 29, 2024 at 2:31 AM Eric Long via B4 Relay
<devnull+i.hack3r.moe@...nel.org> wrote:
>
> From: Eric Long <i@...k3r.moe>
>
> FUNCs do not have sizes, thus currently btf__resolve_size will fail
> with -EINVAL. Add conditions so that we only update size when the BTF
> object is not function or function prototype.
>
> Signed-off-by: Eric Long <i@...k3r.moe>
> ---
>  tools/lib/bpf/linker.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> index 81dbbdd79a7c65a4b048b85e1dba99cb5f7cb56b..cffb388fa40ef054c2661b8363120f8a4d3c3784 100644
> --- a/tools/lib/bpf/linker.c
> +++ b/tools/lib/bpf/linker.c
> @@ -2452,17 +2452,20 @@ static int linker_append_btf(struct bpf_linker *linker, struct src_obj *obj)
>                                 __s64 sz;
>
>                                 dst_var = &dst_sec->sec_vars[glob_sym->var_idx];
> -                               /* Because underlying BTF type might have
> -                                * changed, so might its size have changed, so
> -                                * re-calculate and update it in sec_var.
> -                                */
> -                               sz = btf__resolve_size(linker->btf, glob_sym->underlying_btf_id);
> -                               if (sz < 0) {
> -                                       pr_warn("global '%s': failed to resolve size of underlying type: %d\n",
> -                                               name, (int)sz);
> -                                       return -EINVAL;
> +                               t = btf__type_by_id(linker->btf, glob_sym->underlying_btf_id);
> +                               if (btf_kind(t) != BTF_KIND_FUNC && btf_kind(t) != BTF_KIND_FUNC_PROTO) {

this is sloppy, it can't be both.

Why can't be it a much simpler and cleaner:

diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
index 81dbbdd79a7c..f83c1c29982c 100644
--- a/tools/lib/bpf/linker.c
+++ b/tools/lib/bpf/linker.c
@@ -2451,6 +2451,10 @@ static int linker_append_btf(struct bpf_linker
*linker, struct src_obj *obj)
                        if (glob_sym && glob_sym->var_idx >= 0) {
                                __s64 sz;

+                               /* FUNCs don't have size, nothing to update */
+                               if (btf_is_func(t))
+                                       continue;
+
                                dst_var = &dst_sec->sec_vars[glob_sym->var_idx];
                                /* Because underlying BTF type might have
                                 * changed, so might its size have changed, so

?

pw-bot: cr

> +                                       /* Because underlying BTF type might have
> +                                        * changed, so might its size have changed, so
> +                                        * re-calculate and update it in sec_var.
> +                                        */
> +                                       sz = btf__resolve_size(linker->btf, glob_sym->underlying_btf_id);
> +                                       if (sz < 0) {
> +                                               pr_warn("global '%s': failed to resolve size of underlying type: %d\n",
> +                                                       name, (int)sz);
> +                                               return -EINVAL;
> +                                       }
> +                                       dst_var->size = sz;
>                                 }
> -                               dst_var->size = sz;
>                                 continue;
>                         }
>
>
> --
> 2.46.2
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ