BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH v1 bpf] libbpf: use proper errno value in linker
Date: Sat, 10 May 2025 18:28:06 +0000	[thread overview]
Message-ID: <aB+atmcK/L53R40i@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzYmNyBS-xofAagQ6diVkSEn3iT46kcRrBSM-_14fAmgzg@mail.gmail.com>

On 25/04/30 09:05AM, Andrii Nakryiko wrote:
> On Wed, Apr 30, 2025 at 5:03 AM Anton Protopopov
> <a.s.protopopov@gmail.com> wrote:
> >
> > Return values of the linker_append_sec_data() and the
> > linker_append_elf_relos() functions are propagated all the
> > way up to users of libbpf API. In some error cases these
> > functions return -1 which will be seen as -EPERM from user's
> > point of view. Instead, return a more reasonable -EINVAL.
> >
> > Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
> > Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
> > ---
> >  tools/lib/bpf/linker.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> > index 56f5068e2eba..a469e5d4fee7 100644
> > --- a/tools/lib/bpf/linker.c
> > +++ b/tools/lib/bpf/linker.c
> > @@ -1376,7 +1376,7 @@ static int linker_append_sec_data(struct bpf_linker *linker, struct src_obj *obj
> >                 } else {
> >                         if (!secs_match(dst_sec, src_sec)) {
> >                                 pr_warn("ELF sections %s are incompatible\n", src_sec->sec_name);
> > -                               return -1;
> > +                               return -EINVAL;
> >                         }
> >
> >                         /* "license" and "version" sections are deduped */
> > @@ -2223,7 +2223,7 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob
> >                         }
> >                 } else if (!secs_match(dst_sec, src_sec)) {
> >                         pr_warn("sections %s are not compatible\n", src_sec->sec_name);
> > -                       return -1;
> > +                       return -EINVAL;
> 
> doh, not sure how that slipped through, thanks for the fix! I applied
> it to bpf-next.
> 
> BTW, if you would be so kind, I think we have a similar issue with
> validate_nla() in nlattr.c, where -1 can be eventually returned as
> user-visible error code, it would be nice to fix this up like you did
> with linker APIs, thanks!

Sent it. It fixes the return value in validate_nla.  But just wanted
to add a note here, that I am not signing for fixing all the return
paths in nlattr.c and netlink.c :)

> >                 }
> >
> >                 /* shdr->sh_link points to SYMTAB */
> > --
> > 2.34.1
> >

  parent reply	other threads:[~2025-05-10 18:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 12:08 [PATCH v1 bpf] libbpf: use proper errno value in linker Anton Protopopov
2025-04-30 16:05 ` Andrii Nakryiko
2025-04-30 16:15   ` Anton Protopopov
2025-05-10 18:28   ` Anton Protopopov [this message]
2025-04-30 16:10 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aB+atmcK/L53R40i@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox